1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/**
* @file llcontrol.h
* @brief A mechanism for storing "control state" for a program
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#ifndef LL_LLCONTROL_H
#define LL_LLCONTROL_H
#include "llevent.h"
#include "llnametable.h"
#include "llmap.h"
#include "llstring.h"
#include "llrect.h"
#include "llcontrolgroupreader.h"
#include <vector>
// *NOTE: boost::visit_each<> generates warning 4675 on .net 2003
// Disable the warning for the boost includes.
#if LL_WINDOWS
# if (_MSC_VER >= 1300 && _MSC_VER < 1400)
# pragma warning(push)
# pragma warning( disable : 4675 )
# endif
#endif
#include <boost/bind.hpp>
#include <boost/signal.hpp>
#if LL_WINDOWS
# if (_MSC_VER >= 1300 && _MSC_VER < 1400)
# pragma warning(pop)
# endif
#endif
class LLVector3;
class LLVector3d;
class LLColor4;
class LLColor3;
class LLColor4U;
const BOOL NO_PERSIST = FALSE;
typedef enum e_control_type
{
TYPE_U32 = 0,
TYPE_S32,
TYPE_F32,
TYPE_BOOLEAN,
TYPE_STRING,
TYPE_VEC3,
TYPE_VEC3D,
TYPE_RECT,
TYPE_COL4,
TYPE_COL3,
TYPE_COL4U,
TYPE_LLSD,
TYPE_COUNT
} eControlType;
class LLControlVariable : public LLRefCount
{
friend class LLControlGroup;
typedef boost::signal<void(const LLSD&)> signal_t;
private:
std::string mName;
std::string mComment;
eControlType mType;
bool mPersist;
bool mHideFromSettingsEditor;
std::vector<LLSD> mValues;
signal_t mSignal;
public:
LLControlVariable(const std::string& name, eControlType type,
LLSD initial, const std::string& comment,
bool persist = true, bool hidefromsettingseditor = false);
virtual ~LLControlVariable();
const std::string& getName() const { return mName; }
const std::string& getComment() const { return mComment; }
eControlType type() { return mType; }
bool isType(eControlType tp) { return tp == mType; }
void resetToDefault(bool fire_signal = false);
signal_t* getSignal() { return &mSignal; }
bool isDefault() { return (mValues.size() == 1); }
bool isSaveValueDefault();
bool isPersisted() { return mPersist; }
bool isHiddenFromSettingsEditor() { return mHideFromSettingsEditor; }
LLSD get() const { return getValue(); }
LLSD getValue() const { return mValues.back(); }
LLSD getDefault() const { return mValues.front(); }
LLSD getSaveValue() const;
void set(const LLSD& val) { setValue(val); }
void setValue(const LLSD& value, bool saved_value = TRUE);
void setDefaultValue(const LLSD& value);
void setPersist(bool state);
void setHiddenFromSettingsEditor(bool hide);
void setComment(const std::string& comment);
void firePropertyChanged()
{
mSignal(mValues.back());
}
private:
LLSD getComparableValue(const LLSD& value);
bool llsd_compare(const LLSD& a, const LLSD & b);
};
//const U32 STRING_CACHE_SIZE = 10000;
class LLControlGroup : public LLControlGroupReader
{
protected:
typedef std::map<std::string, LLPointer<LLControlVariable> > ctrl_name_table_t;
ctrl_name_table_t mNameTable;
std::set<std::string> mWarnings;
std::string mTypeString[TYPE_COUNT];
eControlType typeStringToEnum(const std::string& typestr);
std::string typeEnumToString(eControlType typeenum);
public:
LLControlGroup();
~LLControlGroup();
void cleanup();
LLPointer<LLControlVariable> getControl(const std::string& name);
struct ApplyFunctor
{
virtual ~ApplyFunctor() {};
virtual void apply(const std::string& name, LLControlVariable* control) = 0;
};
void applyToAll(ApplyFunctor* func);
BOOL declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor = FALSE);
BOOL declareU32(const std::string& name, U32 initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareS32(const std::string& name, S32 initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareF32(const std::string& name, F32 initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareBOOL(const std::string& name, BOOL initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareString(const std::string& name, const std::string &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareVec3(const std::string& name, const LLVector3 &initial_val,const std::string& comment, BOOL persist = TRUE);
BOOL declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareColor4U(const std::string& name, const LLColor4U &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareLLSD(const std::string& name, const LLSD &initial_val, const std::string& comment, BOOL persist = TRUE);
std::string findString(const std::string& name);
std::string getString(const std::string& name);
LLWString getWString(const std::string& name);
std::string getText(const std::string& name);
LLVector3 getVector3(const std::string& name);
LLVector3d getVector3d(const std::string& name);
LLRect getRect(const std::string& name);
BOOL getBOOL(const std::string& name);
S32 getS32(const std::string& name);
F32 getF32(const std::string& name);
U32 getU32(const std::string& name);
LLSD getLLSD(const std::string& name);
// Note: If an LLColor4U control exists, it will cast it to the correct
// LLColor4 for you.
LLColor4 getColor(const std::string& name);
LLColor4U getColor4U(const std::string& name);
LLColor4 getColor4(const std::string& name);
LLColor3 getColor3(const std::string& name);
void setBOOL(const std::string& name, BOOL val);
void setS32(const std::string& name, S32 val);
void setF32(const std::string& name, F32 val);
void setU32(const std::string& name, U32 val);
void setString(const std::string& name, const std::string& val);
void setVector3(const std::string& name, const LLVector3 &val);
void setVector3d(const std::string& name, const LLVector3d &val);
void setRect(const std::string& name, const LLRect &val);
void setColor4U(const std::string& name, const LLColor4U &val);
void setColor4(const std::string& name, const LLColor4 &val);
void setColor3(const std::string& name, const LLColor3 &val);
void setLLSD(const std::string& name, const LLSD& val);
void setValue(const std::string& name, const LLSD& val);
BOOL controlExists(const std::string& name);
// Returns number of controls loaded, 0 if failed
// If require_declaration is false, will auto-declare controls it finds
// as the given type.
U32 loadFromFileLegacy(const std::string& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING);
U32 saveToFile(const std::string& filename, BOOL nondefault_only);
U32 loadFromFile(const std::string& filename, bool default_values = false);
void resetToDefaults();
// Ignorable Warnings
// Add a config variable to be reset on resetWarnings()
void addWarning(const std::string& name);
BOOL getWarning(const std::string& name);
void setWarning(const std::string& name, BOOL val);
// Resets all ignorables
void resetWarnings();
};
///////////////////////
namespace jc_you_suck
{
class jc_rebind
{
template <typename REC> static void rebind_callback(const LLSD &data, REC *reciever){ *reciever = data; }
typedef boost::signal<void(const LLSD&)> signal_t;
public:
//#define binder_debug
template <typename RBTYPE> static RBTYPE* rebind_llcontrol(std::string name, LLControlGroup* controlgroup, bool init)
{
static std::map<LLControlGroup*, std::map<std::string, void*> > references;
#ifdef binder_debug
llinfos << "rebind_llcontrol" << llendl;
#endif
RBTYPE* type = NULL;
if(controlgroup)
{
if(references.find(controlgroup) == references.end())
{
#ifdef binder_debug
llinfos << "was no map for a group, adding" << llendl;
#endif
references[controlgroup] = std::map<std::string, void*>();
}
if(references[controlgroup].find(name) != references[controlgroup].end())
{
#ifdef binder_debug
llinfos << "pulling type from map for " << name << llendl;
#endif
type = (RBTYPE*)(references[controlgroup][name]);
if(type == NULL)llerrs << "bad type stored" << llendl;
}else
{
#ifdef binder_debug
llinfos << "creating type in map for " << name << llendl;
#endif
type = new RBTYPE();
references[controlgroup][name] = (void*)type;
LLControlVariable* control = controlgroup->getControl(name);
if(control)
{
#ifdef binder_debug
llinfos << "control there " << name << llendl;
#endif
signal_t* signal = control->getSignal();
if(signal)
{
#ifdef binder_debug
llinfos << "signal there" << name << llendl;
#endif
signal->connect(boost::bind(&jc_rebind::rebind_callback<RBTYPE>, _1, type));
if(init)jc_rebind::rebind_callback<RBTYPE>(control->getValue(),type);
}else llerrs << "no signal!" << llendl;
}else llerrs << "no control for " << name << "!" << llendl;
}
}
return type;
}
};
template <> void jc_rebind::rebind_callback<S32>(const LLSD &data, S32 *reciever);
template <> void jc_rebind::rebind_callback<F32>(const LLSD &data, F32 *reciever);
template <> void jc_rebind::rebind_callback<U32>(const LLSD &data, U32 *reciever);
template <> void jc_rebind::rebind_callback<std::string>(const LLSD &data, std::string *reciever);
template <> void jc_rebind::rebind_callback<LLColor4>(const LLSD &data, LLColor4 *reciever);
}
using namespace jc_you_suck;
#define rebind_llcontrol jc_rebind::rebind_llcontrol
///////////////////////
#endif
|