tizen 2.4 release
[framework/convergence/service/service-plugin-client.git] / include / pluginConfig.hpp
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef PLUGIN_CONFIG_HPP_INCLUDED
18 #define PLUGIN_CONFIG_HPP_INCLUDED
19
20 /**
21  * @file pluginConfig.hpp
22  * @author
23  * @date
24  *
25  * @author
26  *
27  * @brief
28  */
29
30 // comment this to enter release mode (i.e. diable couts)
31 #define DEBUG
32
33 // debug and printing
34 #ifdef DEBUG
35 #include <iostream>
36 #endif
37
38 #include "pluginConfigTypes.h"
39
40 /**
41  * @brief Namespace for all content related to plugin.
42  **/
43 namespace plugin
44 {
45     /**
46      * Internal backing storage for configuration.
47      */
48     namespace internal
49     {
50         class ConfigData;
51     }
52
53     /**
54      * @brief General-purpose, class for loading and reading configuration from
55      * simple plaintext files.
56      **/
57     class Config
58     {
59     public:
60         /**
61         * @brief Constructor
62         *
63         **/
64         Config();
65
66         /**
67         * @brief Destructor
68         *
69         **/
70         virtual ~Config();
71
72         /**
73         * @brief Loads configuration to memory and/or gets raw data from configuration.
74         *
75         * @param section will return value attached to a key from this section
76         * @param key will return value attached to this key
77         * @return :string
78         **/
79         std::string _getRaw(const std::string &section, const std::string &key);
80
81         /**
82         * @brief Loads configuration to memory and/or gets raw data from configuration.
83         *
84         * @param section will return value attached to a key from this section
85         * @param key will return value attached to this key
86         * @return :string pointer
87         **/
88         const std::string *_getRawPtr(const std::string &section, const std::string &key);
89
90     public:
91         /**
92         * @brief Loads the configuration from a given file into memory.
93         *
94         * @param filepath path to the configuration file that will be loaded
95         * @param type expected type of configuration file, this value determines
96         * how the file is parsed
97         * @return int return true if successful, false otherwise
98         **/
99         bool load(const std::string &filepath, PluginConfigType type);
100
101         /**
102         * @brief Unloads the configuration from the memory.
103         *
104         * The configuration is automatically unloaded when the Config object is
105         * destoyed, so this method does not have to be executed unless you need
106         * to extremely lower memory usage and few bytes matter.
107         *
108         * @return void
109         **/
110         void unload();
111
112         /**
113          * @brief Checks wheteher config file has been loaded.
114          *
115          * @return bool  return true if successful, false otherwise
116          **/
117         bool isLoaded();
118
119     public:
120         /**
121         * @brief From loaded configuration, gets string value attached to given key.
122         *
123         * @param section ...
124         * @param key ...
125         * @return :string value attached to the key from the section
126         **/
127         std::string getString(const std::string &section, const std::string &key);
128
129         /**
130         * @brief From loaded configuration, gets string pointer attached to given key.
131         *
132         * @param section ...
133         * @param key ...
134         * @return :string pointer attached to the key from the section
135         **/
136         const std::string *getStringPtr(const std::string &section, const std::string &key);
137
138         /**
139         * @brief From loaded configuration, gets integer value attached to given key.
140         *
141         * @param section will return value attached to a key from this section
142         * @param key will return value attached to this key
143         * @return int
144         **/
145         int getInt(const std::string &section, const std::string &key);
146
147         /**
148         * @brief From _loaded configuration, gets double value attached to given key.
149         *
150         * @param section will return value attached to a key from this section
151         * @param key will return value attached to this key
152         * @return double
153         **/
154         double getDouble(const std::string &section, const std::string &key);
155
156     private:
157         bool _loaded;
158         internal::ConfigData *_configuration;
159     };
160 }
161 #endif /* PLUGIN_CONFIG_HPP_INCLUDED */