00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _UT_OPTIONS_H_
00025 #define _UT_OPTIONS_H_
00026
00027 #include "UT_API.h"
00028 #include <iostream.h>
00029 #include "UT_SmallObject.h"
00030 #include "UT_PtrArraySorted.h"
00031 #include "UT_SymbolTable.h"
00032 #include "UT_DeepString.h"
00033
00034 class UT_WorkBuffer;
00035 class UT_String;
00036 class UT_Vector2;
00037 class UT_Vector3;
00038 class UT_Vector4;
00039 class UT_Quaternion;
00040 class UT_Matrix3;
00041 class UT_Matrix4;
00042 class UT_OptionEntry;
00043 class UT_IntArray;
00044 class UT_FloatArray;
00045
00046
00047
00048
00049 typedef enum {
00050 UT_OPTION_INVALID = -1,
00051 UT_OPTION_INT = 0,
00052 UT_OPTION_BOOL = 1,
00053 UT_OPTION_FPREAL = 2,
00054 UT_OPTION_STRING = 3,
00055 UT_OPTION_VECTOR2 = 4,
00056 UT_OPTION_VECTOR3 = 5,
00057 UT_OPTION_VECTOR4 = 6,
00058 UT_OPTION_QUATERNION = 7,
00059 UT_OPTION_MATRIX3 = 8,
00060 UT_OPTION_MATRIX4 = 9,
00061 UT_OPTION_UV = 10,
00062 UT_OPTION_UVW = 11,
00063 UT_OPTION_STRINGRAW = 12,
00064 UT_OPTION_NUM_TYPES = 13
00065 } UT_OptionType;
00066
00067 class UT_API UT_Options
00068 {
00069 public:
00070 UT_Options();
00071 UT_Options(const UT_Options &src);
00072 virtual ~UT_Options();
00073
00074
00075 void clear();
00076
00077
00078
00079 bool load(const char *filename);
00080 bool save(const char *filename) const;
00081 bool load(const char *filename, UT_IStream &is);
00082 bool save(const char *filename, ostream &os) const;
00083
00084
00085 void removeOption(const char *name);
00086
00087 void getOptionString(const char *name,
00088 UT_String &result) const;
00089
00090 static void getOptionString(const UT_OptionEntry *option,
00091 UT_String &result);
00092
00093
00094
00095 bool appendPyDictionary(UT_WorkBuffer &result) const;
00096
00097 bool getPyOptionString(const char *name,
00098 UT_String &result) const;
00099
00100 static bool getPyOptionString(const UT_OptionEntry *option,
00101 UT_String &result);
00102
00103
00104 bool hasOption(const char *name) const;
00105 UT_OptionType getOptionType(const char *name) const;
00106 const UT_OptionEntry*getOptionEntry(const char *name) const;
00107
00108
00109 int getNumOptions() const;
00110 const char *getOptionName(int optionnum) const;
00111 UT_OptionType getOptionType(int optionnum) const;
00112 const UT_OptionEntry*getOptionEntry(int optionnum) const;
00113
00114
00115 int getOptionI(const char *name) const;
00116 bool getOptionB(const char *name) const;
00117 float getOptionF(const char *name) const;
00118 void getOptionS(const char *name, UT_String &value) const;
00119 const UT_Vector2 getOptionV2(const char *name) const;
00120 const UT_Vector3 getOptionV3(const char *name) const;
00121 const UT_Vector4 getOptionV4(const char *name) const;
00122 const UT_Quaternion getOptionQ(const char *name) const;
00123 const UT_Matrix3 getOptionM3(const char *name) const;
00124 const UT_Matrix4 getOptionM4(const char *name) const;
00125 const UT_Vector2 getOptionUV(const char *name) const;
00126 const UT_Vector3 getOptionUVW(const char *name) const;
00127
00128
00129
00130
00131
00132
00133
00134
00135 bool importOption(const char *name, int &value) const;
00136 bool importOption(const char *name, bool &value) const;
00137 bool importOption(const char *name, fpreal32 &value) const;
00138 bool importOption(const char *name, fpreal64 &value) const;
00139 bool importOption(const char *name, UT_String &value) const;
00140 bool importOption(const char *name, UT_Vector2 &value) const;
00141 bool importOption(const char *name, UT_Vector3 &value) const;
00142 bool importOption(const char *name, UT_Vector4 &value) const;
00143 bool importOption(const char *name, UT_Quaternion &value) const;
00144 bool importOption(const char *name, UT_Matrix3 &value) const;
00145 bool importOption(const char *name, UT_Matrix4 &value) const;
00146
00147
00148 bool importOption(const char *name, UT_IntArray &value) const;
00149 bool importOption(const char *name, UT_FloatArray &value) const;
00150
00151
00152 void setOptionI(const char *name, int value);
00153 void setOptionB(const char *name, bool value);
00154 void setOptionF(const char *name, float value);
00155 void setOptionS(const char *name, const char *value);
00156
00157
00158
00159
00160 void setOptionSRaw(const char *name, const char *value);
00161 void setOptionV2(const char *name,
00162 const UT_Vector2 &value);
00163 void setOptionV2(const char *name,
00164 fpreal x, fpreal y);
00165 void setOptionV3(const char *name,
00166 const UT_Vector3 &value);
00167 void setOptionV3(const char *name,
00168 fpreal x, fpreal y, fpreal z);
00169 void setOptionV4(const char *name,
00170 const UT_Vector4 &value);
00171 void setOptionV4(const char *name,
00172 fpreal x, fpreal y, fpreal z, fpreal w);
00173 void setOptionQ(const char *name,
00174 const UT_Quaternion &value);
00175 void setOptionM3(const char *name,
00176 const UT_Matrix3 &value);
00177 void setOptionM4(const char *name,
00178 const UT_Matrix4 &value);
00179 void setOptionUV(const char *name,
00180 const UT_Vector2 &value);
00181 void setOptionUVW(const char *name,
00182 const UT_Vector3 &value);
00183
00184 const UT_Options &operator=(const UT_Options &src);
00185 void merge(const UT_Options &src);
00186 int64 getMemoryUsage() const;
00187
00188 static UT_OptionType getOptionTypeFromString(const char *optiontypestr);
00189 static const char *getStringFromOptionType(UT_OptionType optiontype);
00190
00191 protected:
00192 void addError(const char *filename, int linecount,
00193 const char *error_str) const;
00194 void setOption(const char *name, UT_OptionEntry *value);
00195 virtual void optionChanged(const char *name);
00196
00197 static int compareStrings(const char * const *str1,
00198 const char * const *str2);
00199 static const char *getStringReference(const char *symbol);
00200
00201
00202 UT_PtrArraySorted<const char *> myOptionNames;
00203 UT_PtrArray<UT_OptionEntry *> myOptionValues;
00204 bool mySendOptionChanges;
00205 };
00206
00207
00208 class UT_API UT_OptionEntry : public UT_SmallObject<UT_OptionEntry,
00209 UT_SMALLOBJECT_CLEANPAGES_DEFAULT,
00210 UT_SMALLOBJECT_PAGESIZE_DEFAULT,
00211 UT_SMALLOBJECT_THREADSAFE_ON>
00212 {
00213 public:
00214 UT_OptionEntry()
00215 { }
00216 virtual ~UT_OptionEntry()
00217 { }
00218
00219 virtual UT_OptionType getType() const = 0;
00220 virtual UT_OptionEntry *clone() const = 0;
00221 };
00222
00223
00224 template<class T, UT_OptionType ID, class outT = T>
00225 class UT_API UT_OptionEntryImpl : public UT_OptionEntry
00226 {
00227 public:
00228 UT_OptionEntryImpl(const T &value)
00229 : myValue(value)
00230 { }
00231 virtual ~UT_OptionEntryImpl()
00232 { }
00233
00234 const outT &getValue() const
00235 { return myValue; }
00236 virtual UT_OptionType getType() const
00237 { return ID; }
00238 virtual UT_OptionEntry *clone() const
00239 { return new UT_OptionEntryImpl(myValue); }
00240
00241 private:
00242 T myValue;
00243 };
00244
00245 typedef UT_OptionEntryImpl<int, UT_OPTION_INT> UT_OptionInt;
00246 typedef UT_OptionEntryImpl<bool, UT_OPTION_BOOL> UT_OptionBool;
00247 typedef UT_OptionEntryImpl<float, UT_OPTION_FPREAL> UT_OptionFpreal;
00248 typedef UT_OptionEntryImpl<UT_DeepString, UT_OPTION_STRING, UT_String> UT_OptionString;
00249 typedef UT_OptionEntryImpl<UT_Vector2, UT_OPTION_VECTOR2> UT_OptionVector2;
00250 typedef UT_OptionEntryImpl<UT_Vector3, UT_OPTION_VECTOR3> UT_OptionVector3;
00251 typedef UT_OptionEntryImpl<UT_Vector4, UT_OPTION_VECTOR4> UT_OptionVector4;
00252 typedef UT_OptionEntryImpl<UT_Quaternion, UT_OPTION_QUATERNION> UT_OptionQuaternion;
00253 typedef UT_OptionEntryImpl<UT_Matrix3, UT_OPTION_MATRIX3> UT_OptionMatrix3;
00254 typedef UT_OptionEntryImpl<UT_Matrix4, UT_OPTION_MATRIX4> UT_OptionMatrix4;
00255 typedef UT_OptionEntryImpl<UT_Vector2, UT_OPTION_UV> UT_OptionUV;
00256 typedef UT_OptionEntryImpl<UT_Vector3, UT_OPTION_UVW> UT_OptionUVW;
00257
00258 #endif
00259