1 // Aseprite
2 // Copyright (C) 2001-2016  David Capello
3 //
4 // This program is distributed under the terms of
5 // the End-User License Agreement for Aseprite.
6 
7 #ifndef APP_INI_FILE_H_INCLUDED
8 #define APP_INI_FILE_H_INCLUDED
9 #pragma once
10 
11 #include "app/color.h"
12 #include "gfx/point.h"
13 #include "gfx/rect.h"
14 
15 namespace app {
16 
17   class ConfigModule {
18   public:
19     ConfigModule();
20     ~ConfigModule();
21   };
22 
23   void push_config_state();
24   void pop_config_state();
25   void flush_config_file();
26   void set_config_file(const char* filename);
27 
28   std::string main_config_filename();
29 
30   const char* get_config_string(const char* section, const char* name, const char* value);
31   void set_config_string(const char* section, const char* name, const char* value);
32 
33   int get_config_int(const char* section, const char* name, int value);
34   void set_config_int(const char* section, const char* name, int value);
35 
36   float get_config_float(const char* section, const char* name, float value);
37   void set_config_float(const char* section, const char* name, float value);
38 
39   double get_config_double(const char* section, const char* name, double value);
40   void set_config_double(const char* section, const char* name, double value);
41 
42   bool get_config_bool(const char* section, const char* name, bool value);
43   void set_config_bool(const char* section, const char* name, bool value);
44 
45   gfx::Point get_config_point(const char* section, const char* name, const gfx::Point& point);
46   void set_config_point(const char* section, const char* name, const gfx::Point& point);
47 
48   gfx::Rect get_config_rect(const char* section, const char* name, const gfx::Rect& rect);
49   void set_config_rect(const char* section, const char* name, const gfx::Rect& rect);
50 
51   app::Color get_config_color(const char* section, const char* name, const app::Color& value);
52   void set_config_color(const char* section, const char* name, const app::Color& value);
53 
54   void del_config_value(const char* section, const char* name);
55 
56   // Generic get/set_config_value functions
57 
get_config_value(const char * section,const char * name,const char * value)58   inline const char* get_config_value(const char* section, const char* name, const char* value) {
59     return get_config_string(section, name, value);
60   }
61 
get_config_value(const char * section,const char * name,const std::string & value)62   inline std::string get_config_value(const char* section, const char* name, const std::string& value) {
63     return get_config_string(section, name, value.c_str());
64   }
65 
get_config_value(const char * section,const char * name,bool value)66   inline bool get_config_value(const char* section, const char* name, bool value) {
67     return get_config_bool(section, name, value);
68   }
69 
70   template<typename T>
get_config_value(const char * section,const char * name,const T & value)71   inline T get_config_value(const char* section, const char* name, const T& value) {
72     return static_cast<T>(get_config_int(section, name, static_cast<int>(value)));
73   }
74 
get_config_value(const char * section,const char * name,float value)75   inline float get_config_value(const char* section, const char* name, float value) {
76     return get_config_float(section, name, value);
77   }
78 
get_config_value(const char * section,const char * name,double value)79   inline double get_config_value(const char* section, const char* name, double value) {
80     return get_config_double(section, name, value);
81   }
82 
get_config_value(const char * section,const char * name,const gfx::Point & value)83   inline gfx::Point get_config_value(const char* section, const char* name, const gfx::Point& value) {
84     return get_config_point(section, name, value);
85   }
86 
get_config_value(const char * section,const char * name,const gfx::Rect & value)87   inline gfx::Rect get_config_value(const char* section, const char* name, const gfx::Rect& value) {
88     return get_config_rect(section, name, value);
89   }
90 
get_config_value(const char * section,const char * name,const app::Color & value)91   inline app::Color get_config_value(const char* section, const char* name, const app::Color& value) {
92     return get_config_color(section, name, value);
93   }
94 
set_config_value(const char * section,const char * name,const char * value)95   inline void set_config_value(const char* section, const char* name, const char* value) {
96     set_config_string(section, name, value);
97   }
98 
set_config_value(const char * section,const char * name,const std::string & value)99   inline void set_config_value(const char* section, const char* name, const std::string& value) {
100     set_config_string(section, name, value.c_str());
101   }
102 
set_config_value(const char * section,const char * name,bool value)103   inline void set_config_value(const char* section, const char* name, bool value) {
104     set_config_bool(section, name, value);
105   }
106 
107   template<typename T>
set_config_value(const char * section,const char * name,const T & value)108   inline void set_config_value(const char* section, const char* name, const T& value) {
109     set_config_int(section, name, static_cast<int>(value));
110   }
111 
set_config_value(const char * section,const char * name,float value)112   inline void set_config_value(const char* section, const char* name, float value) {
113     set_config_float(section, name, value);
114   }
115 
set_config_value(const char * section,const char * name,double value)116   inline void set_config_value(const char* section, const char* name, double value) {
117     set_config_double(section, name, value);
118   }
119 
set_config_value(const char * section,const char * name,const gfx::Point & value)120   inline void set_config_value(const char* section, const char* name, const gfx::Point& value) {
121     set_config_point(section, name, value);
122   }
123 
set_config_value(const char * section,const char * name,const gfx::Rect & value)124   inline void set_config_value(const char* section, const char* name, const gfx::Rect& value) {
125     set_config_rect(section, name, value);
126   }
127 
set_config_value(const char * section,const char * name,const app::Color & value)128   inline void set_config_value(const char* section, const char* name, const app::Color& value) {
129     set_config_color(section, name, value);
130   }
131 
132 } // namespace app
133 
134 #endif
135