nomlib
Loading...
Searching...
No Matches
IConfigFile.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SERIALIZERS_ICONFIG_FILE_HPP
30#define NOMLIB_SERIALIZERS_ICONFIG_FILE_HPP
31
32#include <memory>
33#include <map>
34
35#include "nomlib/config.hpp"
36#include "nomlib/ptree/Value.hpp"
37
38#include "nomlib/math/Point2.hpp"
39
40// #define NOM_DEBUG_SERIALIZERS_ICONFIG_FILE
41
42namespace nom {
43
44// Forward declarations
47
53{
54 public:
55 typedef IConfigFile self_type;
56
57 typedef self_type* raw_ptr;
58 typedef std::unique_ptr<self_type> unique_ptr;
59 typedef std::shared_ptr<self_type> shared_ptr;
60
61 typedef std::pair<std::string, Value> Pair;
62 typedef std::map<std::string, Value> value_type;
63
65 friend class JsonConfigFile;
66
68 IConfigFile( void );
69
71 virtual ~IConfigFile( void );
72
74 virtual IValueDeserializer* deserializer( void ) const = 0;
75
77 virtual IValueSerializer* serializer( void ) const = 0;
78
80 virtual bool flush( void ) = 0;
81
83 virtual bool load( void ) = 0;
84
86 virtual bool save( void ) = 0;
87
92 const std::string& filename( void ) const;
93
95 bool exists( const std::string& key ) const;
96
98 int get_int( const std::string& key, int default_value ) const;
99
101 uint get_uint( const std::string& key, uint default_value ) const;
102
104 double get_double( const std::string& key, double default_value ) const;
105
107 const std::string get_string( const std::string& key, const std::string& default_value ) const;
108
110 bool get_bool( const std::string& key, bool default_value ) const;
111
116 void set_property( const std::string& key, const Value& value );
117
121 bool erase( const std::string& key );
122
127 void set_filename( const std::string& filename );
128
129 private:
131 const value_type& get( void ) const;
132
134 std::string filename_;
135
137 value_type config_;
138};
139
140} // namespace nom
141
142#endif // include guard defined
value_type config_
The internal configuration storage map.
double get_double(const std::string &key, double default_value) const
std::string filename_
File I/O path.
virtual IValueSerializer * serializer(void) const =0
bool get_bool(const std::string &key, bool default_value) const
virtual bool load(void)=0
Deserialize the configuration from the set file path.
void set_property(const std::string &key, const Value &value)
Write a value to the configuration, mapped by key.
IConfigFile(void)
Default constructor.
bool erase(const std::string &key)
Destroy a configuration item.
const std::string get_string(const std::string &key, const std::string &default_value) const
virtual bool save(void)=0
Serialize the current configuration to the set file path.
uint get_uint(const std::string &key, uint default_value) const
int get_int(const std::string &key, int default_value) const
const value_type & get(void) const
Internal getter method for the storage container.
void set_filename(const std::string &filename)
Set the file I/O path.
virtual IValueDeserializer * deserializer(void) const =0
bool exists(const std::string &key) const
Check to see if an existing configuration key exists.
virtual ~IConfigFile(void)
Destructor.
const std::string & filename(void) const
Obtain the set file path.
friend class JsonConfigFile
Access to our (private) get method; returns value_type container.
virtual bool flush(void)=0
Force an output (save) of the current configuration.
Abstract interface for loading nom::Value objects.
Abstract interface for saving nom::Value objects.
Generic interface for opaque data containers.
Definition Value.hpp:43