Made on Kubuntu
00001 // Copyright (C) 2009-2010 Ferdinand Majerech 00002 // This file is part of MiniINI 00003 // For conditions of distribution and use, see copyright notice in LICENSE.txt 00004 00005 #ifndef INIFILE_H_INCLUDED 00006 #define INIFILE_H_INCLUDED 00007 00008 #include "typedefs.h" 00009 #include "allocator.h" 00010 #include "inisection.h" 00011 #include <cassert> 00013 00015 enum BenchmarkType 00016 { 00017 BT_STRING, 00018 BT_INT, 00019 BT_FLOAT, 00020 BT_BOOL, 00021 BT_MULTISTRING, 00022 BT_MULTIINT, 00023 BT_MULTIFLOAT, 00024 BT_MULTIBOOL, 00025 BT_STRINGS, 00026 BT_INTS, 00027 BT_FLOATS, 00028 BT_BOOLS 00029 }; 00031 00033 00036 class INIFile 00037 { 00038 friend class ReadMark; 00039 friend class INIFileSTL; 00040 00041 private: 00042 00044 miniini_private::ui Length; 00046 INISection * * Sections; 00048 miniini_private::Allocator * Alloc; 00049 00050 00051 public: 00052 00054 INIFile() 00055 :Length(0) 00056 ,Sections(NULL) 00057 ,Alloc(NULL) 00058 {} 00059 00061 00068 bool OpenFile(const char * const fname); 00069 00071 00078 #ifndef INI_NO_STL 00079 bool OpenFile (const std::string & fname) 00080 { 00081 return OpenFile(fname.c_str()); 00082 } 00083 #endif 00084 00086 00094 bool LoadBuffer(const char * buf, unsigned size); 00095 00097 00100 ~INIFile(); 00101 00103 00108 INISection * GetSection(const char * const name) const; 00109 00111 00116 #ifndef INI_NO_STL 00117 INISection * GetSection(const std::string & name) const 00118 { 00119 assert(IsValid()); 00120 return GetSection(name.c_str()); 00121 } 00122 #endif 00123 00125 00130 INISection * operator [] (const char * const name) const 00131 { 00132 assert(IsValid()); 00133 assert(name); 00134 return GetSection(name); 00135 } 00136 00138 00143 #ifndef INI_NO_STL 00144 INISection * operator [] (const std::string & name) const 00145 { 00146 assert(IsValid()); 00147 return GetSection(name); 00148 } 00149 #endif 00150 00152 unsigned GetLength() const 00153 { 00154 return static_cast<unsigned>(Length); 00155 } 00156 00158 bool IsValid() const 00159 { 00160 //If any of these is 0/NULL, this INIFile was constructed 00161 //but not initialised. 00162 return Length && Sections && Alloc; 00163 } 00164 00165 private: 00166 00167 INIFile(const INIFile &); 00168 00169 void operator = (const INIFile &); 00170 00172 00175 void Benchmark(BenchmarkType type, bool stl); 00176 }; 00177 00178 #endif