00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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:
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
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
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:
00102
typedef std::map<std::string, std::string> propertiesMap;
00103
typedef std::map<std::string, UProperties*> childMap;
00104
00105
private:
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
00133
00134
00135
00136
inline std::string
00137 UProperties::get(
const std::string & keyA) {
00138
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
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 }
00171
00172
#endif // UPROPERTIES_HPP