]>
Commit | Line | Data |
---|---|---|
73abe331 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | $Log$ | |
d477ad88 | 18 | Revision 1.2 2005/11/17 14:43:23 byordano |
19 | import to local CVS | |
20 | ||
21 | Revision 1.1.1.1 2005/10/28 07:33:58 hristov | |
22 | Initial import as subdirectory in AliRoot | |
23 | ||
73abe331 | 24 | Revision 1.1.1.1 2005/09/12 22:11:40 byordano |
25 | SHUTTLE package | |
26 | ||
27 | Revision 1.2 2005/08/30 10:53:23 byordano | |
28 | some more descriptions added | |
29 | ||
30 | */ | |
31 | ||
32 | // | |
33 | // This class is a simple wrapper of | |
34 | // all primitive types used in PVSS SCADA system. | |
35 | // | |
36 | ||
37 | ||
38 | #include "AliSimpleValue.h" | |
39 | ||
40 | #include "AliLog.h" | |
41 | #include <TClass.h> | |
42 | ||
43 | TObject* AliSimpleValue::BoolHolder::Clone(const char* /*name*/) const { | |
44 | return new BoolHolder(fValue); | |
45 | } | |
46 | ||
47 | Bool_t AliSimpleValue::BoolHolder::IsEqual(const TObject* obj) const { | |
48 | ||
49 | if (this == obj) { | |
50 | return kTRUE; | |
51 | } | |
52 | ||
53 | if (BoolHolder::Class() != obj->IsA()) { | |
54 | return kFALSE; | |
55 | } | |
56 | ||
57 | return fValue == ((const BoolHolder*) obj)->fValue; | |
58 | } | |
59 | ||
60 | TObject* AliSimpleValue::ByteHolder::Clone(const char* /*name*/) const { | |
61 | return new ByteHolder(fValue); | |
62 | } | |
63 | ||
64 | Bool_t AliSimpleValue::ByteHolder::IsEqual(const TObject* obj) const { | |
65 | ||
66 | if (this == obj) { | |
67 | return kTRUE; | |
68 | } | |
69 | ||
70 | if (ByteHolder::Class() != obj->IsA()) { | |
71 | return kFALSE; | |
72 | } | |
73 | ||
74 | return fValue == ((const ByteHolder*) obj)->fValue; | |
75 | } | |
76 | ||
77 | TObject* AliSimpleValue::IntHolder::Clone(const char* /*name*/) const { | |
78 | return new IntHolder(fValue); | |
79 | } | |
80 | ||
81 | Bool_t AliSimpleValue::IntHolder::IsEqual(const TObject* obj) const { | |
82 | ||
83 | if (this == obj) { | |
84 | return kTRUE; | |
85 | } | |
86 | ||
87 | if (IntHolder::Class() != obj->IsA()) { | |
88 | return kFALSE; | |
89 | } | |
90 | ||
91 | return fValue == ((const IntHolder*) obj)->fValue; | |
92 | } | |
93 | ||
94 | TObject* AliSimpleValue::UIntHolder::Clone(const char* /*name*/) const { | |
95 | return new UIntHolder(fValue); | |
96 | } | |
97 | ||
98 | Bool_t AliSimpleValue::UIntHolder::IsEqual(const TObject* obj) const { | |
99 | ||
100 | if (this == obj) { | |
101 | return kTRUE; | |
102 | } | |
103 | ||
104 | if (UIntHolder::Class() != obj->IsA()) { | |
105 | return kFALSE; | |
106 | } | |
107 | ||
108 | return fValue == ((const UIntHolder*) obj)->fValue; | |
109 | } | |
110 | ||
111 | TObject* AliSimpleValue::FloatHolder::Clone(const char* /*name*/) const { | |
112 | return new FloatHolder(fValue); | |
113 | } | |
114 | ||
115 | Bool_t AliSimpleValue::FloatHolder::IsEqual(const TObject* obj) const { | |
116 | ||
117 | if (this == obj) { | |
118 | return kTRUE; | |
119 | } | |
120 | ||
121 | if (FloatHolder::Class() != obj->IsA()) { | |
122 | return kFALSE; | |
123 | } | |
124 | ||
125 | return fValue == ((const FloatHolder*) obj)->fValue; | |
126 | } | |
127 | ||
128 | TObject* AliSimpleValue::DynBoolHolder::Clone(const char* /*name*/) const { | |
129 | return new DynBoolHolder(fSize, fValues); | |
130 | } | |
131 | ||
132 | Bool_t AliSimpleValue::DynBoolHolder::IsEqual(const TObject* obj) const { | |
133 | ||
134 | if (this == obj) { | |
135 | return kTRUE; | |
136 | } | |
137 | ||
138 | if (DynBoolHolder::Class() != obj->IsA()) { | |
139 | return kFALSE; | |
140 | } | |
141 | ||
142 | const DynBoolHolder* other = ((const DynBoolHolder*) obj); | |
143 | ||
144 | if (fSize != other->fSize) { | |
145 | return kFALSE; | |
146 | } | |
147 | ||
148 | return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t)); | |
149 | } | |
150 | ||
151 | TObject* AliSimpleValue::DynByteHolder::Clone(const char* /*name*/) const { | |
152 | return new DynByteHolder(fSize, fValues); | |
153 | } | |
154 | ||
155 | Bool_t AliSimpleValue::DynByteHolder::IsEqual(const TObject* obj) const { | |
156 | ||
157 | if (this == obj) { | |
158 | return kTRUE; | |
159 | } | |
160 | ||
161 | if (DynByteHolder::Class() != obj->IsA()) { | |
162 | return kFALSE; | |
163 | } | |
164 | ||
165 | const DynByteHolder* other = ((const DynByteHolder*) obj); | |
166 | ||
167 | if (fSize != other->fSize) { | |
168 | return kFALSE; | |
169 | } | |
170 | ||
171 | return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t)); | |
172 | } | |
173 | ||
174 | TObject* AliSimpleValue::DynIntHolder::Clone(const char* /*name*/) const { | |
175 | return new DynIntHolder(fSize, fValues); | |
176 | } | |
177 | ||
178 | Bool_t AliSimpleValue::DynIntHolder::IsEqual(const TObject* obj) const { | |
179 | ||
180 | if (this == obj) { | |
181 | return kTRUE; | |
182 | } | |
183 | ||
184 | if (DynIntHolder::Class() != obj->IsA()) { | |
185 | return kFALSE; | |
186 | } | |
187 | ||
188 | const DynIntHolder* other = ((const DynIntHolder*) obj); | |
189 | ||
190 | if (fSize != other->fSize) { | |
191 | return kFALSE; | |
192 | } | |
193 | ||
194 | return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t)); | |
195 | } | |
196 | ||
197 | TObject* AliSimpleValue::DynUIntHolder::Clone(const char* /*name*/) const { | |
198 | return new DynUIntHolder(fSize, fValues); | |
199 | } | |
200 | ||
201 | Bool_t AliSimpleValue::DynUIntHolder::IsEqual(const TObject* obj) const { | |
202 | ||
203 | if (this == obj) { | |
204 | return kTRUE; | |
205 | } | |
206 | ||
207 | if (DynUIntHolder::Class() != obj->IsA()) { | |
208 | return kFALSE; | |
209 | } | |
210 | ||
211 | const DynUIntHolder* other = ((const DynUIntHolder*) obj); | |
212 | ||
213 | if (fSize != other->fSize) { | |
214 | return kFALSE; | |
215 | } | |
216 | ||
217 | return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t)); | |
218 | } | |
219 | ||
220 | TObject* AliSimpleValue::DynFloatHolder::Clone(const char* /*name*/) const { | |
221 | return new DynFloatHolder(fSize, fValues); | |
222 | } | |
223 | ||
224 | Bool_t AliSimpleValue::DynFloatHolder::IsEqual(const TObject* obj) const { | |
225 | ||
226 | if (this == obj) { | |
227 | return kTRUE; | |
228 | } | |
229 | ||
230 | if (DynFloatHolder::Class() != obj->IsA()) { | |
231 | return kFALSE; | |
232 | } | |
233 | ||
234 | const DynFloatHolder* other = ((const DynFloatHolder*) obj); | |
235 | ||
236 | if (fSize != other->fSize) { | |
237 | return kFALSE; | |
238 | } | |
239 | ||
240 | return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t)); | |
241 | } | |
242 | ||
243 | ClassImp(AliSimpleValue) | |
244 | ||
245 | AliSimpleValue::AliSimpleValue(): | |
246 | fHolder(NULL), fType(kInvalid) | |
247 | { | |
248 | ||
249 | } | |
250 | ||
251 | AliSimpleValue::AliSimpleValue(const AliSimpleValue& other): | |
252 | TObject(other), fHolder(NULL), fType(other.fType) | |
253 | { | |
254 | if (other.fHolder) { | |
255 | fHolder = other.fHolder->Clone(); | |
256 | } | |
257 | } | |
258 | ||
259 | AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size): | |
260 | fHolder(NULL), fType(type) | |
261 | { | |
262 | ||
263 | switch (type) { | |
264 | case kBool: | |
265 | fHolder = new BoolHolder(); | |
266 | break; | |
267 | case kByte: | |
268 | fHolder = new ByteHolder(); | |
269 | break; | |
270 | case kInt: | |
271 | fHolder = new IntHolder(); | |
272 | break; | |
273 | case kUInt: | |
274 | fHolder = new UIntHolder(); | |
275 | break; | |
276 | case kFloat: | |
277 | fHolder = new FloatHolder(); | |
278 | break; | |
279 | case kDynBool: | |
280 | fHolder = new DynBoolHolder(size); | |
281 | break; | |
282 | case kDynByte: | |
283 | fHolder = new DynByteHolder(size); | |
284 | break; | |
285 | case kDynInt: | |
286 | fHolder = new DynIntHolder(size); | |
287 | break; | |
288 | case kDynUInt: | |
289 | fHolder = new DynUIntHolder(size); | |
290 | break; | |
291 | case kDynFloat: | |
292 | fHolder = new DynFloatHolder(size); | |
293 | break; | |
294 | default: | |
295 | break; | |
296 | } | |
297 | } | |
298 | ||
299 | AliSimpleValue::AliSimpleValue(Bool_t val) { | |
300 | ||
301 | fType = kBool; | |
302 | fHolder = new BoolHolder(val); | |
303 | } | |
304 | ||
305 | AliSimpleValue::AliSimpleValue(Char_t val) { | |
306 | ||
307 | fType = kByte; | |
308 | fHolder = new ByteHolder(val); | |
309 | } | |
310 | ||
311 | AliSimpleValue::AliSimpleValue(Int_t val) { | |
312 | ||
313 | fType = kInt; | |
314 | fHolder = new IntHolder(val); | |
315 | } | |
316 | ||
317 | AliSimpleValue::AliSimpleValue(UInt_t val) { | |
318 | ||
319 | fType = kUInt; | |
320 | fHolder = new UIntHolder(val); | |
321 | } | |
322 | ||
323 | AliSimpleValue::AliSimpleValue(Float_t val) { | |
324 | ||
325 | fType = kFloat; | |
326 | fHolder = new FloatHolder(val); | |
327 | } | |
328 | ||
329 | AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) { | |
330 | ||
331 | fType = kDynBool; | |
332 | fHolder = new DynBoolHolder(size, buf); | |
333 | } | |
334 | ||
335 | AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) { | |
336 | ||
337 | fType = kDynByte; | |
338 | fHolder = new DynByteHolder(size, buf); | |
339 | } | |
340 | ||
341 | AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) { | |
342 | ||
343 | fType = kDynInt; | |
344 | fHolder = new DynIntHolder(size, buf); | |
345 | } | |
346 | ||
347 | AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) { | |
348 | ||
349 | fType = kDynUInt; | |
350 | fHolder = new DynUIntHolder(size, buf); | |
351 | } | |
352 | ||
353 | AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) { | |
354 | ||
355 | fType = kDynFloat; | |
356 | fHolder = new DynFloatHolder(size, buf); | |
357 | } | |
358 | ||
359 | AliSimpleValue::~AliSimpleValue() { | |
360 | ||
361 | if (fHolder) { | |
362 | delete fHolder; | |
363 | } | |
364 | } | |
365 | ||
366 | AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) { | |
367 | ||
368 | if (fHolder) { | |
369 | delete fHolder; | |
370 | } | |
371 | ||
372 | fType = other.fType; | |
373 | ||
374 | if (other.fHolder) { | |
375 | fHolder = other.fHolder->Clone(); | |
376 | } else { | |
377 | fHolder = NULL; | |
378 | } | |
379 | ||
380 | return *this; | |
381 | } | |
382 | ||
383 | Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const { | |
384 | ||
385 | if (fType != other.fType) { | |
386 | return kFALSE; | |
387 | } | |
388 | ||
389 | if (!(fHolder && other.fHolder)) { | |
390 | return kFALSE; | |
391 | } | |
392 | ||
393 | return fHolder->IsEqual(other.fHolder); | |
394 | } | |
395 | ||
396 | void AliSimpleValue::SetBool(Bool_t val) { | |
397 | ||
398 | if (!TypeOk(kBool)) { | |
399 | return; | |
400 | } | |
401 | ||
402 | ((BoolHolder*) fHolder)->fValue = val; | |
403 | } | |
404 | ||
405 | void AliSimpleValue::SetByte(Char_t val) { | |
406 | ||
407 | if (!TypeOk(kByte)) { | |
408 | return; | |
409 | } | |
410 | ||
411 | ((ByteHolder*) fHolder)->fValue = val; | |
412 | } | |
413 | ||
414 | void AliSimpleValue::SetInt(Int_t val) { | |
415 | ||
416 | if (!TypeOk(kInt)) { | |
417 | return; | |
418 | } | |
419 | ||
420 | ((IntHolder*) fHolder)->fValue = val; | |
421 | } | |
422 | ||
423 | void AliSimpleValue::SetUInt(UInt_t val) { | |
424 | ||
425 | if (!TypeOk(kUInt)) { | |
426 | return; | |
427 | } | |
428 | ||
429 | ((UIntHolder*) fHolder)->fValue = val; | |
430 | } | |
431 | ||
432 | void AliSimpleValue::SetFloat(Float_t val) { | |
433 | ||
434 | if (!TypeOk(kFloat)) { | |
435 | return; | |
436 | } | |
437 | ||
438 | ((FloatHolder*) fHolder)->fValue = val; | |
439 | } | |
440 | ||
441 | Bool_t AliSimpleValue::GetBool() const { | |
442 | ||
443 | if (!TypeOk(kBool)) { | |
444 | return kFALSE; | |
445 | } | |
446 | ||
447 | return ((BoolHolder*) fHolder)->fValue; | |
448 | } | |
449 | ||
450 | Char_t AliSimpleValue::GetByte() const { | |
451 | ||
452 | if (!TypeOk(kByte)) { | |
453 | return 0; | |
454 | } | |
455 | ||
456 | return ((ByteHolder*) fHolder)->fValue; | |
457 | } | |
458 | ||
459 | Int_t AliSimpleValue::GetInt() const { | |
460 | ||
461 | if (!TypeOk(kInt)) { | |
462 | return 0; | |
463 | } | |
464 | return ((IntHolder*) fHolder)->fValue; | |
465 | } | |
466 | ||
467 | UInt_t AliSimpleValue::GetUInt() const { | |
468 | ||
469 | if (!TypeOk(kUInt)) { | |
470 | return 0; | |
471 | } | |
472 | ||
473 | return ((UIntHolder*) fHolder)->fValue; | |
474 | } | |
475 | ||
476 | Float_t AliSimpleValue::GetFloat() const { | |
477 | ||
478 | if (!TypeOk(kFloat)) { | |
479 | return 0; | |
480 | } | |
481 | ||
482 | return ((FloatHolder*) fHolder)->fValue; | |
483 | } | |
484 | ||
485 | void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) { | |
486 | ||
487 | if (!TypeOk(kDynBool)) { | |
488 | return; | |
489 | } | |
490 | ||
491 | if (!BoundsOk(n)) { | |
492 | return; | |
493 | } | |
494 | ||
495 | ((DynBoolHolder*) fHolder)->fValues[n] = val; | |
496 | } | |
497 | ||
498 | void AliSimpleValue::SetDynByte(Int_t n, Char_t val) { | |
499 | ||
500 | if (!TypeOk(kDynByte)) { | |
501 | return; | |
502 | } | |
503 | ||
504 | if (!BoundsOk(n)) { | |
505 | return; | |
506 | } | |
507 | ||
508 | ((DynByteHolder*) fHolder)->fValues[n] = val; | |
509 | } | |
510 | ||
511 | void AliSimpleValue::SetDynInt(Int_t n, Int_t val) { | |
512 | ||
513 | if (!TypeOk(kDynInt)) { | |
514 | return; | |
515 | } | |
516 | ||
517 | if (!BoundsOk(n)) { | |
518 | return; | |
519 | } | |
520 | ||
521 | ((DynIntHolder*) fHolder)->fValues[n] = val; | |
522 | } | |
523 | ||
524 | void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) { | |
525 | ||
526 | if (!TypeOk(kDynUInt)) { | |
527 | return; | |
528 | } | |
529 | ||
530 | if (!BoundsOk(n)) { | |
531 | return; | |
532 | } | |
533 | ||
534 | ((DynUIntHolder*) fHolder)->fValues[n] = val; | |
535 | } | |
536 | ||
537 | void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) { | |
538 | ||
539 | if (!TypeOk(kDynFloat)) { | |
540 | return; | |
541 | } | |
542 | ||
543 | if (!BoundsOk(n)) { | |
544 | return; | |
545 | } | |
546 | ||
547 | ((DynFloatHolder*) fHolder)->fValues[n] = val; | |
548 | } | |
549 | ||
550 | Bool_t AliSimpleValue::GetDynBool(Int_t n) const { | |
551 | ||
552 | if (!TypeOk(kDynBool)) { | |
553 | return kFALSE; | |
554 | } | |
555 | ||
556 | if (!BoundsOk(n)) { | |
557 | return kFALSE; | |
558 | } | |
559 | ||
560 | return ((DynBoolHolder*) fHolder)->fValues[n]; | |
561 | } | |
562 | ||
563 | Char_t AliSimpleValue::GetDynByte(Int_t n) const { | |
564 | ||
565 | if (!TypeOk(kDynByte)) { | |
566 | return 0; | |
567 | } | |
568 | ||
569 | if (!BoundsOk(n)) { | |
570 | return 0; | |
571 | } | |
572 | ||
573 | return ((DynByteHolder*) fHolder)->fValues[n]; | |
574 | } | |
575 | ||
576 | Int_t AliSimpleValue::GetDynInt(Int_t n) const { | |
577 | ||
578 | if (!TypeOk(kDynInt)) { | |
579 | return 0; | |
580 | } | |
581 | ||
582 | if (!BoundsOk(n)) { | |
583 | return 0; | |
584 | } | |
585 | ||
586 | return ((DynIntHolder*) fHolder)->fValues[n]; | |
587 | } | |
588 | ||
589 | UInt_t AliSimpleValue::GetDynUInt(Int_t n) const { | |
590 | ||
591 | if (!TypeOk(kDynUInt)) { | |
592 | return 0; | |
593 | } | |
594 | ||
595 | if (!BoundsOk(n)) { | |
596 | return 0; | |
597 | } | |
598 | ||
599 | return ((DynUIntHolder*) fHolder)->fValues[n]; | |
600 | } | |
601 | ||
602 | Float_t AliSimpleValue::GetDynFloat(Int_t n) const { | |
603 | ||
604 | if (!TypeOk(kDynFloat)) { | |
605 | return 0; | |
606 | } | |
607 | ||
608 | if (!BoundsOk(n)) { | |
609 | return 0; | |
610 | } | |
611 | ||
612 | return ((DynFloatHolder*) fHolder)->fValues[n]; | |
613 | } | |
614 | ||
615 | Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const { | |
616 | ||
617 | if (fType != type) { | |
618 | AliError(Form("SimpleValue type is not %s!", | |
619 | GetTypeString(type))); | |
620 | return kFALSE; | |
621 | } | |
622 | ||
623 | return kTRUE; | |
624 | } | |
625 | ||
626 | Bool_t AliSimpleValue::BoundsOk(Int_t n) const { | |
627 | ||
628 | switch (fType) { | |
629 | case kDynBool: | |
630 | case kDynByte: | |
631 | case kDynInt: | |
632 | case kDynUInt: | |
633 | case kDynFloat: { | |
634 | Int_t size = ((DynHolder*) fHolder)->fSize; | |
635 | if (n < 0 || n >= size) { | |
636 | AliError(Form("Index %d out of bounds!", n)); | |
637 | return kFALSE; | |
638 | } | |
639 | return kTRUE; | |
640 | } | |
641 | case kBool: | |
642 | case kByte: | |
643 | case kInt: | |
644 | case kUInt: | |
645 | case kFloat: | |
646 | AliError(Form("SimpleValue type %s is not dynamic!", | |
647 | GetTypeString(fType))); | |
648 | return kFALSE; | |
649 | default: | |
650 | AliError("Invalid or unknown type!"); | |
651 | return kFALSE; | |
652 | } | |
653 | } | |
654 | ||
655 | Int_t AliSimpleValue::GetDynamicSize() const { | |
656 | // | |
657 | // returns the size of dynamic type or 0 in case of | |
658 | // none dynamic type. | |
659 | // | |
660 | ||
661 | if (!fHolder) { | |
662 | return 0; | |
663 | } | |
664 | ||
665 | if (!fHolder->IsA()->InheritsFrom(DynHolder::Class())) { | |
666 | return 0; | |
667 | } | |
668 | ||
669 | return ((DynHolder*) fHolder)->fSize; | |
670 | } | |
671 | ||
672 | TString AliSimpleValue::ToString() const { | |
673 | ||
674 | TString result; | |
675 | ||
676 | result += "Type: "; | |
677 | result += GetTypeString(fType); | |
678 | ||
679 | result += ", Value: "; | |
680 | switch (fType) { | |
681 | case kBool: | |
682 | result += GetBool(); | |
683 | break; | |
684 | case kByte: | |
685 | result += (Int_t) GetByte(); | |
686 | break; | |
687 | case kInt: | |
688 | result += GetInt(); | |
689 | break; | |
690 | case kUInt: | |
691 | result += GetUInt(); | |
692 | break; | |
693 | case kFloat: | |
694 | result += GetFloat(); | |
695 | break; | |
696 | case kDynBool: { | |
697 | result += "["; | |
698 | Int_t size = GetDynamicSize(); | |
699 | for (Int_t k = 0; k < size; k ++) { | |
700 | result += GetDynBool(k); | |
701 | if (k + 1 < size) { | |
702 | result += ", "; | |
703 | } | |
704 | } | |
705 | result += "]"; | |
706 | } | |
707 | break; | |
708 | case kDynByte: { | |
709 | result += "["; | |
710 | Int_t size = GetDynamicSize(); | |
711 | for (Int_t k = 0; k < size; k ++) { | |
712 | result += GetDynByte(k); | |
713 | if (k + 1 < size) { | |
714 | result += ", "; | |
715 | } | |
716 | } | |
717 | result += "]"; | |
718 | } | |
719 | break; | |
720 | case kDynInt: { | |
721 | result += "["; | |
722 | Int_t size = GetDynamicSize(); | |
723 | for (Int_t k = 0; k < size; k ++) { | |
724 | result += GetDynInt(k); | |
725 | if (k + 1 < size) { | |
726 | result += ", "; | |
727 | } | |
728 | } | |
729 | result += "]"; | |
730 | } | |
731 | break; | |
732 | case kDynUInt: { | |
733 | result += "["; | |
734 | Int_t size = GetDynamicSize(); | |
735 | for (Int_t k = 0; k < size; k ++) { | |
736 | result += GetDynUInt(k); | |
737 | if (k + 1 < size) { | |
738 | result += ", "; | |
739 | } | |
740 | } | |
741 | result += "]"; | |
742 | } | |
743 | break; | |
744 | case kDynFloat: { | |
745 | result += "["; | |
746 | Int_t size = GetDynamicSize(); | |
747 | for (Int_t k = 0; k < size; k ++) { | |
748 | result += GetDynFloat(k); | |
749 | if (k + 1 < size) { | |
750 | result += ", "; | |
751 | } | |
752 | } | |
753 | result += "]"; | |
754 | } | |
755 | break; | |
756 | default: | |
757 | result += "Unknown"; | |
758 | } | |
759 | ||
760 | return result; | |
761 | } | |
762 | ||
763 | Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) { | |
764 | ||
765 | switch (type) { | |
766 | case kDynBool: | |
767 | case kDynByte: | |
768 | case kDynInt: | |
769 | case kDynUInt: | |
770 | case kDynFloat: | |
771 | return kTRUE; | |
772 | default: | |
773 | return kFALSE; | |
774 | } | |
775 | } | |
776 | ||
777 | Int_t AliSimpleValue::GetSize() const { | |
778 | // | |
779 | // return the number of bytes used by this value. | |
780 | // In case of dynamic type it returns dynamic size multiplied | |
781 | // by the size of corresponding primitive type. | |
782 | // | |
783 | ||
784 | return IsDynamic(fType) ? | |
785 | GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType): | |
786 | AliSimpleValue::GetPrimitiveSize(fType); | |
787 | } | |
788 | ||
789 | Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) { | |
790 | // | |
791 | // returns the number of bytes used by particular primitive type | |
792 | // or by the corresponding primitive type in case of dynamic type. | |
793 | // | |
794 | ||
795 | ||
796 | switch (type) { | |
797 | ||
798 | case kBool: | |
799 | case kDynBool: return sizeof(Bool_t); | |
800 | case kByte: | |
801 | case kDynByte: return sizeof(Char_t); | |
802 | case kInt: | |
803 | case kDynInt: return sizeof(Int_t); | |
804 | case kUInt: | |
805 | case kDynUInt: return sizeof(UInt_t); | |
806 | case kFloat: | |
807 | case kDynFloat: return sizeof(Float_t); | |
808 | default: | |
809 | return 0; | |
810 | } | |
811 | } | |
812 | ||
813 | const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type type) { | |
814 | ||
815 | switch (type) { | |
816 | case kBool: return "Bool"; | |
817 | case kByte: return "Byte"; | |
818 | case kInt: return "Int"; | |
819 | case kUInt: return "UInt"; | |
820 | case kFloat: return "Float"; | |
821 | case kDynBool: return "DynBool"; | |
822 | case kDynByte: return "DynByte"; | |
823 | case kDynInt: return "DynInt"; | |
824 | case kDynUInt: return "DynUInt"; | |
825 | case kDynFloat: return "DynFloat"; | |
826 | default: | |
827 | return "Unknown"; | |
828 | } | |
829 | } |