IniFile.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef _Inifile_H
19 #define _Inifile_H
20 
21 #include <iostream>
22 #include <vector>
23 #include <string>
24 #include <stdio.h>
25 
26 //-------------------------------------------------------------------
27 
28 
61 class IniFile
62 {
63 public:
64 
68  IniFile();
69 
74  IniFile(std::string fileName);
75  ~IniFile();
76 
86  int SetFileName(std::string fileName, std::string strIniFileUsedBy = "", bool bCreate = false);
87 
88 
98  int WriteKeyString(const char* pSect, const char* pKey, const std::string* pStrToWrite, bool bWarnIfNotfound = true);
99 
109  int WriteKeyInt(const char* pSect,const char* pKey,int nValue, bool bWarnIfNotfound = true);
110 
121  int WriteKeyDouble(const char* pSect,const char* pKey,double dValue,int StringLen=12,int decimals=5, bool bWarnIfNotfound = true);
122 
132  int WriteKeyBool(const char* pSect, const char* pKey, bool bValue, bool bWarnIfNotfound = true);
133 
142  int GetKeyString(const char* pSect,const char* pKey, std::string* pStrToRead,
143  bool bWarnIfNotfound = true);
144 
149  int GetKeyInt(const char* pSect,const char* pKey,int* pValue,
150  bool bWarnIfNotfound = true);
151 
155  int GetKeyLong(const char* pSect,const char* pKey,long* pValue,
156  bool bWarnIfNotfound = true);
157 
166  int GetKeyBool(const char* pSect, const char* pKey, bool* pValue,
167  bool bWarnIfNotfound = true);
168 
177  int GetKeyDouble(const char* pSect,const char* pKey,double* pValue,
178  bool bWarnIfNotfound = true);
179 
188  int GetKeyDouble(const char* pSect,const char* pKey,double* pValue, double dDefault,
189  bool bWarnIfNotfound = true);
190 
199  int GetKey(const char* pSect,const char* pKey, std::string* pStrToRead, bool bWarnIfNotfound = true);
200 
205  int GetKey(const char* pSect,const char* pKey,int* pValue, bool bWarnIfNotfound = true);
206 
215  int GetKey(const char* pSect, const char* pKey, bool* pValue, bool bWarnIfNotfound = true);
216 
225  int GetKey(const char* pSect,const char* pKey,double* pValue, bool bWarnIfNotfound = true);
226 
235  int FindNextSection(std::string* pSect, std::string prevSect, bool bWarnIfNotfound = true);
236 
237 private:
238 
239  int FindSection(const char* sect, bool bWarnIfNotfound = true);
240  int FindKey(const char* skey, bool bWarnIfNotfound = true);
241  int FindNextLine(std::vector<char>& NewLine, int& CharInd);
242 
251  int WriteKeyValue(const char* pSect,const char* pKey,const char* pBuf, bool bWarnIfNotfound = true);
252 
264  int GetKeyValue(const char* pSect,const char* pKey, char* pBuf, int lenBuf,
265  bool bWarnIfNotfound = true);
266 
272  int SkipLineUntil(FILE* pFile, const char EndChar);
273 
280  int ReadLineUntil(FILE* pFile, const char EndChar, std::string& ReadIntoStr);
281 
282  bool m_bFileOK;
283 
287  std::vector<char> m_CurLine;
288 
292  const int m_vectorSize;
293 
298 
299  std::string m_fileName;
300  std::string m_strIniFileUsedBy; //used for debug to inidcate user class of ini-file
301  FILE* f;
302 };
303 
304 #endif
305 
int SkipLineUntil(FILE *pFile, const char EndChar)
Definition: IniFile.cpp:432
bool m_bFileOK
Definition: IniFile.h:282
IniFile()
Definition: IniFile.cpp:28
~IniFile()
Definition: IniFile.cpp:43
int FindNextLine(std::vector< char > &NewLine, int &CharInd)
Definition: IniFile.cpp:468
int FindKey(const char *skey, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:575
FILE * f
Definition: IniFile.h:301
int GetKeyValue(const char *pSect, const char *pKey, char *pBuf, int lenBuf, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:320
const int m_vectorSize
Definition: IniFile.h:292
int WriteKeyString(const char *pSect, const char *pKey, const std::string *pStrToWrite, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:71
std::vector< char > m_CurLine
Definition: IniFile.h:287
int GetKeyBool(const char *pSect, const char *pKey, bool *pValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:215
int WriteKeyDouble(const char *pSect, const char *pKey, double dValue, int StringLen=12, int decimals=5, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:207
int WriteKeyInt(const char *pSect, const char *pKey, int nValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:200
int GetKeyInt(const char *pSect, const char *pKey, int *pValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:241
int FindNextSection(std::string *pSect, std::string prevSect, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:479
int GetKeyDouble(const char *pSect, const char *pKey, double *pValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:297
int FindSection(const char *sect, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:533
int m_CurCharInd
Definition: IniFile.h:297
int SetFileName(std::string fileName, std::string strIniFileUsedBy="", bool bCreate=false)
Definition: IniFile.cpp:47
int GetKey(const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:626
int GetKeyString(const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:373
int ReadLineUntil(FILE *pFile, const char EndChar, std::string &ReadIntoStr)
Definition: IniFile.cpp:449
std::string m_fileName
Definition: IniFile.h:299
int GetKeyLong(const char *pSect, const char *pKey, long *pValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:285
int WriteKeyBool(const char *pSect, const char *pKey, bool bValue, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:193
std::string m_strIniFileUsedBy
Definition: IniFile.h:300
int WriteKeyValue(const char *pSect, const char *pKey, const char *pBuf, bool bWarnIfNotfound=true)
Definition: IniFile.cpp:77


cob_utilities
Author(s): Christian Connette
autogenerated on Wed Apr 7 2021 02:11:52