IniFile.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob3_common
00012  * ROS package name: inifiles_old
00013  * Description:
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Christian Connette, email:christian.connette@ipa.fhg.de
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: Feb 2009
00021  * ToDo: Remove it!
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00034  *       Engineering and Automation (IPA) nor the names of its
00035  *       contributors may be used to endorse or promote products derived from
00036  *       this software without specific prior written permission.
00037  *
00038  * This program is free software: you can redistribute it and/or modify
00039  * it under the terms of the GNU Lesser General Public License LGPL as 
00040  * published by the Free Software Foundation, either version 3 of the 
00041  * License, or (at your option) any later version.
00042  * 
00043  * This program is distributed in the hope that it will be useful,
00044  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00045  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00046  * GNU Lesser General Public License LGPL for more details.
00047  * 
00048  * You should have received a copy of the GNU Lesser General Public 
00049  * License LGPL along with this program. 
00050  * If not, see <http://www.gnu.org/licenses/>.
00051  *
00052  ****************************************************************/
00053 
00054 #ifndef _Inifile_H
00055 #define _Inifile_H
00056 
00057 #include <iostream>
00058 #include <vector>
00059 #include <string>
00060 #include <stdio.h>
00061 
00062 //-------------------------------------------------------------------
00063 
00064 
00097 class IniFile
00098 {
00099 public:
00100 
00104         IniFile();
00105 
00110         IniFile(std::string fileName);
00111         ~IniFile();
00112 
00122         int SetFileName(std::string fileName, std::string strIniFileUsedBy = "", bool bCreate = false);
00123 
00124 
00134         int WriteKeyString(const char* pSect, const char* pKey, const std::string* pStrToWrite, bool bWarnIfNotfound = true);
00135 
00145         int WriteKeyInt(const char* pSect,const char* pKey,int nValue, bool bWarnIfNotfound = true);
00146 
00157         int WriteKeyDouble(const char* pSect,const char* pKey,double dValue,int StringLen=12,int decimals=5, bool bWarnIfNotfound = true);
00158 
00168         int WriteKeyBool(const char* pSect, const char* pKey, bool bValue, bool bWarnIfNotfound = true);
00169 
00178         int GetKeyString(const char* pSect,const char* pKey, std::string* pStrToRead, 
00179                                                         bool bWarnIfNotfound = true);
00180 
00185         int GetKeyInt(const char* pSect,const char* pKey,int* pValue, 
00186                                                         bool bWarnIfNotfound = true);
00187 
00191         int GetKeyLong(const char* pSect,const char* pKey,long* pValue, 
00192                                                         bool bWarnIfNotfound = true);
00193 
00202         int GetKeyBool(const char* pSect, const char* pKey, bool* pValue, 
00203                                                         bool bWarnIfNotfound = true);
00204 
00213         int GetKeyDouble(const char* pSect,const char* pKey,double* pValue, 
00214                                                         bool bWarnIfNotfound = true);
00215 
00224         int GetKeyDouble(const char* pSect,const char* pKey,double* pValue, double dDefault,
00225                                                         bool bWarnIfNotfound = true);
00226 
00235         int GetKey(const char* pSect,const char* pKey, std::string* pStrToRead, bool bWarnIfNotfound = true);
00236 
00241         int GetKey(const char* pSect,const char* pKey,int* pValue, bool bWarnIfNotfound = true);
00242 
00251         int GetKey(const char* pSect, const char* pKey, bool* pValue, bool bWarnIfNotfound = true);
00252 
00261         int GetKey(const char* pSect,const char* pKey,double* pValue, bool bWarnIfNotfound = true);
00262 
00271         int FindNextSection(std::string* pSect, std::string prevSect, bool bWarnIfNotfound = true);
00272 
00273 private:
00274           
00275         int FindSection(const char* sect, bool bWarnIfNotfound = true);
00276         int FindKey(const char* skey,   bool bWarnIfNotfound = true);
00277         int FindNextLine(std::vector<char>& NewLine, int& CharInd);
00278 
00287         int WriteKeyValue(const char* pSect,const char* pKey,const char* pBuf, bool bWarnIfNotfound = true);
00288 
00300         int GetKeyValue(const char* pSect,const char* pKey, char* pBuf, int lenBuf, 
00301                                                         bool bWarnIfNotfound = true);
00302 
00308         int SkipLineUntil(FILE* pFile, const char EndChar);
00309 
00316         int ReadLineUntil(FILE* pFile, const char EndChar, std::string& ReadIntoStr);
00317 
00318         bool m_bFileOK;
00319 
00323         std::vector<char> m_CurLine;
00324 
00328         const int m_vectorSize;
00329 
00333     int m_CurCharInd;
00334 
00335         std::string m_fileName;
00336         std::string m_strIniFileUsedBy; //used for debug to inidcate user class of ini-file
00337         FILE* f;
00338 };
00339 
00340 #endif
00341 


cob_utilities
Author(s): Christian Connette
autogenerated on Sun Oct 5 2014 23:00:37