llnamevalue.cpp

Go to the documentation of this file.
00001 
00032 // Examples:
00033 // AvatarCharacter STRING RW DSV male1
00034 
00035 #include "linden_common.h"
00036 
00037 #include "llnamevalue.h"
00038 
00039 #include "u64.h"
00040 #include "llstring.h"
00041 #include "llcamera.h"
00042 #include "string_table.h"
00043 
00044 // Anonymous enumeration to provide constants in this file.
00045 // *NOTE: These values may be used in sscanf statements below as their
00046 // value-1, so search for '2047' if you cange NV_BUFFER_LEN or '63' if
00047 // you change U64_BUFFER_LEN.
00048 enum
00049 {
00050         NV_BUFFER_LEN = 2048,
00051         U64_BUFFER_LEN = 64
00052 };
00053 
00054 LLStringTable   gNVNameTable(256);
00055 
00056 char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH] = /*Flawfinder: Ignore*/
00057 {
00058         "NULL",
00059         "STRING",
00060         "F32",
00061         "S32",
00062         "VEC3",
00063         "U32",
00064         "CAMERA", // Deprecated, but leaving in case removing completely would cause problems
00065         "ASSET",
00066         "U64"
00067 };              
00068 
00069 char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH] = /*Flawfinder: Ignore*/
00070 {
00071         "NULL",
00072         "R",                    // read only
00073         "RW"                    // read write
00074 };              
00075 
00076 char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH] = /*Flawfinder: Ignore*/
00077 {
00078         "NULL",
00079         "S",    // "Sim", formerly SIM
00080         "DS",   // "Data Sim" formerly SIM_SPACE
00081         "SV",   // "Sim Viewer" formerly SIM_VIEWER
00082         "DSV"   // "Data Sim Viewer", formerly SIM_SPACE_VIEWER
00083 };              /*Flawfinder: Ignore*/
00084 
00085 
00086 //
00087 // Class
00088 //
00089 
00090 LLNameValue::LLNameValue()
00091 {
00092         baseInit();
00093 }
00094 
00095 void LLNameValue::baseInit()
00096 {
00097         mNVNameTable = &gNVNameTable;
00098 
00099         mName = NULL;
00100         mNameValueReference.string = NULL;
00101 
00102         mType = NVT_NULL;
00103         mStringType = NameValueTypeStrings[NVT_NULL];
00104         
00105         mClass = NVC_NULL;
00106         mStringClass = NameValueClassStrings[NVC_NULL];
00107         
00108         mSendto = NVS_NULL;
00109         mStringSendto = NameValueSendtoStrings[NVS_NULL];
00110 }
00111 
00112 void LLNameValue::init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto)
00113 {
00114         mNVNameTable = &gNVNameTable;
00115 
00116         mName = mNVNameTable->addString(name);
00117         
00118         // Nota Bene: Whatever global structure manages this should have these in the name table already!
00119         mStringType = mNVNameTable->addString(type);
00120         if (!strcmp(mStringType, "STRING"))
00121         {
00122                 S32 string_length = (S32)strlen(data);          /*Flawfinder: Ignore*/
00123                 mType = NVT_STRING;
00124 
00125                 delete[] mNameValueReference.string;
00126                 
00127                 // two options here. . .  data can either look like foo or "foo"
00128                 // WRONG! - this is a poorly implemented and incomplete escape
00129                 // mechanism. For example, using this scheme, there is no way
00130                 // to tell an intentional double quotes from a zero length
00131                 // string. This needs to excised. Phoenix
00132                 //if (strchr(data, '\"'))
00133                 //{
00134                 //      string_length -= 2;
00135                 //      mNameValueReference.string = new char[string_length + 1];;
00136                 //      strncpy(mNameValueReference.string, data + 1, string_length);
00137                 //}
00138                 //else
00139                 //{
00140                 mNameValueReference.string = new char[string_length + 1];;
00141                 strncpy(mNameValueReference.string, data, string_length);               /*Flawfinder: Ignore*/
00142                 //}
00143                 mNameValueReference.string[string_length] = 0;
00144         }
00145         else if (!strcmp(mStringType, "F32"))
00146         {
00147                 mType = NVT_F32;
00148                 mNameValueReference.f32 = new F32((F32)atof(data));
00149         }
00150         else if (!strcmp(mStringType, "S32"))
00151         {
00152                 mType = NVT_S32;
00153                 mNameValueReference.s32 = new S32(atoi(data));
00154         }
00155         else if (!strcmp(mStringType, "U64"))
00156         {
00157                 mType = NVT_U64;
00158                 mNameValueReference.u64 = new U64(str_to_U64(data));
00159         }
00160         else if (!strcmp(mStringType, "VEC3"))
00161         {
00162                 mType = NVT_VEC3;
00163                 F32 t1, t2, t3;
00164 
00165                 // two options here. . .  data can either look like 0, 1, 2 or <0, 1, 2>
00166 
00167                 if (strchr(data, '<'))
00168                 {
00169                         sscanf(data, "<%f, %f, %f>", &t1, &t2, &t3);
00170                 }
00171                 else
00172                 {
00173                         sscanf(data, "%f, %f, %f", &t1, &t2, &t3);
00174                 }
00175 
00176                 // finite checks
00177                 if (!llfinite(t1) || !llfinite(t2) || !llfinite(t3))
00178                 {
00179                         t1 = 0.f;
00180                         t2 = 0.f;
00181                         t3 = 0.f;
00182                 }
00183 
00184                 mNameValueReference.vec3 = new LLVector3(t1, t2, t3);
00185         }
00186         else if (!strcmp(mStringType, "U32"))
00187         {
00188                 mType = NVT_U32;
00189                 mNameValueReference.u32 = new U32(atoi(data));
00190         }
00191         else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
00192         {
00193                 // assets are treated like strings, except that the name has
00194                 // meaning to an LLAssetInfo object
00195                 S32 string_length = (S32)strlen(data);          /*Flawfinder: Ignore*/
00196                 mType = NVT_ASSET;
00197 
00198                 // two options here. . .  data can either look like foo or "foo"
00199                 // WRONG! - this is a poorly implemented and incomplete escape
00200                 // mechanism. For example, using this scheme, there is no way
00201                 // to tell an intentional double quotes from a zero length
00202                 // string. This needs to excised. Phoenix
00203                 //if (strchr(data, '\"'))
00204                 //{
00205                 //      string_length -= 2;
00206                 //      mNameValueReference.string = new char[string_length + 1];;
00207                 //      strncpy(mNameValueReference.string, data + 1, string_length);
00208                 //}
00209                 //else
00210                 //{
00211                 mNameValueReference.string = new char[string_length + 1];;
00212                 strncpy(mNameValueReference.string, data, string_length);               /*Flawfinder: Ignore*/
00213                 //}
00214                 mNameValueReference.string[string_length] = 0;
00215         }
00216         else
00217         {
00218                 llwarns << "Unknown name value type string " << mStringType << " for " << mName << llendl;
00219                 mType = NVT_NULL;
00220         }
00221 
00222 
00223         // Nota Bene: Whatever global structure manages this should have these in the name table already!
00224         if (!strcmp(nvclass, "R") ||
00225                 !strcmp(nvclass, "READ_ONLY"))                  // legacy
00226         {
00227                 mClass = NVC_READ_ONLY;
00228                 mStringClass = mNVNameTable->addString("R");
00229         }
00230         else if (!strcmp(nvclass, "RW") ||
00231                         !strcmp(nvclass, "READ_WRITE")) // legacy
00232         {
00233                 mClass = NVC_READ_WRITE;
00234                 mStringClass = mNVNameTable->addString("RW");
00235         }
00236         else
00237         {
00238                 // assume it's bad
00239                 mClass = NVC_NULL;
00240                 mStringClass = mNVNameTable->addString(nvclass);
00241         }
00242 
00243         // Initialize the sendto variable
00244         if (!strcmp(nvsendto, "S") ||
00245                 !strcmp(nvsendto, "SIM"))                       // legacy
00246         {
00247                 mSendto = NVS_SIM;
00248                 mStringSendto = mNVNameTable->addString("S");
00249         }
00250         else if (!strcmp(nvsendto, "DS") ||
00251                 !strcmp(nvsendto, "SIM_SPACE")) // legacy
00252         {
00253                 mSendto = NVS_DATA_SIM;
00254                 mStringSendto = mNVNameTable->addString("DS");
00255         }
00256         else if (!strcmp(nvsendto, "SV") ||
00257                         !strcmp(nvsendto, "SIM_VIEWER"))        // legacy
00258         {
00259                 mSendto = NVS_SIM_VIEWER;
00260                 mStringSendto = mNVNameTable->addString("SV");
00261         }
00262         else if (!strcmp(nvsendto, "DSV") ||
00263                         !strcmp(nvsendto, "SIM_SPACE_VIEWER"))  // legacy
00264         {
00265                 mSendto = NVS_DATA_SIM_VIEWER;
00266                 mStringSendto = mNVNameTable->addString("DSV");
00267         }
00268         else
00269         {
00270                 llwarns << "LLNameValue::init() - unknown sendto field " 
00271                                 << nvsendto << " for NV " << mName << llendl;
00272                 mSendto = NVS_NULL;
00273                 mStringSendto = mNVNameTable->addString("S");
00274         }
00275 
00276 }
00277 
00278 
00279 LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass)
00280 {
00281         baseInit();
00282         // if not specified, send to simulator only
00283         init(name, data, type, nvclass, "SIM");
00284 }
00285 
00286 
00287 LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto)
00288 {
00289         baseInit();
00290         init(name, data, type, nvclass, nvsendto);
00291 }
00292 
00293 
00294 
00295 // Initialize without any initial data.
00296 LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass)
00297 {
00298         baseInit();
00299         mName = mNVNameTable->addString(name);
00300         
00301         // Nota Bene: Whatever global structure manages this should have these in the name table already!
00302         mStringType = mNVNameTable->addString(type);
00303         if (!strcmp(mStringType, "STRING"))
00304         {
00305                 mType = NVT_STRING;
00306                 mNameValueReference.string = NULL;
00307         }
00308         else if (!strcmp(mStringType, "F32"))
00309         {
00310                 mType = NVT_F32;
00311                 mNameValueReference.f32 = NULL;
00312         }
00313         else if (!strcmp(mStringType, "S32"))
00314         {
00315                 mType = NVT_S32;
00316                 mNameValueReference.s32 = NULL;
00317         }
00318         else if (!strcmp(mStringType, "VEC3"))
00319         {
00320                 mType = NVT_VEC3;
00321                 mNameValueReference.vec3 = NULL;
00322         }
00323         else if (!strcmp(mStringType, "U32"))
00324         {
00325                 mType = NVT_U32;
00326                 mNameValueReference.u32 = NULL;
00327         }
00328         else if (!strcmp(mStringType, "U64"))
00329         {
00330                 mType = NVT_U64;
00331                 mNameValueReference.u64 = NULL;
00332         }
00333         else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
00334         {
00335                 mType = NVT_ASSET;
00336                 mNameValueReference.string = NULL;
00337         }
00338         else
00339         {
00340                 mType = NVT_NULL;
00341                 llinfos << "Unknown name-value type " << mStringType << llendl;
00342         }
00343 
00344         // Nota Bene: Whatever global structure manages this should have these in the name table already!
00345         mStringClass = mNVNameTable->addString(nvclass);
00346         if (!strcmp(mStringClass, "READ_ONLY"))
00347         {
00348                 mClass = NVC_READ_ONLY;
00349         }
00350         else if (!strcmp(mStringClass, "READ_WRITE"))
00351         {
00352                 mClass = NVC_READ_WRITE;
00353         }
00354         else
00355         {
00356                 mClass = NVC_NULL;
00357         }
00358 
00359         // Initialize the sendto variable
00360         mStringSendto = mNVNameTable->addString("SIM");
00361         mSendto = NVS_SIM;
00362 }
00363 
00364 
00365 // data is in the format:
00366 // "NameValueName       Type    Class   Data"
00367 LLNameValue::LLNameValue(const char *data)
00368 {
00369         baseInit();
00370         static char name[NV_BUFFER_LEN];        /*Flawfinder: ignore*/
00371         static char type[NV_BUFFER_LEN];        /*Flawfinder: ignore*/
00372         static char nvclass[NV_BUFFER_LEN];     /*Flawfinder: ignore*/
00373         static char nvsendto[NV_BUFFER_LEN];    /*Flawfinder: ignore*/
00374         static char nvdata[NV_BUFFER_LEN];      /*Flawfinder: ignore*/
00375 
00376         S32 i;
00377 
00378         S32     character_count = 0;
00379         S32     length = 0;
00380 
00381         // go to first non-whitespace character
00382         while (1)
00383         {
00384                 if (  (*(data + character_count) == ' ')
00385                         ||(*(data + character_count) == '\n')
00386                         ||(*(data + character_count) == '\t')
00387                         ||(*(data + character_count) == '\r'))
00388                 {
00389                         character_count++;
00390                 }
00391                 else
00392                 {
00393                         break;
00394                 }
00395         }
00396 
00397         // read in the name
00398         sscanf((data + character_count), "%2047s", name);       /*Flawfinder: ignore*/
00399 
00400         // bump past it and add null terminator
00401         length = (S32)strlen(name);                     /* Flawfinder: ignore */
00402         name[length] = 0;
00403         character_count += length;
00404 
00405         // go to the next non-whitespace character
00406         while (1)
00407         {
00408                 if (  (*(data + character_count) == ' ')
00409                         ||(*(data + character_count) == '\n')
00410                         ||(*(data + character_count) == '\t')
00411                         ||(*(data + character_count) == '\r'))
00412                 {
00413                         character_count++;
00414                 }
00415                 else
00416                 {
00417                         break;
00418                 }
00419         }
00420 
00421         // read in the type
00422         sscanf((data + character_count), "%2047s", type);       /*Flawfinder: ignore*/
00423 
00424         // bump past it and add null terminator
00425         length = (S32)strlen(type);             /* Flawfinder: ignore */
00426         type[length] = 0;
00427         character_count += length;
00428 
00429         // go to the next non-whitespace character
00430         while (1)
00431         {
00432                 if (  (*(data + character_count) == ' ')
00433                         ||(*(data + character_count) == '\n')
00434                         ||(*(data + character_count) == '\t')
00435                         ||(*(data + character_count) == '\r'))
00436                 {
00437                         character_count++;
00438                 }
00439                 else
00440                 {
00441                         break;
00442                 }
00443         }
00444 
00445         // do we have a type argument?
00446         for (i = NVC_READ_ONLY; i < NVC_EOF; i++)
00447         {
00448                 if (!strncmp(NameValueClassStrings[i], data + character_count, strlen(NameValueClassStrings[i])))               /* Flawfinder: ignore */
00449                 {
00450                         break;
00451                 }
00452         }
00453 
00454         if (i != NVC_EOF)
00455         {
00456                 // yes we do!
00457                 // read in the class
00458                 sscanf((data + character_count), "%2047s", nvclass);    /*Flawfinder: ignore*/
00459 
00460                 // bump past it and add null terminator
00461                 length = (S32)strlen(nvclass);          /* Flawfinder: ignore */
00462                 nvclass[length] = 0;
00463                 character_count += length;
00464 
00465                 // go to the next non-whitespace character
00466                 while (1)
00467                 {
00468                         if (  (*(data + character_count) == ' ')
00469                                 ||(*(data + character_count) == '\n')
00470                                 ||(*(data + character_count) == '\t')
00471                                 ||(*(data + character_count) == '\r'))
00472                         {
00473                                 character_count++;
00474                         }
00475                         else
00476                         {
00477                                 break;
00478                         }
00479                 }
00480         }
00481         else
00482         {
00483                 // no type argument given, default to read-write
00484                 strncpy(nvclass, "READ_WRITE", sizeof(nvclass) -1);             /* Flawfinder: ignore */
00485                 nvclass[sizeof(nvclass) -1] = '\0';
00486         }
00487 
00488         // Do we have a sendto argument?
00489         for (i = NVS_SIM; i < NVS_EOF; i++)
00490         {
00491                 if (!strncmp(NameValueSendtoStrings[i], data + character_count, strlen(NameValueSendtoStrings[i])))             /* Flawfinder: ignore */
00492                 {
00493                         break;
00494                 }
00495         }
00496 
00497         if (i != NVS_EOF)
00498         {
00499                 // found a sendto argument
00500                 sscanf((data + character_count), "%2047s", nvsendto);   /*Flawfinder: ignore*/
00501 
00502                 // add null terminator
00503                 length = (S32)strlen(nvsendto);         /* Flawfinder: ignore */
00504                 nvsendto[length] = 0;
00505                 character_count += length;
00506 
00507                 // seek to next non-whitespace characer
00508                 while (1)
00509                 {
00510                         if (  (*(data + character_count) == ' ')
00511                                 ||(*(data + character_count) == '\n')
00512                                 ||(*(data + character_count) == '\t')
00513                                 ||(*(data + character_count) == '\r'))
00514                         {
00515                                 character_count++;
00516                         }
00517                         else
00518                         {
00519                                 break;
00520                         }
00521                 }
00522         }
00523         else
00524         {
00525                 // no sendto argument given, default to sim only
00526                 strncpy(nvsendto, "SIM", sizeof(nvsendto) -1);          /* Flawfinder: ignore */
00527                 nvsendto[sizeof(nvsendto) -1] ='\0';
00528         }
00529 
00530 
00531         // copy the rest character by character into data
00532         length = 0;
00533 
00534         while ( (*(nvdata + length++) = *(data + character_count++)) )
00535                 ;
00536 
00537         init(name, nvdata, type, nvclass, nvsendto);
00538 }
00539 
00540 
00541 LLNameValue::~LLNameValue()
00542 {
00543         mNVNameTable->removeString(mName);
00544         mName = NULL;
00545         
00546         switch(mType)
00547         {
00548         case NVT_STRING:
00549         case NVT_ASSET:
00550                 delete [] mNameValueReference.string;
00551                 mNameValueReference.string = NULL;
00552                 break;
00553         case NVT_F32:
00554                 delete mNameValueReference.f32;
00555                 mNameValueReference.string = NULL;
00556                 break;
00557         case NVT_S32:
00558                 delete mNameValueReference.s32;
00559                 mNameValueReference.string = NULL;
00560                 break;
00561         case NVT_VEC3:
00562                 delete mNameValueReference.vec3;
00563                 mNameValueReference.string = NULL;
00564                 break;
00565         case NVT_U32:
00566                 delete mNameValueReference.u32;
00567                 mNameValueReference.u32 = NULL;
00568                 break;
00569         case NVT_U64:
00570                 delete mNameValueReference.u64;
00571                 mNameValueReference.u64 = NULL;
00572                 break;
00573         default:
00574                 break;
00575         }
00576 
00577         delete[] mNameValueReference.string;
00578         mNameValueReference.string = NULL;
00579 }
00580 
00581 char    *LLNameValue::getString()
00582 {
00583         if (mType == NVT_STRING)
00584         {
00585                 return mNameValueReference.string;
00586         }
00587         else
00588         {
00589                 llerrs << mName << " not a string!" << llendl;
00590                 return NULL;
00591         }
00592 }
00593 
00594 const char *LLNameValue::getAsset() const
00595 {
00596         if (mType == NVT_ASSET)
00597         {
00598                 return mNameValueReference.string;
00599         }
00600         else
00601         {
00602                 llerrs << mName << " not an asset!" << llendl;
00603                 return NULL;
00604         }
00605 }
00606 
00607 F32             *LLNameValue::getF32()
00608 {
00609         if (mType == NVT_F32)
00610         {
00611                 return mNameValueReference.f32;
00612         }
00613         else
00614         {
00615                 llerrs << mName << " not a F32!" << llendl;
00616                 return NULL;
00617         }
00618 }
00619 
00620 S32             *LLNameValue::getS32()
00621 {
00622         if (mType == NVT_S32)
00623         {
00624                 return mNameValueReference.s32;
00625         }
00626         else
00627         {
00628                 llerrs << mName << " not a S32!" << llendl;
00629                 return NULL;
00630         }
00631 }
00632 
00633 U32             *LLNameValue::getU32()
00634 {
00635         if (mType == NVT_U32)
00636         {
00637                 return mNameValueReference.u32;
00638         }
00639         else
00640         {
00641                 llerrs << mName << " not a U32!" << llendl;
00642                 return NULL;
00643         }
00644 }
00645 
00646 U64             *LLNameValue::getU64()
00647 {
00648         if (mType == NVT_U64)
00649         {
00650                 return mNameValueReference.u64;
00651         }
00652         else
00653         {
00654                 llerrs << mName << " not a U64!" << llendl;
00655                 return NULL;
00656         }
00657 }
00658 
00659 void    LLNameValue::getVec3(LLVector3 &vec)
00660 {
00661         if (mType == NVT_VEC3)
00662         {
00663                 vec = *mNameValueReference.vec3;
00664         }
00665         else
00666         {
00667                 llerrs << mName << " not a Vec3!" << llendl;
00668         }
00669 }
00670 
00671 LLVector3       *LLNameValue::getVec3()
00672 {
00673         if (mType == NVT_VEC3)
00674         {
00675                  return (mNameValueReference.vec3);
00676         }
00677         else
00678         {
00679                 llerrs << mName << " not a Vec3!" << llendl;
00680                 return NULL;
00681         }
00682 }
00683 
00684 
00685 BOOL LLNameValue::sendToData() const
00686 {
00687         return (mSendto == NVS_DATA_SIM || mSendto == NVS_DATA_SIM_VIEWER);
00688 }
00689 
00690 
00691 BOOL LLNameValue::sendToViewer() const
00692 {
00693         return (mSendto == NVS_SIM_VIEWER || mSendto == NVS_DATA_SIM_VIEWER);
00694 }
00695 
00696 
00697 LLNameValue &LLNameValue::operator=(const LLNameValue &a)
00698 {
00699         if (mType != a.mType)
00700         {
00701                 return *this;
00702         }
00703         if (mClass == NVC_READ_ONLY)
00704                 return *this;
00705 
00706         switch(a.mType)
00707         {
00708         case NVT_STRING:
00709         case NVT_ASSET:
00710                 if (mNameValueReference.string)
00711                         delete [] mNameValueReference.string;
00712 
00713                 mNameValueReference.string = new char [strlen(a.mNameValueReference.string) + 1];               /* Flawfinder: ignore */
00714                 if(mNameValueReference.string != NULL)
00715                 {
00716                         strcpy(mNameValueReference.string, a.mNameValueReference.string);               /* Flawfinder: ignore */
00717                 }
00718                 break;
00719         case NVT_F32:
00720                 *mNameValueReference.f32 = *a.mNameValueReference.f32;
00721                 break;
00722         case NVT_S32:
00723                 *mNameValueReference.s32 = *a.mNameValueReference.s32;
00724                 break;
00725         case NVT_VEC3:
00726                 *mNameValueReference.vec3 = *a.mNameValueReference.vec3;
00727                 break;
00728         case NVT_U32:
00729                 *mNameValueReference.u32 = *a.mNameValueReference.u32;
00730                 break;
00731         case NVT_U64:
00732                 *mNameValueReference.u64 = *a.mNameValueReference.u64;
00733                 break;
00734         default:
00735                 llerrs << "Unknown Name value type " << (U32)a.mType << llendl;
00736                 break;
00737         }
00738 
00739         return *this;
00740 }
00741 
00742 void LLNameValue::setString(const char *a)
00743 {
00744         if (mClass == NVC_READ_ONLY)
00745                 return;
00746 
00747         switch(mType)
00748         {
00749         case NVT_STRING:
00750                 if (a)
00751                 {
00752                         if (mNameValueReference.string)
00753                         {
00754                                 delete [] mNameValueReference.string;
00755                         }
00756 
00757                         mNameValueReference.string = new char [strlen(a) + 1];          /* Flawfinder: ignore */
00758                         if(mNameValueReference.string != NULL)
00759                         {
00760                                 strcpy(mNameValueReference.string,  a);         /* Flawfinder: ignore */
00761                         }
00762                 }
00763                 else
00764                 {
00765                         if (mNameValueReference.string)
00766                                 delete [] mNameValueReference.string;
00767 
00768                         mNameValueReference.string = new char [1];
00769                         mNameValueReference.string[0] = 0;
00770                 }
00771                 break;
00772         default:
00773                 break;
00774         }
00775 
00776         return;
00777 }
00778 
00779 
00780 void LLNameValue::setAsset(const char *a)
00781 {
00782         if (mClass == NVC_READ_ONLY)
00783                 return;
00784 
00785         switch(mType)
00786         {
00787         case NVT_ASSET:
00788                 if (a)
00789                 {
00790                         if (mNameValueReference.string)
00791                         {
00792                                 delete [] mNameValueReference.string;
00793                         }
00794                         mNameValueReference.string = new char [strlen(a) + 1];                  /* Flawfinder: ignore */
00795                         if(mNameValueReference.string != NULL)
00796                         {
00797                                 strcpy(mNameValueReference.string,  a);         /* Flawfinder: ignore */
00798                         }
00799                 }
00800                 else
00801                 {
00802                         if (mNameValueReference.string)
00803                                 delete [] mNameValueReference.string;
00804 
00805                         mNameValueReference.string = new char [1];
00806                         mNameValueReference.string[0] = 0;
00807                 }
00808                 break;
00809         default:
00810                 break;
00811         }
00812 }
00813 
00814 
00815 void LLNameValue::setF32(const F32 a)
00816 {
00817         if (mClass == NVC_READ_ONLY)
00818                 return;
00819 
00820         switch(mType)
00821         {
00822         case NVT_F32:
00823                 *mNameValueReference.f32 = a;
00824                 break;
00825         default:
00826                 break;
00827         }
00828 
00829         return;
00830 }
00831 
00832 
00833 void LLNameValue::setS32(const S32 a)
00834 {
00835         if (mClass == NVC_READ_ONLY)
00836                 return;
00837 
00838         switch(mType)
00839         {
00840         case NVT_S32:
00841                 *mNameValueReference.s32 = a;
00842                 break;
00843         case NVT_U32:
00844                 *mNameValueReference.u32 = a;
00845                 break;
00846         case NVT_F32:
00847                 *mNameValueReference.f32 = (F32)a;
00848                 break;
00849         default:
00850                 break;
00851         }
00852 
00853         return;
00854 }
00855 
00856 
00857 void LLNameValue::setU32(const U32 a)
00858 {
00859         if (mClass == NVC_READ_ONLY)
00860                 return;
00861 
00862         switch(mType)
00863         {
00864         case NVT_S32:
00865                 *mNameValueReference.s32 = a;
00866                 break;
00867         case NVT_U32:
00868                 *mNameValueReference.u32 = a;
00869                 break;
00870         case NVT_F32:
00871                 *mNameValueReference.f32 = (F32)a;
00872                 break;
00873         default:
00874                 llerrs << "NameValue: Trying to set U32 into a " << mStringType << ", unknown conversion" << llendl;
00875                 break;
00876         }
00877         return;
00878 }
00879 
00880 
00881 void LLNameValue::setVec3(const LLVector3 &a)
00882 {
00883         if (mClass == NVC_READ_ONLY)
00884                 return;
00885 
00886         switch(mType)
00887         {
00888         case NVT_VEC3:
00889                 *mNameValueReference.vec3 = a;
00890                 break;
00891         default:
00892                 llerrs << "NameValue: Trying to set LLVector3 into a " << mStringType << ", unknown conversion" << llendl;
00893                 break;
00894         }
00895         return;
00896 }
00897 
00898 
00899 std::string LLNameValue::printNameValue()
00900 {
00901         std::string buffer;
00902         buffer = llformat("%s %s %s %s ", mName, mStringType, mStringClass, mStringSendto);
00903         buffer += printData();
00904 //      llinfos << "Name Value Length: " << buffer.size() + 1 << llendl;
00905         return buffer;
00906 }
00907 
00908 std::string LLNameValue::printData()
00909 {
00910         std::string buffer;
00911         switch(mType)
00912         {
00913         case NVT_STRING:
00914         case NVT_ASSET:
00915                 buffer = mNameValueReference.string;
00916                 break;
00917         case NVT_F32:
00918                 buffer = llformat("%f", *mNameValueReference.f32);
00919                 break;
00920         case NVT_S32:
00921                 buffer = llformat("%d", *mNameValueReference.s32);
00922                 break;
00923         case NVT_U32:
00924                 buffer = llformat("%u", *mNameValueReference.u32);
00925                 break;
00926         case NVT_U64:
00927                 {
00928                         char u64_string[U64_BUFFER_LEN];        /* Flawfinder: ignore */
00929                         U64_to_str(*mNameValueReference.u64, u64_string, sizeof(u64_string));
00930                         buffer = u64_string;
00931                 }
00932                 break;
00933         case NVT_VEC3:
00934                 buffer = llformat( "%f, %f, %f", mNameValueReference.vec3->mV[VX], mNameValueReference.vec3->mV[VY], mNameValueReference.vec3->mV[VZ]);
00935                 break;
00936         default:
00937                 llerrs << "Trying to print unknown NameValue type " << mStringType << llendl;
00938                 break;
00939         }
00940         return buffer;
00941 }
00942 
00943 std::ostream&           operator<<(std::ostream& s, const LLNameValue &a)
00944 {
00945         switch(a.mType)
00946         {
00947         case NVT_STRING:
00948         case NVT_ASSET:
00949                 s << a.mNameValueReference.string;
00950                 break;
00951         case NVT_F32:
00952                 s << (*a.mNameValueReference.f32);
00953                 break;
00954         case NVT_S32:
00955                 s << *(a.mNameValueReference.s32);
00956                 break;
00957         case NVT_U32:
00958                 s << *(a.mNameValueReference.u32);
00959                 break;
00960         case NVT_U64:
00961                 {
00962                         char u64_string[U64_BUFFER_LEN];        /* Flawfinder: ignore */
00963                         U64_to_str(*a.mNameValueReference.u64, u64_string, sizeof(u64_string));
00964                         s << u64_string;
00965                 }
00966         case NVT_VEC3:
00967                 s << *(a.mNameValueReference.vec3);
00968                 break;
00969         default:
00970                 llerrs << "Trying to print unknown NameValue type " << a.mStringType << llendl;
00971                 break;
00972         }
00973         return s;
00974 }
00975 

Generated on Fri May 16 08:32:29 2008 for SecondLife by  doxygen 1.5.5