diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/llmessage/llnamevalue.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to 'linden/indra/llmessage/llnamevalue.cpp')
-rw-r--r-- | linden/indra/llmessage/llnamevalue.cpp | 1216 |
1 files changed, 12 insertions, 1204 deletions
diff --git a/linden/indra/llmessage/llnamevalue.cpp b/linden/indra/llmessage/llnamevalue.cpp index 6c8a2c4..18bd5ac 100644 --- a/linden/indra/llmessage/llnamevalue.cpp +++ b/linden/indra/llmessage/llnamevalue.cpp | |||
@@ -34,12 +34,12 @@ | |||
34 | 34 | ||
35 | #include "linden_common.h" | 35 | #include "linden_common.h" |
36 | 36 | ||
37 | #include <map> | ||
38 | |||
39 | #include "llnamevalue.h" | 37 | #include "llnamevalue.h" |
38 | |||
40 | #include "u64.h" | 39 | #include "u64.h" |
41 | #include "llstring.h" | 40 | #include "llstring.h" |
42 | #include "llcamera.h" | 41 | #include "llcamera.h" |
42 | #include "string_table.h" | ||
43 | 43 | ||
44 | // Anonymous enumeration to provide constants in this file. | 44 | // Anonymous enumeration to provide constants in this file. |
45 | // *NOTE: These values may be used in sscanf statements below as their | 45 | // *NOTE: These values may be used in sscanf statements below as their |
@@ -51,17 +51,7 @@ enum | |||
51 | U64_BUFFER_LEN = 64 | 51 | U64_BUFFER_LEN = 64 |
52 | }; | 52 | }; |
53 | 53 | ||
54 | struct user_callback_t | 54 | LLStringTable gNVNameTable(256); |
55 | { | ||
56 | user_callback_t() {}; | ||
57 | user_callback_t(TNameValueCallback cb, void** data) : m_Callback(cb), m_Data(data) {} | ||
58 | TNameValueCallback m_Callback; | ||
59 | void ** m_Data; | ||
60 | }; | ||
61 | typedef std::map<char *, user_callback_t> user_callback_map_t; | ||
62 | user_callback_map_t gUserCallbackMap; | ||
63 | |||
64 | LLStringTable gNVNameTable(16384); | ||
65 | 55 | ||
66 | char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH] = /*Flawfinder: Ignore*/ | 56 | char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH] = /*Flawfinder: Ignore*/ |
67 | { | 57 | { |
@@ -80,8 +70,7 @@ char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH] = /*Flawfind | |||
80 | { | 70 | { |
81 | "NULL", | 71 | "NULL", |
82 | "R", // read only | 72 | "R", // read only |
83 | "RW", // read write | 73 | "RW" // read write |
84 | "CB" // callback | ||
85 | }; | 74 | }; |
86 | 75 | ||
87 | char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH] = /*Flawfinder: Ignore*/ | 76 | char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH] = /*Flawfinder: Ignore*/ |
@@ -94,13 +83,6 @@ char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH] = /*Flawfi | |||
94 | }; /*Flawfinder: Ignore*/ | 83 | }; /*Flawfinder: Ignore*/ |
95 | 84 | ||
96 | 85 | ||
97 | void add_use_callback(char *name, TNameValueCallback ucb, void **user_data) | ||
98 | { | ||
99 | char *temp = gNVNameTable.addString(name); | ||
100 | gUserCallbackMap[temp] = user_callback_t(ucb,user_data); | ||
101 | } | ||
102 | |||
103 | |||
104 | // | 86 | // |
105 | // Class | 87 | // Class |
106 | // | 88 | // |
@@ -125,12 +107,9 @@ void LLNameValue::baseInit() | |||
125 | 107 | ||
126 | mSendto = NVS_NULL; | 108 | mSendto = NVS_NULL; |
127 | mStringSendto = NameValueSendtoStrings[NVS_NULL]; | 109 | mStringSendto = NameValueSendtoStrings[NVS_NULL]; |
128 | |||
129 | mNameValueCB = NULL; | ||
130 | mUserData = NULL; | ||
131 | } | 110 | } |
132 | 111 | ||
133 | void LLNameValue::init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto, TNameValueCallback nvcb, void **user_data) | 112 | void LLNameValue::init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto) |
134 | { | 113 | { |
135 | mNVNameTable = &gNVNameTable; | 114 | mNVNameTable = &gNVNameTable; |
136 | 115 | ||
@@ -254,40 +233,11 @@ void LLNameValue::init(const char *name, const char *data, const char *type, con | |||
254 | mClass = NVC_READ_WRITE; | 233 | mClass = NVC_READ_WRITE; |
255 | mStringClass = mNVNameTable->addString("RW"); | 234 | mStringClass = mNVNameTable->addString("RW"); |
256 | } | 235 | } |
257 | else if (!strcmp(nvclass, "CB") || | ||
258 | !strcmp(nvclass, "CALLBACK")) // legacy | ||
259 | { | ||
260 | mClass = NVC_CALLBACK; | ||
261 | mStringClass = mNVNameTable->addString("CB"); | ||
262 | mNameValueCB = nvcb; | ||
263 | mUserData = user_data; | ||
264 | } | ||
265 | else | 236 | else |
266 | { | 237 | { |
267 | // assume it's bad | 238 | // assume it's bad |
268 | mClass = NVC_NULL; | 239 | mClass = NVC_NULL; |
269 | mStringClass = mNVNameTable->addString(nvclass); | 240 | mStringClass = mNVNameTable->addString(nvclass); |
270 | mNameValueCB = NULL; | ||
271 | mUserData = NULL; | ||
272 | |||
273 | // are we a user-defined call back? | ||
274 | for (user_callback_map_t::iterator iter = gUserCallbackMap.begin(); | ||
275 | iter != gUserCallbackMap.end(); iter++) | ||
276 | { | ||
277 | char* tname = iter->first; | ||
278 | if (tname == mStringClass) | ||
279 | { | ||
280 | mClass = NVC_CALLBACK; | ||
281 | mNameValueCB = (iter->second).m_Callback; | ||
282 | mUserData = (iter->second).m_Data; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | // Warn if we didn't find a callback | ||
287 | if (mClass == NVC_NULL) | ||
288 | { | ||
289 | llwarns << "Unknown user callback in name value init() for " << mName << llendl; | ||
290 | } | ||
291 | } | 241 | } |
292 | 242 | ||
293 | // Initialize the sendto variable | 243 | // Initialize the sendto variable |
@@ -326,24 +276,24 @@ void LLNameValue::init(const char *name, const char *data, const char *type, con | |||
326 | } | 276 | } |
327 | 277 | ||
328 | 278 | ||
329 | LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, TNameValueCallback nvcb, void **user_data) | 279 | LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass) |
330 | { | 280 | { |
331 | baseInit(); | 281 | baseInit(); |
332 | // if not specified, send to simulator only | 282 | // if not specified, send to simulator only |
333 | init(name, data, type, nvclass, "SIM", nvcb, user_data); | 283 | init(name, data, type, nvclass, "SIM"); |
334 | } | 284 | } |
335 | 285 | ||
336 | 286 | ||
337 | LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto, TNameValueCallback nvcb, void **user_data) | 287 | LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto) |
338 | { | 288 | { |
339 | baseInit(); | 289 | baseInit(); |
340 | init(name, data, type, nvclass, nvsendto, nvcb, user_data); | 290 | init(name, data, type, nvclass, nvsendto); |
341 | } | 291 | } |
342 | 292 | ||
343 | 293 | ||
344 | 294 | ||
345 | // Initialize without any initial data. | 295 | // Initialize without any initial data. |
346 | LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass, TNameValueCallback nvcb, void **user_data) | 296 | LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass) |
347 | { | 297 | { |
348 | baseInit(); | 298 | baseInit(); |
349 | mName = mNVNameTable->addString(name); | 299 | mName = mNVNameTable->addString(name); |
@@ -401,11 +351,9 @@ LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass | |||
401 | { | 351 | { |
402 | mClass = NVC_READ_WRITE; | 352 | mClass = NVC_READ_WRITE; |
403 | } | 353 | } |
404 | else if (!strcmp(mStringClass, "CALLBACK")) | 354 | else |
405 | { | 355 | { |
406 | mClass = NVC_READ_WRITE; | 356 | mClass = NVC_NULL; |
407 | mNameValueCB = nvcb; | ||
408 | mUserData = user_data; | ||
409 | } | 357 | } |
410 | 358 | ||
411 | // Initialize the sendto variable | 359 | // Initialize the sendto variable |
@@ -734,46 +682,6 @@ LLVector3 *LLNameValue::getVec3() | |||
734 | } | 682 | } |
735 | 683 | ||
736 | 684 | ||
737 | F32 LLNameValue::magnitude() | ||
738 | { | ||
739 | switch(mType) | ||
740 | { | ||
741 | case NVT_STRING: | ||
742 | return (F32)(strlen(mNameValueReference.string)); /* Flawfinder: ignore */ | ||
743 | break; | ||
744 | case NVT_F32: | ||
745 | return (fabsf(*mNameValueReference.f32)); | ||
746 | break; | ||
747 | case NVT_S32: | ||
748 | return (fabsf((F32)(*mNameValueReference.s32))); | ||
749 | break; | ||
750 | case NVT_VEC3: | ||
751 | return (mNameValueReference.vec3->magVec()); | ||
752 | break; | ||
753 | case NVT_U32: | ||
754 | return (F32)(*mNameValueReference.u32); | ||
755 | break; | ||
756 | default: | ||
757 | llerrs << "No magnitude operation for NV type " << mStringType << llendl; | ||
758 | break; | ||
759 | } | ||
760 | return 0.f; | ||
761 | } | ||
762 | |||
763 | |||
764 | void LLNameValue::callCallback() | ||
765 | { | ||
766 | if (mNameValueCB) | ||
767 | { | ||
768 | (*mNameValueCB)(this, mUserData); | ||
769 | } | ||
770 | else | ||
771 | { | ||
772 | llinfos << mName << " has no callback!" << llendl; | ||
773 | } | ||
774 | } | ||
775 | |||
776 | |||
777 | BOOL LLNameValue::sendToData() const | 685 | BOOL LLNameValue::sendToData() const |
778 | { | 686 | { |
779 | return (mSendto == NVS_DATA_SIM || mSendto == NVS_DATA_SIM_VIEWER); | 687 | return (mSendto == NVS_DATA_SIM || mSendto == NVS_DATA_SIM_VIEWER); |
@@ -795,13 +703,6 @@ LLNameValue &LLNameValue::operator=(const LLNameValue &a) | |||
795 | if (mClass == NVC_READ_ONLY) | 703 | if (mClass == NVC_READ_ONLY) |
796 | return *this; | 704 | return *this; |
797 | 705 | ||
798 | BOOL b_changed = FALSE; | ||
799 | if ( (mClass == NVC_CALLBACK) | ||
800 | &&(*this != a)) | ||
801 | { | ||
802 | b_changed = TRUE; | ||
803 | } | ||
804 | |||
805 | switch(a.mType) | 706 | switch(a.mType) |
806 | { | 707 | { |
807 | case NVT_STRING: | 708 | case NVT_STRING: |
@@ -835,11 +736,6 @@ LLNameValue &LLNameValue::operator=(const LLNameValue &a) | |||
835 | break; | 736 | break; |
836 | } | 737 | } |
837 | 738 | ||
838 | if (b_changed) | ||
839 | { | ||
840 | callCallback(); | ||
841 | } | ||
842 | |||
843 | return *this; | 739 | return *this; |
844 | } | 740 | } |
845 | 741 | ||
@@ -847,19 +743,12 @@ void LLNameValue::setString(const char *a) | |||
847 | { | 743 | { |
848 | if (mClass == NVC_READ_ONLY) | 744 | if (mClass == NVC_READ_ONLY) |
849 | return; | 745 | return; |
850 | BOOL b_changed = FALSE; | ||
851 | 746 | ||
852 | switch(mType) | 747 | switch(mType) |
853 | { | 748 | { |
854 | case NVT_STRING: | 749 | case NVT_STRING: |
855 | if (a) | 750 | if (a) |
856 | { | 751 | { |
857 | if ( (mClass == NVC_CALLBACK) | ||
858 | &&(strcmp(this->mNameValueReference.string,a))) | ||
859 | { | ||
860 | b_changed = TRUE; | ||
861 | } | ||
862 | |||
863 | if (mNameValueReference.string) | 752 | if (mNameValueReference.string) |
864 | { | 753 | { |
865 | delete [] mNameValueReference.string; | 754 | delete [] mNameValueReference.string; |
@@ -870,11 +759,6 @@ void LLNameValue::setString(const char *a) | |||
870 | { | 759 | { |
871 | strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */ | 760 | strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */ |
872 | } | 761 | } |
873 | |||
874 | if (b_changed) | ||
875 | { | ||
876 | callCallback(); | ||
877 | } | ||
878 | } | 762 | } |
879 | else | 763 | else |
880 | { | 764 | { |
@@ -889,11 +773,6 @@ void LLNameValue::setString(const char *a) | |||
889 | break; | 773 | break; |
890 | } | 774 | } |
891 | 775 | ||
892 | if (b_changed) | ||
893 | { | ||
894 | callCallback(); | ||
895 | } | ||
896 | |||
897 | return; | 776 | return; |
898 | } | 777 | } |
899 | 778 | ||
@@ -902,19 +781,12 @@ void LLNameValue::setAsset(const char *a) | |||
902 | { | 781 | { |
903 | if (mClass == NVC_READ_ONLY) | 782 | if (mClass == NVC_READ_ONLY) |
904 | return; | 783 | return; |
905 | BOOL b_changed = FALSE; | ||
906 | 784 | ||
907 | switch(mType) | 785 | switch(mType) |
908 | { | 786 | { |
909 | case NVT_ASSET: | 787 | case NVT_ASSET: |
910 | if (a) | 788 | if (a) |
911 | { | 789 | { |
912 | if ( (mClass == NVC_CALLBACK) | ||
913 | &&(strcmp(this->mNameValueReference.string,a))) | ||
914 | { | ||
915 | b_changed = TRUE; | ||
916 | } | ||
917 | |||
918 | if (mNameValueReference.string) | 790 | if (mNameValueReference.string) |
919 | { | 791 | { |
920 | delete [] mNameValueReference.string; | 792 | delete [] mNameValueReference.string; |
@@ -924,11 +796,6 @@ void LLNameValue::setAsset(const char *a) | |||
924 | { | 796 | { |
925 | strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */ | 797 | strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */ |
926 | } | 798 | } |
927 | |||
928 | if (b_changed) | ||
929 | { | ||
930 | callCallback(); | ||
931 | } | ||
932 | } | 799 | } |
933 | else | 800 | else |
934 | { | 801 | { |
@@ -942,10 +809,6 @@ void LLNameValue::setAsset(const char *a) | |||
942 | default: | 809 | default: |
943 | break; | 810 | break; |
944 | } | 811 | } |
945 | if (b_changed) | ||
946 | { | ||
947 | callCallback(); | ||
948 | } | ||
949 | } | 812 | } |
950 | 813 | ||
951 | 814 | ||
@@ -953,29 +816,15 @@ void LLNameValue::setF32(const F32 a) | |||
953 | { | 816 | { |
954 | if (mClass == NVC_READ_ONLY) | 817 | if (mClass == NVC_READ_ONLY) |
955 | return; | 818 | return; |
956 | BOOL b_changed = FALSE; | ||
957 | 819 | ||
958 | switch(mType) | 820 | switch(mType) |
959 | { | 821 | { |
960 | case NVT_F32: | 822 | case NVT_F32: |
961 | if ( (mClass == NVC_CALLBACK) | ||
962 | &&(*this->mNameValueReference.f32 != a)) | ||
963 | { | ||
964 | b_changed = TRUE; | ||
965 | } | ||
966 | *mNameValueReference.f32 = a; | 823 | *mNameValueReference.f32 = a; |
967 | if (b_changed) | ||
968 | { | ||
969 | callCallback(); | ||
970 | } | ||
971 | break; | 824 | break; |
972 | default: | 825 | default: |
973 | break; | 826 | break; |
974 | } | 827 | } |
975 | if (b_changed) | ||
976 | { | ||
977 | callCallback(); | ||
978 | } | ||
979 | 828 | ||
980 | return; | 829 | return; |
981 | } | 830 | } |
@@ -985,53 +834,21 @@ void LLNameValue::setS32(const S32 a) | |||
985 | { | 834 | { |
986 | if (mClass == NVC_READ_ONLY) | 835 | if (mClass == NVC_READ_ONLY) |
987 | return; | 836 | return; |
988 | BOOL b_changed = FALSE; | ||
989 | 837 | ||
990 | switch(mType) | 838 | switch(mType) |
991 | { | 839 | { |
992 | case NVT_S32: | 840 | case NVT_S32: |
993 | if ( (mClass == NVC_CALLBACK) | ||
994 | &&(*this->mNameValueReference.s32 != a)) | ||
995 | { | ||
996 | b_changed = TRUE; | ||
997 | } | ||
998 | *mNameValueReference.s32 = a; | 841 | *mNameValueReference.s32 = a; |
999 | if (b_changed) | ||
1000 | { | ||
1001 | callCallback(); | ||
1002 | } | ||
1003 | break; | 842 | break; |
1004 | case NVT_U32: | 843 | case NVT_U32: |
1005 | if ( (mClass == NVC_CALLBACK) | ||
1006 | && ((S32) (*this->mNameValueReference.u32) != a)) | ||
1007 | { | ||
1008 | b_changed = TRUE; | ||
1009 | } | ||
1010 | *mNameValueReference.u32 = a; | 844 | *mNameValueReference.u32 = a; |
1011 | if (b_changed) | ||
1012 | { | ||
1013 | callCallback(); | ||
1014 | } | ||
1015 | break; | 845 | break; |
1016 | case NVT_F32: | 846 | case NVT_F32: |
1017 | if ( (mClass == NVC_CALLBACK) | ||
1018 | &&(*this->mNameValueReference.f32 != a)) | ||
1019 | { | ||
1020 | b_changed = TRUE; | ||
1021 | } | ||
1022 | *mNameValueReference.f32 = (F32)a; | 847 | *mNameValueReference.f32 = (F32)a; |
1023 | if (b_changed) | ||
1024 | { | ||
1025 | callCallback(); | ||
1026 | } | ||
1027 | break; | 848 | break; |
1028 | default: | 849 | default: |
1029 | break; | 850 | break; |
1030 | } | 851 | } |
1031 | if (b_changed) | ||
1032 | { | ||
1033 | callCallback(); | ||
1034 | } | ||
1035 | 852 | ||
1036 | return; | 853 | return; |
1037 | } | 854 | } |
@@ -1041,45 +858,17 @@ void LLNameValue::setU32(const U32 a) | |||
1041 | { | 858 | { |
1042 | if (mClass == NVC_READ_ONLY) | 859 | if (mClass == NVC_READ_ONLY) |
1043 | return; | 860 | return; |
1044 | BOOL b_changed = FALSE; | ||
1045 | 861 | ||
1046 | switch(mType) | 862 | switch(mType) |
1047 | { | 863 | { |
1048 | case NVT_S32: | 864 | case NVT_S32: |
1049 | if ( (mClass == NVC_CALLBACK) | ||
1050 | &&(*this->mNameValueReference.s32 != (S32) a)) | ||
1051 | { | ||
1052 | b_changed = TRUE; | ||
1053 | } | ||
1054 | *mNameValueReference.s32 = a; | 865 | *mNameValueReference.s32 = a; |
1055 | if (b_changed) | ||
1056 | { | ||
1057 | callCallback(); | ||
1058 | } | ||
1059 | break; | 866 | break; |
1060 | case NVT_U32: | 867 | case NVT_U32: |
1061 | if ( (mClass == NVC_CALLBACK) | ||
1062 | &&(*this->mNameValueReference.u32 != a)) | ||
1063 | { | ||
1064 | b_changed = TRUE; | ||
1065 | } | ||
1066 | *mNameValueReference.u32 = a; | 868 | *mNameValueReference.u32 = a; |
1067 | if (b_changed) | ||
1068 | { | ||
1069 | callCallback(); | ||
1070 | } | ||
1071 | break; | 869 | break; |
1072 | case NVT_F32: | 870 | case NVT_F32: |
1073 | if ( (mClass == NVC_CALLBACK) | ||
1074 | &&(*this->mNameValueReference.f32 != a)) | ||
1075 | { | ||
1076 | b_changed = TRUE; | ||
1077 | } | ||
1078 | *mNameValueReference.f32 = (F32)a; | 871 | *mNameValueReference.f32 = (F32)a; |
1079 | if (b_changed) | ||
1080 | { | ||
1081 | callCallback(); | ||
1082 | } | ||
1083 | break; | 872 | break; |
1084 | default: | 873 | default: |
1085 | llerrs << "NameValue: Trying to set U32 into a " << mStringType << ", unknown conversion" << llendl; | 874 | llerrs << "NameValue: Trying to set U32 into a " << mStringType << ", unknown conversion" << llendl; |
@@ -1093,21 +882,11 @@ void LLNameValue::setVec3(const LLVector3 &a) | |||
1093 | { | 882 | { |
1094 | if (mClass == NVC_READ_ONLY) | 883 | if (mClass == NVC_READ_ONLY) |
1095 | return; | 884 | return; |
1096 | BOOL b_changed = FALSE; | ||
1097 | 885 | ||
1098 | switch(mType) | 886 | switch(mType) |
1099 | { | 887 | { |
1100 | case NVT_VEC3: | 888 | case NVT_VEC3: |
1101 | if ( (mClass == NVC_CALLBACK) | ||
1102 | &&(*this->mNameValueReference.vec3 != a)) | ||
1103 | { | ||
1104 | b_changed = TRUE; | ||
1105 | } | ||
1106 | *mNameValueReference.vec3 = a; | 889 | *mNameValueReference.vec3 = a; |
1107 | if (b_changed) | ||
1108 | { | ||
1109 | callCallback(); | ||
1110 | } | ||
1111 | break; | 890 | break; |
1112 | default: | 891 | default: |
1113 | llerrs << "NameValue: Trying to set LLVector3 into a " << mStringType << ", unknown conversion" << llendl; | 892 | llerrs << "NameValue: Trying to set LLVector3 into a " << mStringType << ", unknown conversion" << llendl; |
@@ -1117,29 +896,6 @@ void LLNameValue::setVec3(const LLVector3 &a) | |||
1117 | } | 896 | } |
1118 | 897 | ||
1119 | 898 | ||
1120 | BOOL LLNameValue::nonzero() | ||
1121 | { | ||
1122 | switch(mType) | ||
1123 | { | ||
1124 | case NVT_STRING: | ||
1125 | if (!mNameValueReference.string) | ||
1126 | return 0; | ||
1127 | return (mNameValueReference.string[0] != 0); | ||
1128 | case NVT_F32: | ||
1129 | return (*mNameValueReference.f32 != 0.f); | ||
1130 | case NVT_S32: | ||
1131 | return (*mNameValueReference.s32 != 0); | ||
1132 | case NVT_U32: | ||
1133 | return (*mNameValueReference.u32 != 0); | ||
1134 | case NVT_VEC3: | ||
1135 | return (mNameValueReference.vec3->magVecSquared() != 0.f); | ||
1136 | default: | ||
1137 | llerrs << "NameValue: Trying to call nonzero on a " << mStringType << ", unknown conversion" << llendl; | ||
1138 | break; | ||
1139 | } | ||
1140 | return FALSE; | ||
1141 | } | ||
1142 | |||
1143 | std::string LLNameValue::printNameValue() | 899 | std::string LLNameValue::printNameValue() |
1144 | { | 900 | { |
1145 | std::string buffer; | 901 | std::string buffer; |
@@ -1217,951 +973,3 @@ std::ostream& operator<<(std::ostream& s, const LLNameValue &a) | |||
1217 | return s; | 973 | return s; |
1218 | } | 974 | } |
1219 | 975 | ||
1220 | |||
1221 | // nota bene: return values aren't static for now to prevent memory leaks | ||
1222 | |||
1223 | LLNameValue &operator+(const LLNameValue &a, const LLNameValue &b) | ||
1224 | { | ||
1225 | static LLNameValue retval; | ||
1226 | |||
1227 | switch(a.mType) | ||
1228 | { | ||
1229 | case NVT_STRING: | ||
1230 | if (b.mType == NVT_STRING) | ||
1231 | { | ||
1232 | retval.mType = a.mType; | ||
1233 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1234 | |||
1235 | S32 length1 = (S32)strlen(a.mNameValueReference.string); /* Flawfinder: Ignore */ | ||
1236 | S32 length2 = (S32)strlen(b.mNameValueReference.string); /* Flawfinder: Ignore */ | ||
1237 | delete [] retval.mNameValueReference.string; | ||
1238 | retval.mNameValueReference.string = new char[length1 + length2 + 1]; | ||
1239 | if(retval.mNameValueReference.string != NULL) | ||
1240 | { | ||
1241 | strcpy(retval.mNameValueReference.string, a.mNameValueReference.string); /* Flawfinder: Ignore */ | ||
1242 | strcat(retval.mNameValueReference.string, b.mNameValueReference.string); /* Flawfinder: Ignore */ | ||
1243 | } | ||
1244 | } | ||
1245 | break; | ||
1246 | case NVT_F32: | ||
1247 | if (b.mType == NVT_F32) | ||
1248 | { | ||
1249 | retval.mType = NVT_F32; | ||
1250 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1251 | delete retval.mNameValueReference.f32; | ||
1252 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 + *b.mNameValueReference.f32); | ||
1253 | } | ||
1254 | else if (b.mType == NVT_S32) | ||
1255 | { | ||
1256 | retval.mType = NVT_F32; | ||
1257 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1258 | delete retval.mNameValueReference.f32; | ||
1259 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 + *b.mNameValueReference.s32); | ||
1260 | } | ||
1261 | else if (b.mType == NVT_U32) | ||
1262 | { | ||
1263 | retval.mType = NVT_F32; | ||
1264 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1265 | delete retval.mNameValueReference.f32; | ||
1266 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 + *b.mNameValueReference.u32); | ||
1267 | } | ||
1268 | break; | ||
1269 | case NVT_S32: | ||
1270 | if (b.mType == NVT_F32) | ||
1271 | { | ||
1272 | retval.mType = NVT_F32; | ||
1273 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1274 | delete retval.mNameValueReference.f32; | ||
1275 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 + *b.mNameValueReference.f32); | ||
1276 | } | ||
1277 | else if (b.mType == NVT_S32) | ||
1278 | { | ||
1279 | retval.mType = NVT_S32; | ||
1280 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1281 | delete retval.mNameValueReference.s32; | ||
1282 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 + *b.mNameValueReference.s32); | ||
1283 | } | ||
1284 | else if (b.mType == NVT_U32) | ||
1285 | { | ||
1286 | retval.mType = NVT_S32; | ||
1287 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1288 | delete retval.mNameValueReference.s32; | ||
1289 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 + *b.mNameValueReference.u32); | ||
1290 | } | ||
1291 | break; | ||
1292 | case NVT_U32: | ||
1293 | if (b.mType == NVT_F32) | ||
1294 | { | ||
1295 | retval.mType = NVT_F32; | ||
1296 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1297 | delete retval.mNameValueReference.f32; | ||
1298 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 + *b.mNameValueReference.f32); | ||
1299 | } | ||
1300 | else if (b.mType == NVT_S32) | ||
1301 | { | ||
1302 | retval.mType = NVT_S32; | ||
1303 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1304 | delete retval.mNameValueReference.s32; | ||
1305 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 + *b.mNameValueReference.s32); | ||
1306 | } | ||
1307 | else if (b.mType == NVT_U32) | ||
1308 | { | ||
1309 | retval.mType = NVT_U32; | ||
1310 | retval.mStringType = NameValueTypeStrings[NVT_U32]; | ||
1311 | delete retval.mNameValueReference.u32; | ||
1312 | retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 + *b.mNameValueReference.u32); | ||
1313 | } | ||
1314 | break; | ||
1315 | case NVT_VEC3: | ||
1316 | if ( (a.mType == b.mType) | ||
1317 | &&(a.mType == NVT_VEC3)) | ||
1318 | { | ||
1319 | retval.mType = a.mType; | ||
1320 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1321 | delete retval.mNameValueReference.vec3; | ||
1322 | retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 + *b.mNameValueReference.vec3); | ||
1323 | } | ||
1324 | break; | ||
1325 | default: | ||
1326 | llerrs << "Unknown add of NV type " << a.mStringType << " to " << b.mStringType << llendl; | ||
1327 | break; | ||
1328 | } | ||
1329 | return retval; | ||
1330 | } | ||
1331 | |||
1332 | LLNameValue &operator-(const LLNameValue &a, const LLNameValue &b) | ||
1333 | { | ||
1334 | static LLNameValue retval; | ||
1335 | |||
1336 | switch(a.mType) | ||
1337 | { | ||
1338 | case NVT_STRING: | ||
1339 | break; | ||
1340 | case NVT_F32: | ||
1341 | if (b.mType == NVT_F32) | ||
1342 | { | ||
1343 | retval.mType = NVT_F32; | ||
1344 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1345 | delete retval.mNameValueReference.f32; | ||
1346 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 - *b.mNameValueReference.f32); | ||
1347 | } | ||
1348 | else if (b.mType == NVT_S32) | ||
1349 | { | ||
1350 | retval.mType = NVT_F32; | ||
1351 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1352 | delete retval.mNameValueReference.f32; | ||
1353 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 - *b.mNameValueReference.s32); | ||
1354 | } | ||
1355 | else if (b.mType == NVT_U32) | ||
1356 | { | ||
1357 | retval.mType = NVT_F32; | ||
1358 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1359 | delete retval.mNameValueReference.f32; | ||
1360 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 - *b.mNameValueReference.u32); | ||
1361 | } | ||
1362 | break; | ||
1363 | case NVT_S32: | ||
1364 | if (b.mType == NVT_F32) | ||
1365 | { | ||
1366 | retval.mType = NVT_F32; | ||
1367 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1368 | delete retval.mNameValueReference.f32; | ||
1369 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 - *b.mNameValueReference.f32); | ||
1370 | } | ||
1371 | else if (b.mType == NVT_S32) | ||
1372 | { | ||
1373 | retval.mType = NVT_S32; | ||
1374 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1375 | delete retval.mNameValueReference.s32; | ||
1376 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 - *b.mNameValueReference.s32); | ||
1377 | } | ||
1378 | else if (b.mType == NVT_U32) | ||
1379 | { | ||
1380 | retval.mType = NVT_S32; | ||
1381 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1382 | delete retval.mNameValueReference.s32; | ||
1383 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 - *b.mNameValueReference.u32); | ||
1384 | } | ||
1385 | break; | ||
1386 | case NVT_U32: | ||
1387 | if (b.mType == NVT_F32) | ||
1388 | { | ||
1389 | retval.mType = NVT_F32; | ||
1390 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1391 | delete retval.mNameValueReference.f32; | ||
1392 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 - *b.mNameValueReference.f32); | ||
1393 | } | ||
1394 | else if (b.mType == NVT_S32) | ||
1395 | { | ||
1396 | retval.mType = NVT_S32; | ||
1397 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1398 | delete retval.mNameValueReference.s32; | ||
1399 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 - *b.mNameValueReference.s32); | ||
1400 | } | ||
1401 | else if (b.mType == NVT_U32) | ||
1402 | { | ||
1403 | retval.mType = NVT_U32; | ||
1404 | retval.mStringType = NameValueTypeStrings[NVT_U32]; | ||
1405 | delete retval.mNameValueReference.u32; | ||
1406 | retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 - *b.mNameValueReference.u32); | ||
1407 | } | ||
1408 | break; | ||
1409 | case NVT_VEC3: | ||
1410 | if ( (a.mType == b.mType) | ||
1411 | &&(a.mType == NVT_VEC3)) | ||
1412 | { | ||
1413 | retval.mType = a.mType; | ||
1414 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1415 | delete retval.mNameValueReference.vec3; | ||
1416 | retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 - *b.mNameValueReference.vec3); | ||
1417 | } | ||
1418 | break; | ||
1419 | default: | ||
1420 | llerrs << "Unknown subtract of NV type " << a.mStringType << " to " << b.mStringType << llendl; | ||
1421 | break; | ||
1422 | } | ||
1423 | return retval; | ||
1424 | } | ||
1425 | |||
1426 | LLNameValue &operator*(const LLNameValue &a, const LLNameValue &b) | ||
1427 | { | ||
1428 | static LLNameValue retval; | ||
1429 | |||
1430 | switch(a.mType) | ||
1431 | { | ||
1432 | case NVT_STRING: | ||
1433 | break; | ||
1434 | case NVT_F32: | ||
1435 | if (b.mType == NVT_F32) | ||
1436 | { | ||
1437 | retval.mType = NVT_F32; | ||
1438 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1439 | delete retval.mNameValueReference.f32; | ||
1440 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * *b.mNameValueReference.f32); | ||
1441 | } | ||
1442 | else if (b.mType == NVT_S32) | ||
1443 | { | ||
1444 | retval.mType = NVT_F32; | ||
1445 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1446 | delete retval.mNameValueReference.f32; | ||
1447 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * *b.mNameValueReference.s32); | ||
1448 | } | ||
1449 | else if (b.mType == NVT_U32) | ||
1450 | { | ||
1451 | retval.mType = NVT_F32; | ||
1452 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1453 | delete retval.mNameValueReference.f32; | ||
1454 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * *b.mNameValueReference.u32); | ||
1455 | } | ||
1456 | break; | ||
1457 | case NVT_S32: | ||
1458 | if (b.mType == NVT_F32) | ||
1459 | { | ||
1460 | retval.mType = NVT_F32; | ||
1461 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1462 | delete retval.mNameValueReference.f32; | ||
1463 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 * *b.mNameValueReference.f32); | ||
1464 | } | ||
1465 | else if (b.mType == NVT_S32) | ||
1466 | { | ||
1467 | retval.mType = NVT_S32; | ||
1468 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1469 | delete retval.mNameValueReference.s32; | ||
1470 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 * *b.mNameValueReference.s32); | ||
1471 | } | ||
1472 | else if (b.mType == NVT_U32) | ||
1473 | { | ||
1474 | retval.mType = NVT_S32; | ||
1475 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1476 | delete retval.mNameValueReference.s32; | ||
1477 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 * *b.mNameValueReference.u32); | ||
1478 | } | ||
1479 | break; | ||
1480 | case NVT_U32: | ||
1481 | if (b.mType == NVT_F32) | ||
1482 | { | ||
1483 | retval.mType = NVT_F32; | ||
1484 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1485 | delete retval.mNameValueReference.f32; | ||
1486 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 * *b.mNameValueReference.f32); | ||
1487 | } | ||
1488 | else if (b.mType == NVT_S32) | ||
1489 | { | ||
1490 | retval.mType = NVT_S32; | ||
1491 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1492 | delete retval.mNameValueReference.s32; | ||
1493 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 * *b.mNameValueReference.s32); | ||
1494 | } | ||
1495 | else if (b.mType == NVT_U32) | ||
1496 | { | ||
1497 | retval.mType = NVT_U32; | ||
1498 | retval.mStringType = NameValueTypeStrings[NVT_U32]; | ||
1499 | delete retval.mNameValueReference.u32; | ||
1500 | retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 * *b.mNameValueReference.u32); | ||
1501 | } | ||
1502 | break; | ||
1503 | case NVT_VEC3: | ||
1504 | if ( (a.mType == b.mType) | ||
1505 | &&(a.mType == NVT_VEC3)) | ||
1506 | { | ||
1507 | retval.mType = NVT_F32; | ||
1508 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1509 | delete retval.mNameValueReference.f32; | ||
1510 | retval.mNameValueReference.f32 = new F32((*a.mNameValueReference.vec3) * (*b.mNameValueReference.vec3)); | ||
1511 | } | ||
1512 | break; | ||
1513 | default: | ||
1514 | llerrs << "Unknown multiply of NV type " << a.mStringType << " to " << b.mStringType << llendl; | ||
1515 | break; | ||
1516 | } | ||
1517 | return retval; | ||
1518 | } | ||
1519 | |||
1520 | LLNameValue &operator/(const LLNameValue &a, const LLNameValue &b) | ||
1521 | { | ||
1522 | static LLNameValue retval; | ||
1523 | |||
1524 | switch(a.mType) | ||
1525 | { | ||
1526 | case NVT_STRING: | ||
1527 | break; | ||
1528 | case NVT_F32: | ||
1529 | if (b.mType == NVT_F32) | ||
1530 | { | ||
1531 | retval.mType = NVT_F32; | ||
1532 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1533 | delete retval.mNameValueReference.f32; | ||
1534 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 / *b.mNameValueReference.f32); | ||
1535 | } | ||
1536 | else if (b.mType == NVT_S32) | ||
1537 | { | ||
1538 | retval.mType = NVT_F32; | ||
1539 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1540 | delete retval.mNameValueReference.f32; | ||
1541 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 / *b.mNameValueReference.s32); | ||
1542 | } | ||
1543 | else if (b.mType == NVT_U32) | ||
1544 | { | ||
1545 | retval.mType = NVT_F32; | ||
1546 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1547 | delete retval.mNameValueReference.f32; | ||
1548 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 / *b.mNameValueReference.u32); | ||
1549 | } | ||
1550 | break; | ||
1551 | case NVT_S32: | ||
1552 | if (b.mType == NVT_F32) | ||
1553 | { | ||
1554 | retval.mType = NVT_F32; | ||
1555 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1556 | delete retval.mNameValueReference.f32; | ||
1557 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 / *b.mNameValueReference.f32); | ||
1558 | } | ||
1559 | else if (b.mType == NVT_S32) | ||
1560 | { | ||
1561 | retval.mType = NVT_S32; | ||
1562 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1563 | delete retval.mNameValueReference.s32; | ||
1564 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 / *b.mNameValueReference.s32); | ||
1565 | } | ||
1566 | else if (b.mType == NVT_U32) | ||
1567 | { | ||
1568 | retval.mType = NVT_S32; | ||
1569 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1570 | delete retval.mNameValueReference.s32; | ||
1571 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 / *b.mNameValueReference.u32); | ||
1572 | } | ||
1573 | break; | ||
1574 | case NVT_U32: | ||
1575 | if (b.mType == NVT_F32) | ||
1576 | { | ||
1577 | retval.mType = NVT_F32; | ||
1578 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1579 | delete retval.mNameValueReference.f32; | ||
1580 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 / *b.mNameValueReference.f32); | ||
1581 | } | ||
1582 | else if (b.mType == NVT_S32) | ||
1583 | { | ||
1584 | retval.mType = NVT_S32; | ||
1585 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1586 | delete retval.mNameValueReference.s32; | ||
1587 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 / *b.mNameValueReference.s32); | ||
1588 | } | ||
1589 | else if (b.mType == NVT_U32) | ||
1590 | { | ||
1591 | retval.mType = NVT_U32; | ||
1592 | retval.mStringType = NameValueTypeStrings[NVT_U32]; | ||
1593 | delete retval.mNameValueReference.u32; | ||
1594 | retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 / *b.mNameValueReference.u32); | ||
1595 | } | ||
1596 | break; | ||
1597 | default: | ||
1598 | llerrs << "Unknown divide of NV type " << a.mStringType << " to " << b.mStringType << llendl; | ||
1599 | break; | ||
1600 | } | ||
1601 | return retval; | ||
1602 | } | ||
1603 | |||
1604 | LLNameValue &operator%(const LLNameValue &a, const LLNameValue &b) | ||
1605 | { | ||
1606 | static LLNameValue retval; | ||
1607 | |||
1608 | switch(a.mType) | ||
1609 | { | ||
1610 | case NVT_STRING: | ||
1611 | break; | ||
1612 | case NVT_F32: | ||
1613 | break; | ||
1614 | case NVT_S32: | ||
1615 | if (b.mType == NVT_S32) | ||
1616 | { | ||
1617 | retval.mType = NVT_S32; | ||
1618 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1619 | delete retval.mNameValueReference.s32; | ||
1620 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 % *b.mNameValueReference.s32); | ||
1621 | } | ||
1622 | else if (b.mType == NVT_U32) | ||
1623 | { | ||
1624 | retval.mType = NVT_S32; | ||
1625 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1626 | delete retval.mNameValueReference.s32; | ||
1627 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.s32 % *b.mNameValueReference.u32); | ||
1628 | } | ||
1629 | break; | ||
1630 | case NVT_U32: | ||
1631 | if (b.mType == NVT_S32) | ||
1632 | { | ||
1633 | retval.mType = NVT_S32; | ||
1634 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
1635 | delete retval.mNameValueReference.s32; | ||
1636 | retval.mNameValueReference.s32 = new S32(*a.mNameValueReference.u32 % *b.mNameValueReference.s32); | ||
1637 | } | ||
1638 | else if (b.mType == NVT_U32) | ||
1639 | { | ||
1640 | retval.mType = NVT_U32; | ||
1641 | retval.mStringType = NameValueTypeStrings[NVT_U32]; | ||
1642 | delete retval.mNameValueReference.u32; | ||
1643 | retval.mNameValueReference.u32 = new U32(*a.mNameValueReference.u32 % *b.mNameValueReference.u32); | ||
1644 | } | ||
1645 | break; | ||
1646 | case NVT_VEC3: | ||
1647 | if ( (a.mType == b.mType) | ||
1648 | &&(a.mType == NVT_VEC3)) | ||
1649 | { | ||
1650 | retval.mType = a.mType; | ||
1651 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1652 | delete retval.mNameValueReference.vec3; | ||
1653 | retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 % *b.mNameValueReference.vec3); | ||
1654 | } | ||
1655 | break; | ||
1656 | default: | ||
1657 | llerrs << "Unknown % of NV type " << a.mStringType << " to " << b.mStringType << llendl; | ||
1658 | break; | ||
1659 | } | ||
1660 | return retval; | ||
1661 | } | ||
1662 | |||
1663 | |||
1664 | // Multiplying anything times a float gives you some floats | ||
1665 | LLNameValue &operator*(const LLNameValue &a, F32 k) | ||
1666 | { | ||
1667 | static LLNameValue retval; | ||
1668 | |||
1669 | switch(a.mType) | ||
1670 | { | ||
1671 | case NVT_STRING: | ||
1672 | break; | ||
1673 | case NVT_F32: | ||
1674 | retval.mType = NVT_F32; | ||
1675 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1676 | delete retval.mNameValueReference.f32; | ||
1677 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * k); | ||
1678 | break; | ||
1679 | case NVT_S32: | ||
1680 | retval.mType = NVT_F32; | ||
1681 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1682 | delete retval.mNameValueReference.f32; | ||
1683 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 * k); | ||
1684 | break; | ||
1685 | case NVT_U32: | ||
1686 | retval.mType = NVT_F32; | ||
1687 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1688 | delete retval.mNameValueReference.f32; | ||
1689 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 * k); | ||
1690 | break; | ||
1691 | case NVT_VEC3: | ||
1692 | retval.mType = a.mType; | ||
1693 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1694 | delete retval.mNameValueReference.vec3; | ||
1695 | retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 * k); | ||
1696 | break; | ||
1697 | default: | ||
1698 | llerrs << "Unknown multiply of NV type " << a.mStringType << " with F32" << llendl; | ||
1699 | break; | ||
1700 | } | ||
1701 | return retval; | ||
1702 | } | ||
1703 | |||
1704 | |||
1705 | LLNameValue &operator*(F32 k, const LLNameValue &a) | ||
1706 | { | ||
1707 | static LLNameValue retval; | ||
1708 | |||
1709 | switch(a.mType) | ||
1710 | { | ||
1711 | case NVT_STRING: | ||
1712 | break; | ||
1713 | case NVT_F32: | ||
1714 | retval.mType = NVT_F32; | ||
1715 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1716 | delete retval.mNameValueReference.f32; | ||
1717 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.f32 * k); | ||
1718 | break; | ||
1719 | case NVT_S32: | ||
1720 | retval.mType = NVT_F32; | ||
1721 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1722 | delete retval.mNameValueReference.f32; | ||
1723 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.s32 * k); | ||
1724 | break; | ||
1725 | case NVT_U32: | ||
1726 | retval.mType = NVT_F32; | ||
1727 | retval.mStringType = NameValueTypeStrings[NVT_F32]; | ||
1728 | delete retval.mNameValueReference.f32; | ||
1729 | retval.mNameValueReference.f32 = new F32(*a.mNameValueReference.u32 * k); | ||
1730 | break; | ||
1731 | case NVT_VEC3: | ||
1732 | retval.mType = a.mType; | ||
1733 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
1734 | delete retval.mNameValueReference.vec3; | ||
1735 | retval.mNameValueReference.vec3 = new LLVector3(*a.mNameValueReference.vec3 * k); | ||
1736 | break; | ||
1737 | default: | ||
1738 | llerrs << "Unknown multiply of NV type " << a.mStringType << " with F32" << llendl; | ||
1739 | break; | ||
1740 | } | ||
1741 | return retval; | ||
1742 | } | ||
1743 | |||
1744 | |||
1745 | bool operator==(const LLNameValue &a, const LLNameValue &b) | ||
1746 | { | ||
1747 | switch(a.mType) | ||
1748 | { | ||
1749 | case NVT_STRING: | ||
1750 | if (b.mType == NVT_STRING) | ||
1751 | { | ||
1752 | if (!a.mNameValueReference.string) | ||
1753 | return FALSE; | ||
1754 | if (!b.mNameValueReference.string) | ||
1755 | return FALSE; | ||
1756 | return (!strcmp(a.mNameValueReference.string, b.mNameValueReference.string)); | ||
1757 | } | ||
1758 | break; | ||
1759 | case NVT_F32: | ||
1760 | if (b.mType == NVT_F32) | ||
1761 | { | ||
1762 | return (*a.mNameValueReference.f32 == *b.mNameValueReference.f32); | ||
1763 | } | ||
1764 | else if (b.mType == NVT_S32) | ||
1765 | { | ||
1766 | return (*a.mNameValueReference.f32 == *b.mNameValueReference.s32); | ||
1767 | } | ||
1768 | else if (b.mType == NVT_U32) | ||
1769 | { | ||
1770 | return (*a.mNameValueReference.f32 == *b.mNameValueReference.u32); | ||
1771 | } | ||
1772 | break; | ||
1773 | case NVT_S32: | ||
1774 | if (b.mType == NVT_F32) | ||
1775 | { | ||
1776 | return (*a.mNameValueReference.s32 == *b.mNameValueReference.f32); | ||
1777 | } | ||
1778 | else if (b.mType == NVT_S32) | ||
1779 | { | ||
1780 | return (*a.mNameValueReference.s32 == *b.mNameValueReference.s32); | ||
1781 | } | ||
1782 | else if (b.mType == NVT_U32) | ||
1783 | { | ||
1784 | return (*a.mNameValueReference.s32 == (S32) *b.mNameValueReference.u32); | ||
1785 | } | ||
1786 | break; | ||
1787 | case NVT_U32: | ||
1788 | if (b.mType == NVT_F32) | ||
1789 | { | ||
1790 | return (*a.mNameValueReference.u32 == *b.mNameValueReference.f32); | ||
1791 | } | ||
1792 | else if (b.mType == NVT_S32) | ||
1793 | { | ||
1794 | return ((S32) *a.mNameValueReference.u32 == *b.mNameValueReference.s32); | ||
1795 | } | ||
1796 | else if (b.mType == NVT_U32) | ||
1797 | { | ||
1798 | return (*a.mNameValueReference.u32 == *b.mNameValueReference.u32); | ||
1799 | } | ||
1800 | break; | ||
1801 | case NVT_VEC3: | ||
1802 | if ( (a.mType == b.mType) | ||
1803 | &&(a.mType == NVT_VEC3)) | ||
1804 | { | ||
1805 | return (*a.mNameValueReference.vec3 == *b.mNameValueReference.vec3); | ||
1806 | } | ||
1807 | break; | ||
1808 | default: | ||
1809 | llerrs << "Unknown == NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
1810 | break; | ||
1811 | } | ||
1812 | return FALSE; | ||
1813 | } | ||
1814 | |||
1815 | bool operator<=(const LLNameValue &a, const LLNameValue &b) | ||
1816 | { | ||
1817 | switch(a.mType) | ||
1818 | { | ||
1819 | case NVT_STRING: | ||
1820 | if (b.mType == NVT_STRING) | ||
1821 | { | ||
1822 | S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string); | ||
1823 | return (retval <= 0); | ||
1824 | } | ||
1825 | break; | ||
1826 | case NVT_F32: | ||
1827 | if (b.mType == NVT_F32) | ||
1828 | { | ||
1829 | return (*a.mNameValueReference.f32 <= *b.mNameValueReference.f32); | ||
1830 | } | ||
1831 | else if (b.mType == NVT_S32) | ||
1832 | { | ||
1833 | return (*a.mNameValueReference.f32 <= *b.mNameValueReference.s32); | ||
1834 | } | ||
1835 | else if (b.mType == NVT_U32) | ||
1836 | { | ||
1837 | return (*a.mNameValueReference.f32 <= *b.mNameValueReference.u32); | ||
1838 | } | ||
1839 | break; | ||
1840 | case NVT_S32: | ||
1841 | if (b.mType == NVT_F32) | ||
1842 | { | ||
1843 | return (*a.mNameValueReference.s32 <= *b.mNameValueReference.f32); | ||
1844 | } | ||
1845 | else if (b.mType == NVT_S32) | ||
1846 | { | ||
1847 | return (*a.mNameValueReference.s32 <= *b.mNameValueReference.s32); | ||
1848 | } | ||
1849 | else if (b.mType == NVT_U32) | ||
1850 | { | ||
1851 | return (*a.mNameValueReference.s32 <= (S32) *b.mNameValueReference.u32); | ||
1852 | } | ||
1853 | break; | ||
1854 | case NVT_U32: | ||
1855 | if (b.mType == NVT_F32) | ||
1856 | { | ||
1857 | return (*a.mNameValueReference.u32 <= *b.mNameValueReference.f32); | ||
1858 | } | ||
1859 | else if (b.mType == NVT_S32) | ||
1860 | { | ||
1861 | return ((S32) *a.mNameValueReference.u32 <= *b.mNameValueReference.s32); | ||
1862 | } | ||
1863 | else if (b.mType == NVT_U32) | ||
1864 | { | ||
1865 | return (*a.mNameValueReference.u32 <= *b.mNameValueReference.u32); | ||
1866 | } | ||
1867 | break; | ||
1868 | default: | ||
1869 | llerrs << "Unknown <= NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
1870 | break; | ||
1871 | } | ||
1872 | return FALSE; | ||
1873 | } | ||
1874 | |||
1875 | |||
1876 | bool operator>=(const LLNameValue &a, const LLNameValue &b) | ||
1877 | { | ||
1878 | switch(a.mType) | ||
1879 | { | ||
1880 | case NVT_STRING: | ||
1881 | if ( (a.mType == b.mType) | ||
1882 | &&(a.mType == NVT_STRING)) | ||
1883 | { | ||
1884 | S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string); | ||
1885 | return (retval >= 0); | ||
1886 | } | ||
1887 | break; | ||
1888 | case NVT_F32: | ||
1889 | if (b.mType == NVT_F32) | ||
1890 | { | ||
1891 | return (*a.mNameValueReference.f32 >= *b.mNameValueReference.f32); | ||
1892 | } | ||
1893 | else if (b.mType == NVT_S32) | ||
1894 | { | ||
1895 | return (*a.mNameValueReference.f32 >= *b.mNameValueReference.s32); | ||
1896 | } | ||
1897 | else if (b.mType == NVT_U32) | ||
1898 | { | ||
1899 | return (*a.mNameValueReference.f32 >= *b.mNameValueReference.u32); | ||
1900 | } | ||
1901 | break; | ||
1902 | case NVT_S32: | ||
1903 | if (b.mType == NVT_F32) | ||
1904 | { | ||
1905 | return (*a.mNameValueReference.s32 >= *b.mNameValueReference.f32); | ||
1906 | } | ||
1907 | else if (b.mType == NVT_S32) | ||
1908 | { | ||
1909 | return (*a.mNameValueReference.s32 >= *b.mNameValueReference.s32); | ||
1910 | } | ||
1911 | else if (b.mType == NVT_U32) | ||
1912 | { | ||
1913 | return (*a.mNameValueReference.s32 >= (S32) *b.mNameValueReference.u32); | ||
1914 | } | ||
1915 | break; | ||
1916 | case NVT_U32: | ||
1917 | if (b.mType == NVT_F32) | ||
1918 | { | ||
1919 | return (*a.mNameValueReference.u32 >= *b.mNameValueReference.f32); | ||
1920 | } | ||
1921 | else if (b.mType == NVT_S32) | ||
1922 | { | ||
1923 | return ((S32) *a.mNameValueReference.u32 >= *b.mNameValueReference.s32); | ||
1924 | } | ||
1925 | else if (b.mType == NVT_U32) | ||
1926 | { | ||
1927 | return (*a.mNameValueReference.u32 >= *b.mNameValueReference.u32); | ||
1928 | } | ||
1929 | break; | ||
1930 | default: | ||
1931 | llerrs << "Unknown >= NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
1932 | break; | ||
1933 | } | ||
1934 | return FALSE; | ||
1935 | } | ||
1936 | |||
1937 | |||
1938 | bool operator<(const LLNameValue &a, const LLNameValue &b) | ||
1939 | { | ||
1940 | switch(a.mType) | ||
1941 | { | ||
1942 | case NVT_STRING: | ||
1943 | if ( (a.mType == b.mType) | ||
1944 | &&(a.mType == NVT_STRING)) | ||
1945 | { | ||
1946 | S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string); | ||
1947 | return (retval < 0); | ||
1948 | } | ||
1949 | break; | ||
1950 | case NVT_F32: | ||
1951 | if (b.mType == NVT_F32) | ||
1952 | { | ||
1953 | return (*a.mNameValueReference.f32 < *b.mNameValueReference.f32); | ||
1954 | } | ||
1955 | else if (b.mType == NVT_S32) | ||
1956 | { | ||
1957 | return (*a.mNameValueReference.f32 < *b.mNameValueReference.s32); | ||
1958 | } | ||
1959 | else if (b.mType == NVT_U32) | ||
1960 | { | ||
1961 | return (*a.mNameValueReference.f32 < *b.mNameValueReference.u32); | ||
1962 | } | ||
1963 | break; | ||
1964 | case NVT_S32: | ||
1965 | if (b.mType == NVT_F32) | ||
1966 | { | ||
1967 | return (*a.mNameValueReference.s32 < *b.mNameValueReference.f32); | ||
1968 | } | ||
1969 | else if (b.mType == NVT_S32) | ||
1970 | { | ||
1971 | return (*a.mNameValueReference.s32 < *b.mNameValueReference.s32); | ||
1972 | } | ||
1973 | else if (b.mType == NVT_U32) | ||
1974 | { | ||
1975 | return (*a.mNameValueReference.s32 < (S32) *b.mNameValueReference.u32); | ||
1976 | } | ||
1977 | break; | ||
1978 | case NVT_U32: | ||
1979 | if (b.mType == NVT_F32) | ||
1980 | { | ||
1981 | return (*a.mNameValueReference.u32 < *b.mNameValueReference.f32); | ||
1982 | } | ||
1983 | else if (b.mType == NVT_S32) | ||
1984 | { | ||
1985 | return ((S32) *a.mNameValueReference.u32 < *b.mNameValueReference.s32); | ||
1986 | } | ||
1987 | else if (b.mType == NVT_U32) | ||
1988 | { | ||
1989 | return (*a.mNameValueReference.u32 < *b.mNameValueReference.u32); | ||
1990 | } | ||
1991 | break; | ||
1992 | default: | ||
1993 | llerrs << "Unknown < NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
1994 | break; | ||
1995 | } | ||
1996 | return FALSE; | ||
1997 | } | ||
1998 | |||
1999 | |||
2000 | bool operator>(const LLNameValue &a, const LLNameValue &b) | ||
2001 | { | ||
2002 | switch(a.mType) | ||
2003 | { | ||
2004 | case NVT_STRING: | ||
2005 | if ( (a.mType == b.mType) | ||
2006 | &&(a.mType == NVT_STRING)) | ||
2007 | { | ||
2008 | S32 retval = strcmp(a.mNameValueReference.string, b.mNameValueReference.string); | ||
2009 | return (retval > 0); | ||
2010 | } | ||
2011 | break; | ||
2012 | case NVT_F32: | ||
2013 | if (b.mType == NVT_F32) | ||
2014 | { | ||
2015 | return (*a.mNameValueReference.f32 > *b.mNameValueReference.f32); | ||
2016 | } | ||
2017 | else if (b.mType == NVT_S32) | ||
2018 | { | ||
2019 | return (*a.mNameValueReference.f32 > *b.mNameValueReference.s32); | ||
2020 | } | ||
2021 | else if (b.mType == NVT_U32) | ||
2022 | { | ||
2023 | return (*a.mNameValueReference.f32 > *b.mNameValueReference.u32); | ||
2024 | } | ||
2025 | break; | ||
2026 | case NVT_S32: | ||
2027 | if (b.mType == NVT_F32) | ||
2028 | { | ||
2029 | return (*a.mNameValueReference.s32 > *b.mNameValueReference.f32); | ||
2030 | } | ||
2031 | else if (b.mType == NVT_S32) | ||
2032 | { | ||
2033 | return (*a.mNameValueReference.s32 > *b.mNameValueReference.s32); | ||
2034 | } | ||
2035 | else if (b.mType == NVT_U32) | ||
2036 | { | ||
2037 | return (*a.mNameValueReference.s32 > (S32) *b.mNameValueReference.u32); | ||
2038 | } | ||
2039 | break; | ||
2040 | case NVT_U32: | ||
2041 | if (b.mType == NVT_F32) | ||
2042 | { | ||
2043 | return (*a.mNameValueReference.u32 > *b.mNameValueReference.f32); | ||
2044 | } | ||
2045 | else if (b.mType == NVT_S32) | ||
2046 | { | ||
2047 | return ((S32) *a.mNameValueReference.u32 > *b.mNameValueReference.s32); | ||
2048 | } | ||
2049 | else if (b.mType == NVT_U32) | ||
2050 | { | ||
2051 | return (*a.mNameValueReference.u32 > *b.mNameValueReference.u32); | ||
2052 | } | ||
2053 | break; | ||
2054 | default: | ||
2055 | llerrs << "Unknown > NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
2056 | break; | ||
2057 | } | ||
2058 | return FALSE; | ||
2059 | } | ||
2060 | |||
2061 | bool operator!=(const LLNameValue &a, const LLNameValue &b) | ||
2062 | { | ||
2063 | switch(a.mType) | ||
2064 | { | ||
2065 | case NVT_STRING: | ||
2066 | if ( (a.mType == b.mType) | ||
2067 | &&(a.mType == NVT_STRING)) | ||
2068 | { | ||
2069 | return (strcmp(a.mNameValueReference.string, b.mNameValueReference.string)) ? true : false; | ||
2070 | } | ||
2071 | break; | ||
2072 | case NVT_F32: | ||
2073 | if (b.mType == NVT_F32) | ||
2074 | { | ||
2075 | return (*a.mNameValueReference.f32 != *b.mNameValueReference.f32); | ||
2076 | } | ||
2077 | else if (b.mType == NVT_S32) | ||
2078 | { | ||
2079 | return (*a.mNameValueReference.f32 != *b.mNameValueReference.s32); | ||
2080 | } | ||
2081 | else if (b.mType == NVT_U32) | ||
2082 | { | ||
2083 | return (*a.mNameValueReference.f32 != *b.mNameValueReference.u32); | ||
2084 | } | ||
2085 | break; | ||
2086 | case NVT_S32: | ||
2087 | if (b.mType == NVT_F32) | ||
2088 | { | ||
2089 | return (*a.mNameValueReference.s32 != *b.mNameValueReference.f32); | ||
2090 | } | ||
2091 | else if (b.mType == NVT_S32) | ||
2092 | { | ||
2093 | return (*a.mNameValueReference.s32 != *b.mNameValueReference.s32); | ||
2094 | } | ||
2095 | else if (b.mType == NVT_U32) | ||
2096 | { | ||
2097 | return (*a.mNameValueReference.s32 != (S32) *b.mNameValueReference.u32); | ||
2098 | } | ||
2099 | break; | ||
2100 | case NVT_U32: | ||
2101 | if (b.mType == NVT_F32) | ||
2102 | { | ||
2103 | return (*a.mNameValueReference.u32 != *b.mNameValueReference.f32); | ||
2104 | } | ||
2105 | else if (b.mType == NVT_S32) | ||
2106 | { | ||
2107 | return ((S32) *a.mNameValueReference.u32 != *b.mNameValueReference.s32); | ||
2108 | } | ||
2109 | else if (b.mType == NVT_U32) | ||
2110 | { | ||
2111 | return (*a.mNameValueReference.u32 != *b.mNameValueReference.u32); | ||
2112 | } | ||
2113 | break; | ||
2114 | case NVT_VEC3: | ||
2115 | if ( (a.mType == b.mType) | ||
2116 | &&(a.mType == NVT_VEC3)) | ||
2117 | { | ||
2118 | return (*a.mNameValueReference.vec3 != *b.mNameValueReference.vec3); | ||
2119 | } | ||
2120 | break; | ||
2121 | default: | ||
2122 | llerrs << "Unknown != NV type " << a.mStringType << " with " << b.mStringType << llendl; | ||
2123 | break; | ||
2124 | } | ||
2125 | return FALSE; | ||
2126 | } | ||
2127 | |||
2128 | |||
2129 | LLNameValue &operator-(const LLNameValue &a) | ||
2130 | { | ||
2131 | static LLNameValue retval; | ||
2132 | |||
2133 | switch(a.mType) | ||
2134 | { | ||
2135 | case NVT_STRING: | ||
2136 | break; | ||
2137 | case NVT_F32: | ||
2138 | retval.mType = a.mType; | ||
2139 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
2140 | delete retval.mNameValueReference.f32; | ||
2141 | retval.mNameValueReference.f32 = new F32(-*a.mNameValueReference.f32); | ||
2142 | break; | ||
2143 | case NVT_S32: | ||
2144 | retval.mType = a.mType; | ||
2145 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
2146 | delete retval.mNameValueReference.s32; | ||
2147 | retval.mNameValueReference.s32 = new S32(-*a.mNameValueReference.s32); | ||
2148 | break; | ||
2149 | case NVT_U32: | ||
2150 | retval.mType = NVT_S32; | ||
2151 | retval.mStringType = NameValueTypeStrings[NVT_S32]; | ||
2152 | delete retval.mNameValueReference.s32; | ||
2153 | // Can't do unary minus on U32, doesn't work. | ||
2154 | retval.mNameValueReference.s32 = new S32(-S32(*a.mNameValueReference.u32)); | ||
2155 | break; | ||
2156 | case NVT_VEC3: | ||
2157 | retval.mType = a.mType; | ||
2158 | retval.mStringType = NameValueTypeStrings[a.mType]; | ||
2159 | delete retval.mNameValueReference.vec3; | ||
2160 | retval.mNameValueReference.vec3 = new LLVector3(-*a.mNameValueReference.vec3); | ||
2161 | break; | ||
2162 | default: | ||
2163 | llerrs << "Unknown - NV type " << a.mStringType << llendl; | ||
2164 | break; | ||
2165 | } | ||
2166 | return retval; | ||
2167 | } | ||