1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
|
/**
* @file llnamevalue.cpp
* @brief class for defining name value pairs.
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2007, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
// Examples:
// AvatarCharacter STRING RW DSV male1
#include "linden_common.h"
#include "llnamevalue.h"
#include "u64.h"
#include "llstring.h"
#include "string_table.h"
// Anonymous enumeration to provide constants in this file.
// *NOTE: These values may be used in sscanf statements below as their
// value-1, so search for '2047' if you cange NV_BUFFER_LEN or '63' if
// you change U64_BUFFER_LEN.
enum
{
NV_BUFFER_LEN = 2048,
U64_BUFFER_LEN = 64
};
LLStringTable gNVNameTable(256);
char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH] = /*Flawfinder: Ignore*/
{
"NULL",
"STRING",
"F32",
"S32",
"VEC3",
"U32",
"CAMERA", // Deprecated, but leaving in case removing completely would cause problems
"ASSET",
"U64"
};
char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH] = /*Flawfinder: Ignore*/
{
"NULL",
"R", // read only
"RW" // read write
};
char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH] = /*Flawfinder: Ignore*/
{
"NULL",
"S", // "Sim", formerly SIM
"DS", // "Data Sim" formerly SIM_SPACE
"SV", // "Sim Viewer" formerly SIM_VIEWER
"DSV" // "Data Sim Viewer", formerly SIM_SPACE_VIEWER
}; /*Flawfinder: Ignore*/
//
// Class
//
LLNameValue::LLNameValue()
{
baseInit();
}
void LLNameValue::baseInit()
{
mNVNameTable = &gNVNameTable;
mName = NULL;
mNameValueReference.string = NULL;
mType = NVT_NULL;
mStringType = NameValueTypeStrings[NVT_NULL];
mClass = NVC_NULL;
mStringClass = NameValueClassStrings[NVC_NULL];
mSendto = NVS_NULL;
mStringSendto = NameValueSendtoStrings[NVS_NULL];
}
void LLNameValue::init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto)
{
mNVNameTable = &gNVNameTable;
mName = mNVNameTable->addString(name);
// Nota Bene: Whatever global structure manages this should have these in the name table already!
mStringType = mNVNameTable->addString(type);
if (!strcmp(mStringType, "STRING"))
{
S32 string_length = (S32)strlen(data); /*Flawfinder: Ignore*/
mType = NVT_STRING;
delete[] mNameValueReference.string;
// two options here. . . data can either look like foo or "foo"
// WRONG! - this is a poorly implemented and incomplete escape
// mechanism. For example, using this scheme, there is no way
// to tell an intentional double quotes from a zero length
// string. This needs to excised. Phoenix
//if (strchr(data, '\"'))
//{
// string_length -= 2;
// mNameValueReference.string = new char[string_length + 1];;
// strncpy(mNameValueReference.string, data + 1, string_length);
//}
//else
//{
mNameValueReference.string = new char[string_length + 1];;
strncpy(mNameValueReference.string, data, string_length); /*Flawfinder: Ignore*/
//}
mNameValueReference.string[string_length] = 0;
}
else if (!strcmp(mStringType, "F32"))
{
mType = NVT_F32;
mNameValueReference.f32 = new F32((F32)atof(data));
}
else if (!strcmp(mStringType, "S32"))
{
mType = NVT_S32;
mNameValueReference.s32 = new S32(atoi(data));
}
else if (!strcmp(mStringType, "U64"))
{
mType = NVT_U64;
mNameValueReference.u64 = new U64(str_to_U64(ll_safe_string(data)));
}
else if (!strcmp(mStringType, "VEC3"))
{
mType = NVT_VEC3;
F32 t1, t2, t3;
// two options here. . . data can either look like 0, 1, 2 or <0, 1, 2>
if (strchr(data, '<'))
{
sscanf(data, "<%f, %f, %f>", &t1, &t2, &t3);
}
else
{
sscanf(data, "%f, %f, %f", &t1, &t2, &t3);
}
// finite checks
if (!llfinite(t1) || !llfinite(t2) || !llfinite(t3))
{
t1 = 0.f;
t2 = 0.f;
t3 = 0.f;
}
mNameValueReference.vec3 = new LLVector3(t1, t2, t3);
}
else if (!strcmp(mStringType, "U32"))
{
mType = NVT_U32;
mNameValueReference.u32 = new U32(atoi(data));
}
else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
{
// assets are treated like strings, except that the name has
// meaning to an LLAssetInfo object
S32 string_length = (S32)strlen(data); /*Flawfinder: Ignore*/
mType = NVT_ASSET;
// two options here. . . data can either look like foo or "foo"
// WRONG! - this is a poorly implemented and incomplete escape
// mechanism. For example, using this scheme, there is no way
// to tell an intentional double quotes from a zero length
// string. This needs to excised. Phoenix
//if (strchr(data, '\"'))
//{
// string_length -= 2;
// mNameValueReference.string = new char[string_length + 1];;
// strncpy(mNameValueReference.string, data + 1, string_length);
//}
//else
//{
mNameValueReference.string = new char[string_length + 1];;
strncpy(mNameValueReference.string, data, string_length); /*Flawfinder: Ignore*/
//}
mNameValueReference.string[string_length] = 0;
}
else
{
llwarns << "Unknown name value type string " << mStringType << " for " << mName << llendl;
mType = NVT_NULL;
}
// Nota Bene: Whatever global structure manages this should have these in the name table already!
if (!strcmp(nvclass, "R") ||
!strcmp(nvclass, "READ_ONLY")) // legacy
{
mClass = NVC_READ_ONLY;
mStringClass = mNVNameTable->addString("R");
}
else if (!strcmp(nvclass, "RW") ||
!strcmp(nvclass, "READ_WRITE")) // legacy
{
mClass = NVC_READ_WRITE;
mStringClass = mNVNameTable->addString("RW");
}
else
{
// assume it's bad
mClass = NVC_NULL;
mStringClass = mNVNameTable->addString(nvclass);
}
// Initialize the sendto variable
if (!strcmp(nvsendto, "S") ||
!strcmp(nvsendto, "SIM")) // legacy
{
mSendto = NVS_SIM;
mStringSendto = mNVNameTable->addString("S");
}
else if (!strcmp(nvsendto, "DS") ||
!strcmp(nvsendto, "SIM_SPACE")) // legacy
{
mSendto = NVS_DATA_SIM;
mStringSendto = mNVNameTable->addString("DS");
}
else if (!strcmp(nvsendto, "SV") ||
!strcmp(nvsendto, "SIM_VIEWER")) // legacy
{
mSendto = NVS_SIM_VIEWER;
mStringSendto = mNVNameTable->addString("SV");
}
else if (!strcmp(nvsendto, "DSV") ||
!strcmp(nvsendto, "SIM_SPACE_VIEWER")) // legacy
{
mSendto = NVS_DATA_SIM_VIEWER;
mStringSendto = mNVNameTable->addString("DSV");
}
else
{
llwarns << "LLNameValue::init() - unknown sendto field "
<< nvsendto << " for NV " << mName << llendl;
mSendto = NVS_NULL;
mStringSendto = mNVNameTable->addString("S");
}
}
LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass)
{
baseInit();
// if not specified, send to simulator only
init(name, data, type, nvclass, "SIM");
}
LLNameValue::LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto)
{
baseInit();
init(name, data, type, nvclass, nvsendto);
}
// Initialize without any initial data.
LLNameValue::LLNameValue(const char *name, const char *type, const char *nvclass)
{
baseInit();
mName = mNVNameTable->addString(name);
// Nota Bene: Whatever global structure manages this should have these in the name table already!
mStringType = mNVNameTable->addString(type);
if (!strcmp(mStringType, "STRING"))
{
mType = NVT_STRING;
mNameValueReference.string = NULL;
}
else if (!strcmp(mStringType, "F32"))
{
mType = NVT_F32;
mNameValueReference.f32 = NULL;
}
else if (!strcmp(mStringType, "S32"))
{
mType = NVT_S32;
mNameValueReference.s32 = NULL;
}
else if (!strcmp(mStringType, "VEC3"))
{
mType = NVT_VEC3;
mNameValueReference.vec3 = NULL;
}
else if (!strcmp(mStringType, "U32"))
{
mType = NVT_U32;
mNameValueReference.u32 = NULL;
}
else if (!strcmp(mStringType, "U64"))
{
mType = NVT_U64;
mNameValueReference.u64 = NULL;
}
else if(!strcmp(mStringType, (const char*)NameValueTypeStrings[NVT_ASSET]))
{
mType = NVT_ASSET;
mNameValueReference.string = NULL;
}
else
{
mType = NVT_NULL;
llinfos << "Unknown name-value type " << mStringType << llendl;
}
// Nota Bene: Whatever global structure manages this should have these in the name table already!
mStringClass = mNVNameTable->addString(nvclass);
if (!strcmp(mStringClass, "READ_ONLY"))
{
mClass = NVC_READ_ONLY;
}
else if (!strcmp(mStringClass, "READ_WRITE"))
{
mClass = NVC_READ_WRITE;
}
else
{
mClass = NVC_NULL;
}
// Initialize the sendto variable
mStringSendto = mNVNameTable->addString("SIM");
mSendto = NVS_SIM;
}
// data is in the format:
// "NameValueName Type Class Data"
LLNameValue::LLNameValue(const char *data)
{
baseInit();
static char name[NV_BUFFER_LEN]; /*Flawfinder: ignore*/
static char type[NV_BUFFER_LEN]; /*Flawfinder: ignore*/
static char nvclass[NV_BUFFER_LEN]; /*Flawfinder: ignore*/
static char nvsendto[NV_BUFFER_LEN]; /*Flawfinder: ignore*/
static char nvdata[NV_BUFFER_LEN]; /*Flawfinder: ignore*/
S32 i;
S32 character_count = 0;
S32 length = 0;
// go to first non-whitespace character
while (1)
{
if ( (*(data + character_count) == ' ')
||(*(data + character_count) == '\n')
||(*(data + character_count) == '\t')
||(*(data + character_count) == '\r'))
{
character_count++;
}
else
{
break;
}
}
// read in the name
sscanf((data + character_count), "%2047s", name); /*Flawfinder: ignore*/
// bump past it and add null terminator
length = (S32)strlen(name); /* Flawfinder: ignore */
name[length] = 0;
character_count += length;
// go to the next non-whitespace character
while (1)
{
if ( (*(data + character_count) == ' ')
||(*(data + character_count) == '\n')
||(*(data + character_count) == '\t')
||(*(data + character_count) == '\r'))
{
character_count++;
}
else
{
break;
}
}
// read in the type
sscanf((data + character_count), "%2047s", type); /*Flawfinder: ignore*/
// bump past it and add null terminator
length = (S32)strlen(type); /* Flawfinder: ignore */
type[length] = 0;
character_count += length;
// go to the next non-whitespace character
while (1)
{
if ( (*(data + character_count) == ' ')
||(*(data + character_count) == '\n')
||(*(data + character_count) == '\t')
||(*(data + character_count) == '\r'))
{
character_count++;
}
else
{
break;
}
}
// do we have a type argument?
for (i = NVC_READ_ONLY; i < NVC_EOF; i++)
{
if (!strncmp(NameValueClassStrings[i], data + character_count, strlen(NameValueClassStrings[i]))) /* Flawfinder: ignore */
{
break;
}
}
if (i != NVC_EOF)
{
// yes we do!
// read in the class
sscanf((data + character_count), "%2047s", nvclass); /*Flawfinder: ignore*/
// bump past it and add null terminator
length = (S32)strlen(nvclass); /* Flawfinder: ignore */
nvclass[length] = 0;
character_count += length;
// go to the next non-whitespace character
while (1)
{
if ( (*(data + character_count) == ' ')
||(*(data + character_count) == '\n')
||(*(data + character_count) == '\t')
||(*(data + character_count) == '\r'))
{
character_count++;
}
else
{
break;
}
}
}
else
{
// no type argument given, default to read-write
strncpy(nvclass, "READ_WRITE", sizeof(nvclass) -1); /* Flawfinder: ignore */
nvclass[sizeof(nvclass) -1] = '\0';
}
// Do we have a sendto argument?
for (i = NVS_SIM; i < NVS_EOF; i++)
{
if (!strncmp(NameValueSendtoStrings[i], data + character_count, strlen(NameValueSendtoStrings[i]))) /* Flawfinder: ignore */
{
break;
}
}
if (i != NVS_EOF)
{
// found a sendto argument
sscanf((data + character_count), "%2047s", nvsendto); /*Flawfinder: ignore*/
// add null terminator
length = (S32)strlen(nvsendto); /* Flawfinder: ignore */
nvsendto[length] = 0;
character_count += length;
// seek to next non-whitespace characer
while (1)
{
if ( (*(data + character_count) == ' ')
||(*(data + character_count) == '\n')
||(*(data + character_count) == '\t')
||(*(data + character_count) == '\r'))
{
character_count++;
}
else
{
break;
}
}
}
else
{
// no sendto argument given, default to sim only
strncpy(nvsendto, "SIM", sizeof(nvsendto) -1); /* Flawfinder: ignore */
nvsendto[sizeof(nvsendto) -1] ='\0';
}
// copy the rest character by character into data
length = 0;
while ( (*(nvdata + length++) = *(data + character_count++)) )
;
init(name, nvdata, type, nvclass, nvsendto);
}
LLNameValue::~LLNameValue()
{
mNVNameTable->removeString(mName);
mName = NULL;
switch(mType)
{
case NVT_STRING:
case NVT_ASSET:
delete [] mNameValueReference.string;
mNameValueReference.string = NULL;
break;
case NVT_F32:
delete mNameValueReference.f32;
mNameValueReference.string = NULL;
break;
case NVT_S32:
delete mNameValueReference.s32;
mNameValueReference.string = NULL;
break;
case NVT_VEC3:
delete mNameValueReference.vec3;
mNameValueReference.string = NULL;
break;
case NVT_U32:
delete mNameValueReference.u32;
mNameValueReference.u32 = NULL;
break;
case NVT_U64:
delete mNameValueReference.u64;
mNameValueReference.u64 = NULL;
break;
default:
break;
}
delete[] mNameValueReference.string;
mNameValueReference.string = NULL;
}
char *LLNameValue::getString()
{
if (mType == NVT_STRING)
{
return mNameValueReference.string;
}
else
{
llerrs << mName << " not a string!" << llendl;
return NULL;
}
}
const char *LLNameValue::getAsset() const
{
if (mType == NVT_ASSET)
{
return mNameValueReference.string;
}
else
{
llerrs << mName << " not an asset!" << llendl;
return NULL;
}
}
F32 *LLNameValue::getF32()
{
if (mType == NVT_F32)
{
return mNameValueReference.f32;
}
else
{
llerrs << mName << " not a F32!" << llendl;
return NULL;
}
}
S32 *LLNameValue::getS32()
{
if (mType == NVT_S32)
{
return mNameValueReference.s32;
}
else
{
llerrs << mName << " not a S32!" << llendl;
return NULL;
}
}
U32 *LLNameValue::getU32()
{
if (mType == NVT_U32)
{
return mNameValueReference.u32;
}
else
{
llerrs << mName << " not a U32!" << llendl;
return NULL;
}
}
U64 *LLNameValue::getU64()
{
if (mType == NVT_U64)
{
return mNameValueReference.u64;
}
else
{
llerrs << mName << " not a U64!" << llendl;
return NULL;
}
}
void LLNameValue::getVec3(LLVector3 &vec)
{
if (mType == NVT_VEC3)
{
vec = *mNameValueReference.vec3;
}
else
{
llerrs << mName << " not a Vec3!" << llendl;
}
}
LLVector3 *LLNameValue::getVec3()
{
if (mType == NVT_VEC3)
{
return (mNameValueReference.vec3);
}
else
{
llerrs << mName << " not a Vec3!" << llendl;
return NULL;
}
}
BOOL LLNameValue::sendToData() const
{
return (mSendto == NVS_DATA_SIM || mSendto == NVS_DATA_SIM_VIEWER);
}
BOOL LLNameValue::sendToViewer() const
{
return (mSendto == NVS_SIM_VIEWER || mSendto == NVS_DATA_SIM_VIEWER);
}
LLNameValue &LLNameValue::operator=(const LLNameValue &a)
{
if (mType != a.mType)
{
return *this;
}
if (mClass == NVC_READ_ONLY)
return *this;
switch(a.mType)
{
case NVT_STRING:
case NVT_ASSET:
if (mNameValueReference.string)
delete [] mNameValueReference.string;
mNameValueReference.string = new char [strlen(a.mNameValueReference.string) + 1]; /* Flawfinder: ignore */
if(mNameValueReference.string != NULL)
{
strcpy(mNameValueReference.string, a.mNameValueReference.string); /* Flawfinder: ignore */
}
break;
case NVT_F32:
*mNameValueReference.f32 = *a.mNameValueReference.f32;
break;
case NVT_S32:
*mNameValueReference.s32 = *a.mNameValueReference.s32;
break;
case NVT_VEC3:
*mNameValueReference.vec3 = *a.mNameValueReference.vec3;
break;
case NVT_U32:
*mNameValueReference.u32 = *a.mNameValueReference.u32;
break;
case NVT_U64:
*mNameValueReference.u64 = *a.mNameValueReference.u64;
break;
default:
llerrs << "Unknown Name value type " << (U32)a.mType << llendl;
break;
}
return *this;
}
void LLNameValue::setString(const char *a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_STRING:
if (a)
{
if (mNameValueReference.string)
{
delete [] mNameValueReference.string;
}
mNameValueReference.string = new char [strlen(a) + 1]; /* Flawfinder: ignore */
if(mNameValueReference.string != NULL)
{
strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */
}
}
else
{
if (mNameValueReference.string)
delete [] mNameValueReference.string;
mNameValueReference.string = new char [1];
mNameValueReference.string[0] = 0;
}
break;
default:
break;
}
return;
}
void LLNameValue::setAsset(const char *a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_ASSET:
if (a)
{
if (mNameValueReference.string)
{
delete [] mNameValueReference.string;
}
mNameValueReference.string = new char [strlen(a) + 1]; /* Flawfinder: ignore */
if(mNameValueReference.string != NULL)
{
strcpy(mNameValueReference.string, a); /* Flawfinder: ignore */
}
}
else
{
if (mNameValueReference.string)
delete [] mNameValueReference.string;
mNameValueReference.string = new char [1];
mNameValueReference.string[0] = 0;
}
break;
default:
break;
}
}
void LLNameValue::setF32(const F32 a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_F32:
*mNameValueReference.f32 = a;
break;
default:
break;
}
return;
}
void LLNameValue::setS32(const S32 a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_S32:
*mNameValueReference.s32 = a;
break;
case NVT_U32:
*mNameValueReference.u32 = a;
break;
case NVT_F32:
*mNameValueReference.f32 = (F32)a;
break;
default:
break;
}
return;
}
void LLNameValue::setU32(const U32 a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_S32:
*mNameValueReference.s32 = a;
break;
case NVT_U32:
*mNameValueReference.u32 = a;
break;
case NVT_F32:
*mNameValueReference.f32 = (F32)a;
break;
default:
llerrs << "NameValue: Trying to set U32 into a " << mStringType << ", unknown conversion" << llendl;
break;
}
return;
}
void LLNameValue::setVec3(const LLVector3 &a)
{
if (mClass == NVC_READ_ONLY)
return;
switch(mType)
{
case NVT_VEC3:
*mNameValueReference.vec3 = a;
break;
default:
llerrs << "NameValue: Trying to set LLVector3 into a " << mStringType << ", unknown conversion" << llendl;
break;
}
return;
}
std::string LLNameValue::printNameValue() const
{
std::string buffer;
buffer = llformat("%s %s %s %s ", mName, mStringType, mStringClass, mStringSendto);
buffer += printData();
// llinfos << "Name Value Length: " << buffer.size() + 1 << llendl;
return buffer;
}
std::string LLNameValue::printData() const
{
std::string buffer;
switch(mType)
{
case NVT_STRING:
case NVT_ASSET:
buffer = mNameValueReference.string;
break;
case NVT_F32:
buffer = llformat("%f", *mNameValueReference.f32);
break;
case NVT_S32:
buffer = llformat("%d", *mNameValueReference.s32);
break;
case NVT_U32:
buffer = llformat("%u", *mNameValueReference.u32);
break;
case NVT_U64:
{
char u64_string[U64_BUFFER_LEN]; /* Flawfinder: ignore */
U64_to_str(*mNameValueReference.u64, u64_string, sizeof(u64_string));
buffer = u64_string;
}
break;
case NVT_VEC3:
buffer = llformat( "%f, %f, %f", mNameValueReference.vec3->mV[VX], mNameValueReference.vec3->mV[VY], mNameValueReference.vec3->mV[VZ]);
break;
default:
llerrs << "Trying to print unknown NameValue type " << mStringType << llendl;
break;
}
return buffer;
}
std::ostream& operator<<(std::ostream& s, const LLNameValue &a)
{
switch(a.mType)
{
case NVT_STRING:
case NVT_ASSET:
s << a.mNameValueReference.string;
break;
case NVT_F32:
s << (*a.mNameValueReference.f32);
break;
case NVT_S32:
s << *(a.mNameValueReference.s32);
break;
case NVT_U32:
s << *(a.mNameValueReference.u32);
break;
case NVT_U64:
{
char u64_string[U64_BUFFER_LEN]; /* Flawfinder: ignore */
U64_to_str(*a.mNameValueReference.u64, u64_string, sizeof(u64_string));
s << u64_string;
}
case NVT_VEC3:
s << *(a.mNameValueReference.vec3);
break;
default:
llerrs << "Trying to print unknown NameValue type " << a.mStringType << llendl;
break;
}
return s;
}
|