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 "globals.h" 00010 #include "allocator.h" 00011 #include "inisection.h" 00012 #include "miniini_assert.h" 00013 00029 00030 class INIFile 00031 { 00032 private: 00033 00035 miniini_private::ui Length; 00037 INISection * * Sections; 00039 miniini_private::Allocator * Alloc; 00041 miniini_private::i Iter; 00042 00043 00044 public: 00045 00047 INIFile() 00048 :Length(0) 00049 ,Sections(NULL) 00050 ,Alloc(NULL) 00051 ,Iter(-1) 00052 {} 00053 00055 void Reset() 00056 { 00057 Iter = -1; 00058 } 00059 00064 bool Next() 00065 { 00066 if(Iter < static_cast<miniini_private::i>(Length) - 1) 00067 { 00068 ++Iter; 00069 return true; 00070 } 00071 return false; 00072 } 00073 00081 bool OpenFile(const char * const fname); 00082 00090 #ifndef MINIINI_NO_STL 00091 bool OpenFile (const std::string & fname) 00092 { 00093 return OpenFile(fname.c_str()); 00094 } 00095 #endif 00096 00107 bool LoadBuffer(const char * buf, unsigned size); 00108 00112 ~INIFile(); 00113 00119 INISection * GetSection(const char * const name) const; 00120 00126 #ifndef MINIINI_NO_STL 00127 INISection * GetSection(const std::string & name) const 00128 { 00129 return GetSection(name.c_str()); 00130 } 00131 #endif 00132 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 00150 #ifndef MINIINI_NO_STL 00151 INISection * operator [] (const std::string & name) const 00152 { 00153 return GetSection(name); 00154 } 00155 #endif 00156 00160 unsigned GetLength() const 00161 { 00162 return static_cast<unsigned>(Length); 00163 } 00164 00169 bool IsValid() const 00170 { 00171 //If any of these is 0/NULL, this INIFile was constructed 00172 //but not initialised. (Length will be at least 1 after 00173 //initialization due to default section) 00174 return Length && Sections && Alloc; 00175 } 00176 00177 private: 00178 00187 static inline miniini_private::ui Header(const miniini_private::c * & currentcharref, 00188 miniini_private::c * & header, 00189 miniini_private::ui & headercap); 00190 00191 INIFile(const INIFile &); 00192 00193 void operator = (const INIFile &); 00194 }; 00195 00196 #endif