- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

uproperties.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/util/uproperties.hpp 00008 begin : Wed Feb 6 2002 00009 $Id: uproperties.hpp,v 1.11 2005/05/21 15:17:23 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UPROPERTIES_HPP 00029 #define UPROPERTIES_HPP 00030 00031 #include "../uobject.hpp" 00032 00033 #include <vector> 00034 #include <map> 00035 00036 namespace ufo { 00037 00044 class UFO_EXPORT UProperties : public UObject { 00045 UFO_DECLARE_DYNAMIC_CLASS(UProperties) 00046 public: // Public types 00048 class Reader : public virtual UObject { 00049 public: 00053 virtual void read(std::istream & streamA, UProperties * propA) = 0; 00054 }; 00055 00056 class Writer : public virtual UObject { 00057 public: 00060 virtual void write(std::ostream & streamA, UProperties * propA) = 0; 00061 }; 00062 00063 public: 00064 UProperties(); 00065 UProperties(const std::string & fileNameA); 00066 00067 // overrides UObject 00068 UObject * clone(); 00069 00070 void setReader(Reader * p); 00071 Reader * getReader(); 00072 00073 void setWriter(Writer * p); 00074 Writer * getWriter(); 00075 00076 void load(const std::string & fileNameA); 00077 void load(std::istream & streamA); 00078 00079 void save(std::ostream & streamA); 00080 void save(const std::string & fileNameA); 00081 00083 std::string get(const std::string & keyA); 00084 void put(const std::string & keyA, const std::string & valueA); 00085 00087 std::vector<std::string> getKeys(); 00088 00090 void clear(); 00091 00092 // 00093 //nested properties functions 00094 // 00095 void putChild(const std::string & keyA, UProperties * propA); 00096 UProperties * getChild(const std::string & keyA); 00097 00099 std::vector<std::string> getChildKeys(); 00100 00101 public: // Protected types 00102 typedef std::map<std::string, std::string> propertiesMap; 00103 typedef std::map<std::string, UProperties*> childMap; 00104 00105 private: // Private attributes 00106 propertiesMap m_hash; 00107 childMap m_children; 00108 00109 Reader * m_reader; 00110 Writer * m_writer; 00111 }; 00112 00113 class UINIReader : public UProperties::Reader { 00114 public: 00115 void read(std::istream & streamA, UProperties * propA); 00116 00117 protected: 00118 void parse(char * buffer, unsigned int n); 00119 00120 UProperties * m_localProp; 00121 UProperties * m_nestedProp; 00122 }; 00123 00124 class UINIWriter : public UProperties::Writer { 00125 public: 00126 void write(std::ostream & streamA, UProperties * propA); 00127 }; 00128 00129 00130 00131 // 00132 // inline implementation 00133 // 00134 00135 00136 inline std::string 00137 UProperties::get(const std::string & keyA) { 00138 // avoid creation of empty key, value pair 00139 propertiesMap::const_iterator iter; 00140 iter = m_hash.find(keyA); 00141 00142 if (iter != m_hash.end()) { 00143 return (*iter).second; 00144 } else { 00145 return ""; 00146 } 00147 } 00148 00149 inline void 00150 UProperties::put(const std::string & keyA, const std::string & valueA) { 00151 m_hash[keyA] = valueA; 00152 //(*((m_hash.insert(value_type(keyA, data_type()))).first)).second = valueA; 00153 } 00154 00155 00156 inline std::vector<std::string> 00157 UProperties::getKeys() { 00158 std::vector<std::string> ret; 00159 00160 for(propertiesMap::const_iterator iter = m_hash.begin(); 00161 iter != m_hash.end(); 00162 ++iter) { 00163 ret.push_back((*iter).first); 00164 } 00165 return ret; 00166 } 00167 00168 00169 00170 } // namespace ufo 00171 00172 #endif // UPROPERTIES_HPP

The libUFO Project - written by Johannes Schmidt