1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.1 2006/06/02 14:14:36 hristov
19 Separate library for CDB (Jan)
21 Revision 1.2 2006/03/07 07:52:34 hristov
22 New version (B.Yordanov)
24 Revision 1.2 2005/11/17 14:43:23 byordano
27 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
28 Initial import as subdirectory in AliRoot
30 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
33 Revision 1.2 2005/08/30 10:53:23 byordano
34 some more descriptions added
39 // This class is a simple wrapper of
40 // all primitive types used in PVSS SCADA system.
44 #include "AliSimpleValue.h"
49 //______________________________________________________________________
50 TObject* AliSimpleValue::AliBoolHolder::Clone(const char* /*name*/) const {
51 return new AliBoolHolder(fValue);
56 //______________________________________________________________________
57 Bool_t AliSimpleValue::AliBoolHolder::IsEqual(const TObject* obj) const {
58 // check whether this is equal to obj
64 if (AliBoolHolder::Class() != obj->IsA()) {
68 return fValue == ((const AliBoolHolder*) obj)->fValue;
71 //______________________________________________________________________
72 TObject* AliSimpleValue::AliByteHolder::Clone(const char* /*name*/) const {
75 return new AliByteHolder(fValue);
78 //______________________________________________________________________
79 Bool_t AliSimpleValue::AliByteHolder::IsEqual(const TObject* obj) const {
80 // check whether this is equal to obj
86 if (AliByteHolder::Class() != obj->IsA()) {
90 return fValue == ((const AliByteHolder*) obj)->fValue;
93 //______________________________________________________________________
94 TObject* AliSimpleValue::AliIntHolder::Clone(const char* /*name*/) const {
96 return new AliIntHolder(fValue);
99 //______________________________________________________________________
100 Bool_t AliSimpleValue::AliIntHolder::IsEqual(const TObject* obj) const {
101 // check whether this is equal to obj
107 if (AliIntHolder::Class() != obj->IsA()) {
111 return fValue == ((const AliIntHolder*) obj)->fValue;
114 //______________________________________________________________________
115 TObject* AliSimpleValue::AliUIntHolder::Clone(const char* /*name*/) const {
117 return new AliUIntHolder(fValue);
120 //______________________________________________________________________
121 Bool_t AliSimpleValue::AliUIntHolder::IsEqual(const TObject* obj) const {
122 // check whether this is equal to obj
128 if (AliUIntHolder::Class() != obj->IsA()) {
132 return fValue == ((const AliUIntHolder*) obj)->fValue;
135 //______________________________________________________________________
136 TObject* AliSimpleValue::AliFloatHolder::Clone(const char* /*name*/) const {
138 return new AliFloatHolder(fValue);
141 //______________________________________________________________________
142 Bool_t AliSimpleValue::AliFloatHolder::IsEqual(const TObject* obj) const {
143 // check whether this is equal to obj
149 if (AliFloatHolder::Class() != obj->IsA()) {
153 return fValue == ((const AliFloatHolder*) obj)->fValue;
156 //______________________________________________________________________
157 TObject* AliSimpleValue::AliDynBoolHolder::Clone(const char* /*name*/) const {
159 return new AliDynBoolHolder(fSize, fValues);
162 //______________________________________________________________________
163 Bool_t AliSimpleValue::AliDynBoolHolder::IsEqual(const TObject* obj) const {
164 // check whether this is equal to obj
170 if (AliDynBoolHolder::Class() != obj->IsA()) {
174 const AliDynBoolHolder* other = ((const AliDynBoolHolder*) obj);
176 if (fSize != other->fSize) {
180 return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t));
183 //______________________________________________________________________
184 TObject* AliSimpleValue::AliDynByteHolder::Clone(const char* /*name*/) const {
186 return new AliDynByteHolder(fSize, fValues);
189 //______________________________________________________________________
190 Bool_t AliSimpleValue::AliDynByteHolder::IsEqual(const TObject* obj) const {
191 // check whether this is equal to obj
197 if (AliDynByteHolder::Class() != obj->IsA()) {
201 const AliDynByteHolder* other = ((const AliDynByteHolder*) obj);
203 if (fSize != other->fSize) {
207 return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t));
210 //______________________________________________________________________
211 TObject* AliSimpleValue::AliDynIntHolder::Clone(const char* /*name*/) const {
213 return new AliDynIntHolder(fSize, fValues);
216 //______________________________________________________________________
217 Bool_t AliSimpleValue::AliDynIntHolder::IsEqual(const TObject* obj) const {
218 // check whether this is equal to obj
224 if (AliDynIntHolder::Class() != obj->IsA()) {
228 const AliDynIntHolder* other = ((const AliDynIntHolder*) obj);
230 if (fSize != other->fSize) {
234 return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t));
237 //______________________________________________________________________
238 TObject* AliSimpleValue::AliDynUIntHolder::Clone(const char* /*name*/) const {
240 return new AliDynUIntHolder(fSize, fValues);
243 //______________________________________________________________________
244 Bool_t AliSimpleValue::AliDynUIntHolder::IsEqual(const TObject* obj) const {
245 // check whether this is equal to obj
251 if (AliDynUIntHolder::Class() != obj->IsA()) {
255 const AliDynUIntHolder* other = ((const AliDynUIntHolder*) obj);
257 if (fSize != other->fSize) {
261 return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t));
264 //______________________________________________________________________
265 TObject* AliSimpleValue::AliDynFloatHolder::Clone(const char* /*name*/) const {
266 return new AliDynFloatHolder(fSize, fValues);
269 //______________________________________________________________________
270 Bool_t AliSimpleValue::AliDynFloatHolder::IsEqual(const TObject* obj) const {
271 // check whether this is equal to obj
277 if (AliDynFloatHolder::Class() != obj->IsA()) {
281 const AliDynFloatHolder* other = ((const AliDynFloatHolder*) obj);
283 if (fSize != other->fSize) {
287 return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t));
290 //______________________________________________________________________
291 //______________________________________________________________________
293 ClassImp(AliSimpleValue)
295 //______________________________________________________________________
296 AliSimpleValue::AliSimpleValue():
297 fHolder(NULL), fType(kInvalid)
302 //______________________________________________________________________
303 AliSimpleValue::AliSimpleValue(const AliSimpleValue& other):
304 TObject(other), fHolder(NULL), fType(other.fType)
308 fHolder = other.fHolder->Clone();
312 //______________________________________________________________________
313 AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size):
314 fHolder(NULL), fType(type)
320 fHolder = new AliBoolHolder();
323 fHolder = new AliByteHolder();
326 fHolder = new AliIntHolder();
329 fHolder = new AliUIntHolder();
332 fHolder = new AliFloatHolder();
335 fHolder = new AliDynBoolHolder(size);
338 fHolder = new AliDynByteHolder(size);
341 fHolder = new AliDynIntHolder(size);
344 fHolder = new AliDynUIntHolder(size);
347 fHolder = new AliDynFloatHolder(size);
354 //______________________________________________________________________
355 AliSimpleValue::AliSimpleValue(Bool_t val) {
359 fHolder = new AliBoolHolder(val);
362 //______________________________________________________________________
363 AliSimpleValue::AliSimpleValue(Char_t val) {
367 fHolder = new AliByteHolder(val);
370 //______________________________________________________________________
371 AliSimpleValue::AliSimpleValue(Int_t val) {
375 fHolder = new AliIntHolder(val);
378 //______________________________________________________________________
379 AliSimpleValue::AliSimpleValue(UInt_t val) {
383 fHolder = new AliUIntHolder(val);
386 //______________________________________________________________________
387 AliSimpleValue::AliSimpleValue(Float_t val) {
391 fHolder = new AliFloatHolder(val);
394 //______________________________________________________________________
395 AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) {
399 fHolder = new AliDynBoolHolder(size, buf);
402 //______________________________________________________________________
403 AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) {
407 fHolder = new AliDynByteHolder(size, buf);
410 //______________________________________________________________________
411 AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) {
415 fHolder = new AliDynIntHolder(size, buf);
418 //______________________________________________________________________
419 AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) {
423 fHolder = new AliDynUIntHolder(size, buf);
426 //______________________________________________________________________
427 AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) {
431 fHolder = new AliDynFloatHolder(size, buf);
434 //______________________________________________________________________
435 AliSimpleValue::~AliSimpleValue() {
443 //______________________________________________________________________
444 AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) {
454 fHolder = other.fHolder->Clone();
462 //______________________________________________________________________
463 Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const {
466 if (fType != other.fType) {
470 if (!(fHolder && other.fHolder)) {
474 return fHolder->IsEqual(other.fHolder);
477 //______________________________________________________________________
478 void AliSimpleValue::SetBool(Bool_t val) {
481 if (!TypeOk(kBool)) {
485 ((AliBoolHolder*) fHolder)->fValue = val;
488 //______________________________________________________________________
489 void AliSimpleValue::SetByte(Char_t val) {
492 if (!TypeOk(kByte)) {
496 ((AliByteHolder*) fHolder)->fValue = val;
499 //______________________________________________________________________
500 void AliSimpleValue::SetInt(Int_t val) {
507 ((AliIntHolder*) fHolder)->fValue = val;
510 //______________________________________________________________________
511 void AliSimpleValue::SetUInt(UInt_t val) {
514 if (!TypeOk(kUInt)) {
518 ((AliUIntHolder*) fHolder)->fValue = val;
521 //______________________________________________________________________
522 void AliSimpleValue::SetFloat(Float_t val) {
525 if (!TypeOk(kFloat)) {
529 ((AliFloatHolder*) fHolder)->fValue = val;
532 //______________________________________________________________________
533 Bool_t AliSimpleValue::GetBool() const {
536 if (!TypeOk(kBool)) {
540 return ((AliBoolHolder*) fHolder)->fValue;
543 //______________________________________________________________________
544 Char_t AliSimpleValue::GetByte() const {
547 if (!TypeOk(kByte)) {
551 return ((AliByteHolder*) fHolder)->fValue;
554 //______________________________________________________________________
555 Int_t AliSimpleValue::GetInt() const {
561 return ((AliIntHolder*) fHolder)->fValue;
564 //______________________________________________________________________
565 UInt_t AliSimpleValue::GetUInt() const {
568 if (!TypeOk(kUInt)) {
572 return ((AliUIntHolder*) fHolder)->fValue;
575 //______________________________________________________________________
576 Float_t AliSimpleValue::GetFloat() const {
579 if (!TypeOk(kFloat)) {
583 return ((AliFloatHolder*) fHolder)->fValue;
586 //______________________________________________________________________
587 void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) {
590 if (!TypeOk(kDynBool)) {
598 ((AliDynBoolHolder*) fHolder)->fValues[n] = val;
601 //______________________________________________________________________
602 void AliSimpleValue::SetDynByte(Int_t n, Char_t val) {
605 if (!TypeOk(kDynByte)) {
613 ((AliDynByteHolder*) fHolder)->fValues[n] = val;
616 //______________________________________________________________________
617 void AliSimpleValue::SetDynInt(Int_t n, Int_t val) {
620 if (!TypeOk(kDynInt)) {
628 ((AliDynIntHolder*) fHolder)->fValues[n] = val;
631 //______________________________________________________________________
632 void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) {
635 if (!TypeOk(kDynUInt)) {
643 ((AliDynUIntHolder*) fHolder)->fValues[n] = val;
646 //______________________________________________________________________
647 void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) {
650 if (!TypeOk(kDynFloat)) {
658 ((AliDynFloatHolder*) fHolder)->fValues[n] = val;
661 //______________________________________________________________________
662 Bool_t AliSimpleValue::GetDynBool(Int_t n) const {
665 if (!TypeOk(kDynBool)) {
673 return ((AliDynBoolHolder*) fHolder)->fValues[n];
676 //______________________________________________________________________
677 Char_t AliSimpleValue::GetDynByte(Int_t n) const {
680 if (!TypeOk(kDynByte)) {
688 return ((AliDynByteHolder*) fHolder)->fValues[n];
691 //______________________________________________________________________
692 Int_t AliSimpleValue::GetDynInt(Int_t n) const {
695 if (!TypeOk(kDynInt)) {
703 return ((AliDynIntHolder*) fHolder)->fValues[n];
706 //______________________________________________________________________
707 UInt_t AliSimpleValue::GetDynUInt(Int_t n) const {
710 if (!TypeOk(kDynUInt)) {
718 return ((AliDynUIntHolder*) fHolder)->fValues[n];
721 //______________________________________________________________________
722 Float_t AliSimpleValue::GetDynFloat(Int_t n) const {
725 if (!TypeOk(kDynFloat)) {
733 return ((AliDynFloatHolder*) fHolder)->fValues[n];
736 //______________________________________________________________________
737 Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const {
738 // check that AliSimpleValue is of type type
741 AliError(Form("SimpleValue type is not %s!",
742 GetTypeString(type)));
749 //______________________________________________________________________
750 Bool_t AliSimpleValue::BoundsOk(Int_t n) const {
751 // Check that n is within bounds of dyn value
759 Int_t size = ((AliDynHolder*) fHolder)->fSize;
760 if (n < 0 || n >= size) {
761 AliError(Form("Index %d out of bounds!", n));
771 AliError(Form("SimpleValue type %s is not dynamic!",
772 GetTypeString(fType)));
775 AliError("Invalid or unknown type!");
780 //______________________________________________________________________
781 Int_t AliSimpleValue::GetDynamicSize() const {
783 // returns the size of dynamic type or 0 in case of
784 // none dynamic type.
791 if (!fHolder->IsA()->InheritsFrom(AliDynHolder::Class())) {
795 return ((AliDynHolder*) fHolder)->fSize;
798 //______________________________________________________________________
799 TString AliSimpleValue::ToString() const {
805 result += GetTypeString(fType);
807 result += ", Value: ";
813 result += (Int_t) GetByte();
822 result += GetFloat();
826 Int_t size = GetDynamicSize();
827 for (Int_t k = 0; k < size; k ++) {
828 result += GetDynBool(k);
838 Int_t size = GetDynamicSize();
839 for (Int_t k = 0; k < size; k ++) {
840 result += GetDynByte(k);
850 Int_t size = GetDynamicSize();
851 for (Int_t k = 0; k < size; k ++) {
852 result += GetDynInt(k);
862 Int_t size = GetDynamicSize();
863 for (Int_t k = 0; k < size; k ++) {
864 result += GetDynUInt(k);
874 Int_t size = GetDynamicSize();
875 for (Int_t k = 0; k < size; k ++) {
876 result += GetDynFloat(k);
891 //______________________________________________________________________
892 Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) {
893 // check that type is dynamic
907 //______________________________________________________________________
908 Int_t AliSimpleValue::GetSize() const {
910 // return the number of bytes used by this value.
911 // In case of dynamic type it returns dynamic size multiplied
912 // by the size of corresponding primitive type.
915 return IsDynamic(fType) ?
916 GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType):
917 AliSimpleValue::GetPrimitiveSize(fType);
920 //______________________________________________________________________
921 Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) {
923 // returns the number of bytes used by particular primitive type
924 // or by the corresponding primitive type in case of dynamic type.
931 case kDynBool: return sizeof(Bool_t);
933 case kDynByte: return sizeof(Char_t);
935 case kDynInt: return sizeof(Int_t);
937 case kDynUInt: return sizeof(UInt_t);
939 case kDynFloat: return sizeof(Float_t);
945 //______________________________________________________________________
946 const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type type) {
947 // return type name correspondyng to type
950 case kBool: return "Bool";
951 case kByte: return "Byte";
952 case kInt: return "Int";
953 case kUInt: return "UInt";
954 case kFloat: return "Float";
955 case kDynBool: return "DynBool";
956 case kDynByte: return "DynByte";
957 case kDynInt: return "DynInt";
958 case kDynUInt: return "DynUInt";
959 case kDynFloat: return "DynFloat";