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