]> Dogcows Code - chaz/openbox/blob - util/epist/config.cc
add the otk::Point type
[chaz/openbox] / util / epist / config.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // config.cc for Epistrophy - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifdef HAVE_CONFIG_H
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
26
27 #include "config.hh"
28
29 using std::string;
30
31 Config::Config() {}
32
33 Config::~Config()
34 {
35 // deallocate memory for the 3 lists
36 BoolItemList::const_iterator b_it, b_end = bool_items.end();
37 for (b_it = bool_items.begin(); b_it != b_end; ++b_it)
38 delete *b_it;
39 bool_items.clear();
40
41 NumberItemList::const_iterator n_it, n_end = number_items.end();
42 for (n_it = number_items.begin(); n_it != n_end; ++n_it)
43 delete *n_it;
44 number_items.clear();
45
46 StringItemList::const_iterator s_it, s_end = string_items.end();
47 for (s_it = string_items.begin(); s_it != s_end; ++s_it)
48 delete *s_it;
49 string_items.clear();
50 }
51
52
53 bool Config::getValue(Config::StringType type, string &ret) const
54 {
55 StringItemList::const_iterator it = string_items.begin(), end = string_items.end();
56 for (; it != end; ++it) {
57 if ((*it)->type == type) {
58 ret = (*it)->value;
59 return true;
60 }
61 }
62 return false;
63 }
64
65
66 bool Config::getValue(Config::NumberType type, int &ret) const
67 {
68 NumberItemList::const_iterator it = number_items.begin(), end = number_items.end();
69 for (; it != end; ++it) {
70 if ((*it)->type == type) {
71 ret = (*it)->value;
72 return true;
73 }
74 }
75 return false;
76 }
77
78
79 bool Config::getValue(Config::BoolType type, bool &ret) const
80 {
81 BoolItemList::const_iterator it = bool_items.begin(), end = bool_items.end();
82 for (; it != end; ++it) {
83 if ((*it)->type == type) {
84 ret = (*it)->value;
85 return true;
86 }
87 }
88 return false;
89 }
90
91
92 void Config::addOption(const std::string &name, const std::string &value)
93 {
94 const struct {
95 const char *name;
96 Config::BoolType type;
97 }
98 bool_options[] = {
99 { "stackedcycling", Config::stackedCycling },
100 { "stackedcyclingraise", Config::stackedCyclingRaise },
101 { "", NUM_BOOL_TYPES }
102 };
103
104 const struct {
105 const char *name;
106 Config::StringType type;
107 }
108 string_options[] = {
109 { "", NUM_STRING_TYPES }
110 };
111
112 const struct {
113 const char *name;
114 Config::NumberType type;
115 }
116 number_options[] = {
117 { "chaintimeout", chainTimeout },
118 { "workspacecolumns", workspaceColumns },
119 { "", NUM_NUMBER_TYPES }
120 };
121
122 // if it's bool option, add it to the bool_items list
123 size_t i = 0;
124 while (bool_options[i].type != NUM_BOOL_TYPES) {
125 if (strcasecmp(name.c_str(), bool_options[i].name) == 0) {
126 BoolItem *item = new BoolItem;
127 const char *tmp = value.c_str();
128
129 item->type = bool_options[i].type;
130
131 if (strcasecmp(tmp, "true") == 0 || strcasecmp(tmp, "1") == 0 ||
132 strcasecmp(tmp, "on") == 0)
133 item->value = true;
134 else
135 item->value = false;
136
137 bool_items.push_back(item);
138 return;
139 }
140 i++;
141 }
142
143 // if it's a string, add it to the string_items list
144 i = 0;
145 while (string_options[i].type != NUM_STRING_TYPES) {
146 if (strcasecmp(name.c_str(), string_options[i].name) == 0) {
147 StringItem *item = new StringItem;
148 item->type = string_options[i].type;
149 item->value = value;
150
151 string_items.push_back(item);
152 return;
153 }
154 i++;
155 }
156
157 // if it's a number, add it to the number_items list
158 i = 0;
159 while (number_options[i].type != NUM_NUMBER_TYPES) {
160 if (strcasecmp(name.c_str(), number_options[i].name) == 0) {
161 NumberItem *item = new NumberItem;
162 item->type = number_options[i].type;
163 item->value = atoi( value.c_str() );
164
165 number_items.push_back(item);
166 return;
167 }
168 i++;
169 }
170 }
This page took 0.041745 seconds and 4 git commands to generate.