llcontrol.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLCONTROL_H
00033 #define LL_LLCONTROL_H
00034 
00035 #include "llevent.h"
00036 #include "llnametable.h"
00037 #include "llmap.h"
00038 #include "llstring.h"
00039 #include "llrect.h"
00040 
00041 #include <vector>
00042 
00043 // *NOTE: boost::visit_each<> generates warning 4675 on .net 2003
00044 // Disable the warning for the boost includes.
00045 #if LL_WINDOWS
00046 # if (_MSC_VER >= 1300 && _MSC_VER < 1400)
00047 #   pragma warning(push)
00048 #   pragma warning( disable : 4675 )
00049 # endif
00050 #endif
00051 
00052 #include <boost/bind.hpp>
00053 #include <boost/signal.hpp>
00054 
00055 #if LL_WINDOWS
00056 # if (_MSC_VER >= 1300 && _MSC_VER < 1400)
00057 #   pragma warning(pop)
00058 # endif
00059 #endif
00060 
00061 class LLVector3;
00062 class LLVector3d;
00063 class LLColor4;
00064 class LLColor3;
00065 class LLColor4U;
00066 
00067 const BOOL NO_PERSIST = FALSE;
00068 
00069 typedef enum e_control_type
00070 {
00071         TYPE_U32 = 0,
00072         TYPE_S32,
00073         TYPE_F32,
00074         TYPE_BOOLEAN,
00075         TYPE_STRING,
00076         TYPE_VEC3,
00077         TYPE_VEC3D,
00078         TYPE_RECT,
00079         TYPE_COL4,
00080         TYPE_COL3,
00081         TYPE_COL4U,
00082         TYPE_LLSD,
00083         TYPE_COUNT
00084 } eControlType;
00085 
00086 class LLControlVariable
00087 {
00088         friend class LLControlGroup;
00089         typedef boost::signal<void(const LLSD&)> signal_t;
00090 
00091 private:
00092         LLString                mName;
00093         LLString                mComment;
00094         eControlType    mType;
00095         BOOL                    mPersist;
00096         std::vector<LLSD> mValues;
00097         
00098         signal_t mSignal;
00099         
00100 public:
00101         LLControlVariable(const LLString& name, eControlType type,
00102                                           LLSD initial, const LLString& comment,
00103                                           BOOL persist = TRUE);
00104 
00105         virtual ~LLControlVariable();
00106         
00107         const LLString& getName() const { return mName; }
00108         const LLString& getComment() const { return mComment; }
00109 
00110         eControlType type()             { return mType; }
00111         BOOL isType(eControlType tp) { return tp == mType; }
00112 
00113         void resetToDefault(bool fire_signal = TRUE);
00114 
00115         signal_t* getSignal() { return &mSignal; }
00116 
00117         bool isDefault() { return (mValues.size() == 1); }
00118         bool isSaveValueDefault();
00119         bool isPersisted() { return mPersist; }
00120         void set(const LLSD& val)       { setValue(val); }
00121         LLSD get()                      const   { return getValue(); }
00122         LLSD getDefault()       const   { return mValues.front(); }
00123         LLSD getValue()         const   { return mValues.back(); }
00124         LLSD getSaveValue() const;
00125         void setValue(const LLSD& value, bool saved_value = TRUE);
00126         void firePropertyChanged()
00127         {
00128                 mSignal(mValues.back());
00129         }
00130         BOOL llsd_compare(const LLSD& a, const LLSD& b);
00131 };
00132 
00133 //const U32 STRING_CACHE_SIZE = 10000;
00134 class LLControlGroup
00135 {
00136 protected:
00137         typedef std::map<LLString, LLControlVariable* > ctrl_name_table_t;
00138         ctrl_name_table_t mNameTable;
00139         std::set<LLString> mWarnings;
00140         LLString mTypeString[TYPE_COUNT];
00141 
00142         eControlType typeStringToEnum(const LLString& typestr);
00143         LLString typeEnumToString(eControlType typeenum);       
00144 public:
00145         LLControlGroup();
00146         ~LLControlGroup();
00147         void cleanup();
00148         
00149         LLControlVariable*      getControl(const LLString& name);
00150 
00151         struct ApplyFunctor
00152         {
00153                 virtual ~ApplyFunctor() {};
00154                 virtual void apply(const LLString& name, LLControlVariable* control) = 0;
00155         };
00156         void applyToAll(ApplyFunctor* func);
00157         
00158         BOOL declareControl(const LLString& name, eControlType type, const LLSD initial_val, const LLString& comment, BOOL persist);
00159         BOOL declareU32(const LLString& name, U32 initial_val, const LLString& comment, BOOL persist = TRUE);
00160         BOOL declareS32(const LLString& name, S32 initial_val, const LLString& comment, BOOL persist = TRUE);
00161         BOOL declareF32(const LLString& name, F32 initial_val, const LLString& comment, BOOL persist = TRUE);
00162         BOOL declareBOOL(const LLString& name, BOOL initial_val, const LLString& comment, BOOL persist = TRUE);
00163         BOOL declareString(const LLString& name, const LLString &initial_val, const LLString& comment, BOOL persist = TRUE);
00164         BOOL declareVec3(const LLString& name, const LLVector3 &initial_val,const LLString& comment,  BOOL persist = TRUE);
00165         BOOL declareVec3d(const LLString& name, const LLVector3d &initial_val, const LLString& comment, BOOL persist = TRUE);
00166         BOOL declareRect(const LLString& name, const LLRect &initial_val, const LLString& comment, BOOL persist = TRUE);
00167         BOOL declareColor4U(const LLString& name, const LLColor4U &initial_val, const LLString& comment, BOOL persist = TRUE);
00168         BOOL declareColor4(const LLString& name, const LLColor4 &initial_val, const LLString& comment, BOOL persist = TRUE);
00169         BOOL declareColor3(const LLString& name, const LLColor3 &initial_val, const LLString& comment, BOOL persist = TRUE);
00170         BOOL declareLLSD(const LLString& name, const LLSD &initial_val, const LLString& comment, BOOL persist = TRUE);
00171         
00172         LLString        findString(const LLString& name);
00173 
00174         LLString        getString(const LLString& name);
00175         LLWString       getWString(const LLString& name);
00176         LLString        getText(const LLString& name);
00177         LLVector3       getVector3(const LLString& name);
00178         LLVector3d      getVector3d(const LLString& name);
00179         LLRect          getRect(const LLString& name);
00180         BOOL            getBOOL(const LLString& name);
00181         S32                     getS32(const LLString& name);
00182         F32                     getF32(const LLString& name);
00183         U32                     getU32(const LLString& name);
00184         LLSD        getLLSD(const LLString& name);
00185 
00186 
00187         // Note: If an LLColor4U control exists, it will cast it to the correct
00188         // LLColor4 for you.
00189         LLColor4        getColor(const LLString& name);
00190         LLColor4U       getColor4U(const LLString& name);
00191         LLColor4        getColor4(const LLString& name);
00192         LLColor3        getColor3(const LLString& name);
00193 
00194         void    setBOOL(const LLString& name, BOOL val);
00195         void    setS32(const LLString& name, S32 val);
00196         void    setF32(const LLString& name, F32 val);
00197         void    setU32(const LLString& name, U32 val);
00198         void    setString(const LLString&  name, const LLString& val);
00199         void    setVector3(const LLString& name, const LLVector3 &val);
00200         void    setVector3d(const LLString& name, const LLVector3d &val);
00201         void    setRect(const LLString& name, const LLRect &val);
00202         void    setColor4U(const LLString& name, const LLColor4U &val);
00203         void    setColor4(const LLString& name, const LLColor4 &val);
00204         void    setColor3(const LLString& name, const LLColor3 &val);
00205         void    setLLSD(const LLString& name, const LLSD& val);
00206         void    setValue(const LLString& name, const LLSD& val);
00207         
00208         
00209         BOOL    controlExists(const LLString& name);
00210 
00211         // Returns number of controls loaded, 0 if failed
00212         // If require_declaration is false, will auto-declare controls it finds
00213         // as the given type.
00214         U32     loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING);
00215         U32 saveToFile(const LLString& filename, BOOL nondefault_only);
00216         U32     loadFromFile(const LLString& filename);
00217         void    resetToDefaults();
00218 
00219         
00220         // Ignorable Warnings
00221         
00222         // Add a config variable to be reset on resetWarnings()
00223         void addWarning(const LLString& name);
00224         BOOL getWarning(const LLString& name);
00225         void setWarning(const LLString& name, BOOL val);
00226         
00227         // Resets all ignorables
00228         void resetWarnings();
00229 };
00230 
00231 #endif

Generated on Fri May 16 08:33:05 2008 for SecondLife by  doxygen 1.5.5