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 "miniini_assert.h" 00012 00014 00017 class INIFile 00018 { 00019 private: 00020 00022 miniini_private::ui Length; 00024 INISection * * Sections; 00026 miniini_private::Allocator * Alloc; 00028 miniini_private::i Iter; 00029 00030 00031 public: 00032 00033 #ifdef MINIINI_BENCH_EXTRA 00034 #ifdef linux 00035 00036 miniini_private::ld FileTime; 00037 #endif 00038 #endif 00039 00041 INIFile() 00042 :Length(0) 00043 ,Sections(NULL) 00044 ,Alloc(NULL) 00045 ,Iter(-1) 00046 {} 00047 00049 void Reset() 00050 { 00051 Iter = -1; 00052 } 00053 00055 00059 bool Next() 00060 { 00061 if(Iter < static_cast<miniini_private::i>(Length) - 1) 00062 { 00063 ++Iter; 00064 return true; 00065 } 00066 return false; 00067 } 00068 00070 00077 bool OpenFile(const char * const fname); 00078 00080 00087 #ifndef MINIINI_NO_STL 00088 bool OpenFile (const std::string & fname) 00089 { 00090 return OpenFile(fname.c_str()); 00091 } 00092 #endif 00093 00095 00103 bool LoadBuffer(const char * buf, unsigned size); 00104 00106 00109 ~INIFile(); 00110 00112 00117 INISection * GetSection(const char * const name) const; 00118 00120 00125 #ifndef MINIINI_NO_STL 00126 INISection * GetSection(const std::string & name) const 00127 { 00128 return GetSection(name.c_str()); 00129 } 00130 #endif 00131 00133 00138 INISection * operator [] (const char * const name) const 00139 { 00140 MINIINI_ASSERT(name, "NULL pointer was passed as section name to" 00141 "INIFile::operator []"); 00142 return GetSection(name); 00143 } 00144 00146 00151 #ifndef MINIINI_NO_STL 00152 INISection * operator [] (const std::string & name) const 00153 { 00154 return GetSection(name); 00155 } 00156 #endif 00157 00159 unsigned GetLength() const 00160 { 00161 return static_cast<unsigned>(Length); 00162 } 00163 00165 bool IsValid() const 00166 { 00167 //If any of these is 0/NULL, this INIFile was constructed 00168 //but not initialised. (Length will be at least 1 after 00169 //initialization due to default section) 00170 return Length && Sections && Alloc; 00171 } 00172 00173 private: 00174 00176 00184 static inline miniini_private::ui Header(const miniini_private::c * & currentcharref, 00185 miniini_private::c * & header, 00186 miniini_private::ui & headercap); 00187 00188 INIFile(const INIFile &); 00189 00190 void operator = (const INIFile &); 00191 }; 00192 00193 #endif