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

