1 /* 2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef INIFILE_H 27 #define INIFILE_H 28 29 #include "Platform.h" 30 #include "OrderedMap.h" 31 32 #include <map> 33 34 35 class IniSectionData : public IPropertyContainer { 36 private: 37 OrderedMap<TString, TString> FMap; 38 39 public: 40 IniSectionData(); 41 IniSectionData(OrderedMap<TString, TString> Values); 42 43 std::vector<TString> GetKeys(); 44 std::list<TString> GetLines(); 45 OrderedMap<TString, TString> GetData(); 46 47 bool SetValue(const TString Key, TString Value); 48 void Append(OrderedMap<TString, TString> Values); 49 50 virtual bool GetValue(const TString Key, TString& Value); 51 virtual size_t GetCount(); 52 }; 53 54 55 class IniFile : public ISectionalPropertyContainer { 56 private: 57 OrderedMap<TString, IniSectionData*> FMap; 58 59 public: 60 IniFile(); 61 virtual ~IniFile(); 62 63 void internalTest(); 64 65 bool LoadFromFile(const TString FileName); 66 bool SaveToFile(const TString FileName, bool ownerOnly = true); 67 68 void Append(const TString SectionName, const TString Key, TString Value); 69 void AppendSection(const TString SectionName, 70 OrderedMap<TString, TString> Values); 71 bool SetValue(const TString SectionName, 72 const TString Key, TString Value); 73 74 // ISectionalPropertyContainer 75 virtual bool GetSection(const TString SectionName, 76 OrderedMap<TString, TString> &Data); 77 virtual bool ContainsSection(const TString SectionName); 78 virtual bool GetValue(const TString SectionName, 79 const TString Key, TString& Value); 80 }; 81 82 #endif // INIFILE_H 83