tbx  0.7.5
propertyset.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_PROPERTYSET_H_
26 #define TBX_PROPERTYSET_H_
27 
28 #include <string>
29 #include <map>
30 #include <iostream>
31 
32 namespace tbx {
33 
40 class PropertySet {
41 public:
42 
49  bool exists(std::string name) const;
50 
57  void set(std::string name, std::string value);
58 
65  void set(std::string name, const char *value);
66 
74  std::string get(std::string name, const char *def ="") const;
75 
82  void set(std::string name, int value);
83 
91  int get(std::string name, int def) const;
92 
99  void set(std::string name, bool value);
107  bool get(std::string name, bool def) const;
108 
115  bool erase(std::string name);
116 
127  void set_indexed(std::string name, int index, std::string value);
139  std::string get_indexed(std::string name, int index, const char *def = "") const;
150  void set_indexed(std::string name, int index, int value);
162  int get_indexed(std::string name, int index, int def) const;
173  void set_indexed(std::string name, int index, bool value);
185  bool get_indexed(std::string name, int index, bool def) const;
186 
194  bool exists_indexed(std::string name, int index);
202  bool erase_indexed(std::string name, int index);
203 
210  bool write(std::ostream &os) const;
211 
223  bool read(std::istream &is);
224 
228  void clear();
229 
233  bool empty();
240  bool save(std::string file_name) const;
247  bool load(std::string file_name);
248 
249 protected:
253  std::map<std::string,std::string> _properties;
254 };
255 
256 }
257 
258 #endif /* TBX_PROPERTYSET_H_ */
std::map< std::string, std::string > _properties
Underlying map to contain the properties.
Definition: propertyset.h:253
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
bool save(std::string file_name) const
Save property set to a file.
Definition: propertyset.cc:225
bool erase_indexed(std::string name, int index)
Erase an indexed property.
Definition: propertyset.cc:147
void set_indexed(std::string name, int index, std::string value)
Set an indexed string property.
Definition: propertyset.cc:86
bool exists_indexed(std::string name, int index)
Check if the property set contains the indexed property.
Definition: propertyset.cc:140
bool empty()
Check if property set is empty.
Definition: propertyset.cc:220
bool load(std::string file_name)
Load property set from a file.
Definition: propertyset.cc:232
Maintain a simple set of string properties with their values.
Definition: propertyset.h:40
bool read(std::istream &is)
Reads the properties from a stream.
Definition: propertyset.cc:174
bool exists(std::string name) const
Check if property is a member of this property set.
Definition: propertyset.cc:32
void clear()
Remove all properties from the property set.
Definition: propertyset.cc:215
bool erase(std::string name)
Erases a property from the set.
Definition: propertyset.cc:128
std::string get_indexed(std::string name, int index, const char *def="") const
Get the value of an indexed string property.
Definition: propertyset.cc:93
bool write(std::ostream &os) const
Writes the property list to a stream.
Definition: propertyset.cc:155