nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef INIFILE_H 00024 #define INIFILE_H 00025 00026 namespace nux 00027 { 00028 00029 class CIniFile 00030 { 00031 public: 00032 struct Record 00033 { 00034 std::string Comments; 00035 char Commented; 00036 std::string Section; 00037 std::string Key; 00038 std::string Value; 00039 }; 00040 00041 enum CommentChar 00042 { 00043 Pound = '#', 00044 SemiColon = ';' 00045 }; 00046 00047 CIniFile (void); 00048 virtual ~CIniFile (void); 00049 00050 static bool AddSection (std::string SectionName, std::string FileName); 00051 static bool CommentRecord (CommentChar cc, std::string KeyName, std::string SectionName, std::string FileName); 00052 static bool CommentSection (char CommentChar, std::string SectionName, std::string FileName); 00053 static std::string Content (std::string FileName); 00054 static bool Create (std::string FileName); 00055 static bool DeleteRecord (std::string KeyName, std::string SectionName, std::string FileName); 00056 static bool DeleteSection (std::string SectionName, std::string FileName); 00057 static std::vector<Record> GetRecord (std::string KeyName, std::string SectionName, std::string FileName); 00058 static std::vector<Record> GetSection (std::string SectionName, std::string FileName); 00059 static std::vector<std::string> GetSectionNames (std::string FileName); 00060 static std::string GetValue (std::string KeyName, std::string SectionName, std::string FileName); 00061 static bool RecordExists (std::string KeyName, std::string SectionName, std::string FileName); 00062 static bool RenameSection (std::string OldSectionName, std::string NewSectionName, std::string FileName); 00063 static bool SectionExists (std::string SectionName, std::string FileName); 00064 static bool SetRecordComments (std::string Comments, std::string KeyName, std::string SectionName, std::string FileName); 00065 static bool SetSectionComments (std::string Comments, std::string SectionName, std::string FileName); 00066 static bool SetValue (std::string KeyName, std::string Value, std::string SectionName, std::string FileName); 00067 static bool Sort (std::string FileName, bool Descending); 00068 static bool UnCommentRecord (std::string KeyName, std::string SectionName, std::string FileName); 00069 static bool UnCommentSection (std::string SectionName, std::string FileName); 00070 00071 private: 00072 static std::vector<Record> GetSections (std::string FileName); 00073 static bool Load (std::string FileName, std::vector<Record>& content); 00074 static bool Save (std::string FileName, std::vector<Record>& content); 00075 }; 00076 00077 } 00078 00079 #endif // INIFILE_H