// // File : TIniFile.hh // // Purpose: Declaration of the class TIniFile // // Author : Jens Berger, berger@ikf.uni-frankfurt.de // // $Id: TIniFile.hh 11796 2010-12-15 08:04:14Z mathes $ // /** @file TIniFile.hh * Declaration of the class TIniFile. * @author Jens Berger, berger@ikf.uni-frankfurt.de */ #ifndef _FdRoot_TIniFile_hh_ #define _FdRoot_TIniFile_hh_ // system include files #include #include #include // ROOT includes #include namespace FdRoot { /** This class allows the user to read and write .INI files. * * Your application can read and write variables in sections of * the types string, integer, boolean and float. Based on J.B.'s version 0.01. * * Example: * \code // write to ini file ... TIniFile trackparameter("tracking.ini"); trackparameter.Write("Helixfit", "ChiSqrMax", 1.234); // read from ini file ... TIniFile trackparameter("tracking.ini"); float MaxChiSqr; trackparameter.Read("Helixfit", "ChiSqrMax", 1.0, MaxChiSqr); * \endcode */ class TIniFile { static const int kMaxInifileSize = 256000; public: /** Error/Status codes. */ typedef enum { kSuccess = 0, kSectionNotFound, kVariableNotFound, kWrongSection //<<< variable in other section } ETInifileStatusCode; /** Default constructor for the class TIniFile. */ TIniFile() { fFileName = ""; }; /** Constructor for the class TIniFile, that opens (or creates) an ini-file. */ TIniFile(const TString& filename); /** Destructor of the class TIniFile, closes file and cleans up. */ ~TIniFile(); /** Retrieve the name of the file currently in use. * * I preferred 'const char *' to 'TString&'. */ const char *GetFilename() { return fFileName.Data(); } /** Get the error code of the last operation. */ ETInifileStatusCode GetLastError() { return fLastErrorCode; } /** Get section from filestring. */ ETInifileStatusCode GetSection(const TString& Section, int& spos, int& sn, int& pos, int& n); /** Get section from filestring. */ ETInifileStatusCode GetSection(const TString& Section, int& spos, int& sn); /** Get start of var area in section from filestring. */ ETInifileStatusCode GetVarAreaInSection(const TString& Section, int& pos, int& n); /** Get variable from section in filestring. */ ETInifileStatusCode GetVarInSect(const TString& Section, const TString& Variable, int& lpos, int& ln ,int& pos, int& n); /** Get variable from section in filestring. */ ETInifileStatusCode GetVarDataInSect(const TString& Section, const TString& Variable, int& pos, int& n); /** Get variable from section in filestring. */ ETInifileStatusCode GetVarLineInSect(const TString& Section, const TString& Variable, int& lpos, int& ln); /** Remove section with all its variables. */ ETInifileStatusCode DeleteSection(const TString& Section); /** Remove variable in Section. */ ETInifileStatusCode DeleteVarInSect(const TString& Section, const TString& Variable); /** Read string. */ void Read(const TString& Section, const TString& Variable, const TString& Default, TString& Result); /** Read integers, booleans. */ void Read(const TString& Section, const TString& Variable, const int Default, int& Result); /** Read unsigned int. */ void Read(const TString& Section, const TString& Variable, const int Default, unsigned int& Result) { Read( Section, Variable, Default, (int&)Result ); } /** Read float. */ void Read(const TString& Section, const TString& Variable, const float Default, float& Result); /** Read double. */ void Read(const TString& Section, const TString& Variable, const double Default, double& Result); /** Write string. */ void Write(const TString& Section, const TString& Variable, const TString& Value); /** Write integers, booleans. */ void Write(const TString& Section, const TString& Variable, const int Value); /** Write unsigned int. */ void Write(const TString& Section, const TString& Variable, const unsigned int Value) { Write( Section, Variable, (const int &)Value); } /** Write float. */ void Write(const TString& Section, const TString& Variable, const float Value); /** Write double. */ void Write(const TString& Section, const TString& Variable, const double Value); private: // copy ctor. and assignment operator are not allowed TIniFile(const TIniFile&); TIniFile& operator=(const TIniFile&); TString fFileName; //! TString *fFStr; //! ETInifileStatusCode fLastErrorCode; //! }; } // namespace FdRoot #endif // _FdRoot_TIniFile_hh_