llnamevalue.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLNAMEVALUE_H
00033 #define LL_LLNAMEVALUE_H
00034 
00035 #include "string_table.h"
00036 #include "llskipmap.h"
00037 #include "llmath.h"
00038 #include "v3math.h"
00039 #include "lldbstrings.h"
00040 
00041 class LLNameValue;
00042 typedef void (*TNameValueCallback)(LLNameValue *changed, void **user_data);
00043 
00044 void add_use_callback(char *name, TNameValueCallback ucb, void **user_data);
00045 
00046 typedef enum e_name_value_types
00047 {
00048         NVT_NULL,
00049         NVT_STRING,
00050         NVT_F32,
00051         NVT_S32,
00052         NVT_VEC3,
00053         NVT_U32,
00054         NVT_CAMERA, // Deprecated, but leaving in case removing this will cause problems
00055         NVT_ASSET,
00056         NVT_U64,
00057         NVT_EOF
00058 } ENameValueType;
00059 
00060 typedef enum e_name_value_class
00061 {
00062         NVC_NULL,
00063         NVC_READ_ONLY,
00064         NVC_READ_WRITE,
00065         NVC_CALLBACK,
00066         NVC_EOF
00067 } ENameValueClass;
00068 
00069 typedef enum e_name_value_sento
00070 {
00071         NVS_NULL,
00072         NVS_SIM,
00073         NVS_DATA_SIM,
00074         NVS_SIM_VIEWER,
00075         NVS_DATA_SIM_VIEWER,
00076         NVS_EOF
00077 } ENameValueSendto;
00078 
00079 
00080 // NameValues can always be "printed" into a buffer of this length.
00081 const U32 NAME_VALUE_BUF_SIZE = 1024;
00082 
00083 
00084 const U32 NAME_VALUE_TYPE_STRING_LENGTH = 8;
00085 const U32 NAME_VALUE_CLASS_STRING_LENGTH = 16;
00086 const U32 NAME_VALUE_SENDTO_STRING_LENGTH = 18;
00087 const U32 NAME_VALUE_DATA_SIZE = 
00088                         NAME_VALUE_BUF_SIZE - 
00089                         ( DB_NV_NAME_BUF_SIZE +
00090                         NAME_VALUE_TYPE_STRING_LENGTH +
00091                         NAME_VALUE_CLASS_STRING_LENGTH + 
00092                         NAME_VALUE_SENDTO_STRING_LENGTH );
00093 
00094 
00095 extern char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH];                       /* Flawfinder: Ignore */
00096 extern char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH];             /* Flawfinder: Ignore */
00097 extern char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH];           /* Flawfinder: Ignore */
00098 
00099 typedef union u_name_value_reference
00100 {
00101         char            *string;
00102         F32                     *f32;
00103         S32                     *s32;
00104         LLVector3       *vec3;
00105         U32                     *u32;
00106         U64                     *u64;
00107 } UNameValueReference;
00108 
00109 
00110 class LLNameValue
00111 {
00112 public:
00113         void baseInit();
00114         void init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto, 
00115                                 TNameValueCallback nvcb = NULL, void **user_data = NULL);
00116 
00117         LLNameValue();
00118         LLNameValue(const char *data);
00119         LLNameValue(const char *name, const char *type, const char *nvclass, 
00120                                 TNameValueCallback nvcb = NULL, void **user_data = NULL);
00121         LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, 
00122                                 TNameValueCallback nvcb = NULL, void **user_data = NULL);
00123         LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto, 
00124                                 TNameValueCallback nvcb = NULL, void **user_data = NULL);
00125 
00126         ~LLNameValue();
00127 
00128         char                    *getString();
00129         const char              *getAsset() const;
00130         F32                             *getF32();
00131         S32                             *getS32();
00132         void                    getVec3(LLVector3 &vec);
00133         LLVector3               *getVec3();
00134         F32                             magnitude();
00135         U32                             *getU32();
00136         U64                             *getU64();
00137 
00138         const char              *getType() const                { return mStringType; }
00139         const char              *getClass() const               { return mStringClass; }
00140         const char              *getSendto() const              { return mStringSendto; }
00141 
00142         BOOL                    sendToData() const;
00143         BOOL                    sendToViewer() const;
00144 
00145         void                    callCallback();
00146         std::string             printNameValue();
00147         std::string             printData();
00148         
00149         ENameValueType          getTypeEnum() const             { return mType; }
00150         ENameValueClass         getClassEnum() const    { return mClass; }
00151         ENameValueSendto        getSendtoEnum() const   { return mSendto; }
00152 
00153         LLNameValue             &operator=(const LLNameValue &a);
00154         void                    setString(const char *a);
00155         void                    setAsset(const char *a);
00156         void                    setF32(const F32 a);
00157         void                    setS32(const S32 a);
00158         void                    setVec3(const LLVector3 &a);
00159         void                    setU32(const U32 a);
00160 
00161         BOOL                    nonzero();
00162 
00163         friend std::ostream&            operator<<(std::ostream& s, const LLNameValue &a);
00164 
00165         friend LLNameValue      &operator+(const LLNameValue &a, const LLNameValue &b);
00166         friend LLNameValue      &operator-(const LLNameValue &a, const LLNameValue &b);
00167         friend LLNameValue      &operator*(const LLNameValue &a, const LLNameValue &b);
00168         friend LLNameValue      &operator/(const LLNameValue &a, const LLNameValue &b);
00169         friend LLNameValue      &operator%(const LLNameValue &a, const LLNameValue &b);
00170         friend LLNameValue      &operator*(const LLNameValue &a, F32 k);
00171         friend LLNameValue      &operator*(F32 k, const LLNameValue &a);
00172 
00173         friend bool                     operator==(const LLNameValue &a, const LLNameValue &b); 
00174         friend bool                     operator<=(const LLNameValue &a, const LLNameValue &b); 
00175         friend bool                     operator>=(const LLNameValue &a, const LLNameValue &b); 
00176         friend bool                     operator<(const LLNameValue &a, const LLNameValue &b);  
00177         friend bool                     operator>(const LLNameValue &a, const LLNameValue &b);  
00178         friend bool                     operator!=(const LLNameValue &a, const LLNameValue &b); 
00179 
00180         friend LLNameValue      &operator-(const LLNameValue &a);       
00181 
00182 private:
00183         void                    printNameValue(std::ostream& s);
00184         
00185 public:
00186         char                                            *mName;
00187 
00188         char                                            *mStringType;
00189         ENameValueType                          mType;
00190         char                                            *mStringClass;
00191         ENameValueClass                         mClass;
00192         char                                            *mStringSendto;
00193         ENameValueSendto                        mSendto;
00194 
00195         UNameValueReference                     mNameValueReference;
00196         LLStringTable                           *mNVNameTable;
00197         TNameValueCallback                      mNameValueCB;
00198         void                                            **mUserData;
00199 };
00200 
00201 extern LLStringTable    gNVNameTable;
00202 
00203 
00204 #endif

Generated on Thu Jul 1 06:08:54 2010 for Second Life Viewer by  doxygen 1.4.7