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.1.1 2005/09/12 22:11:40 byordano
21 Revision 1.2 2005/08/30 10:53:23 byordano
22 some more descriptions added
27 // This class is a simple wrapper of
28 // all primitive types used in PVSS SCADA system.
32 #include "AliSimpleValue.h"
37 TObject* AliSimpleValue::BoolHolder::Clone(const char* /*name*/) const {
38 return new BoolHolder(fValue);
41 Bool_t AliSimpleValue::BoolHolder::IsEqual(const TObject* obj) const {
47 if (BoolHolder::Class() != obj->IsA()) {
51 return fValue == ((const BoolHolder*) obj)->fValue;
54 TObject* AliSimpleValue::ByteHolder::Clone(const char* /*name*/) const {
55 return new ByteHolder(fValue);
58 Bool_t AliSimpleValue::ByteHolder::IsEqual(const TObject* obj) const {
64 if (ByteHolder::Class() != obj->IsA()) {
68 return fValue == ((const ByteHolder*) obj)->fValue;
71 TObject* AliSimpleValue::IntHolder::Clone(const char* /*name*/) const {
72 return new IntHolder(fValue);
75 Bool_t AliSimpleValue::IntHolder::IsEqual(const TObject* obj) const {
81 if (IntHolder::Class() != obj->IsA()) {
85 return fValue == ((const IntHolder*) obj)->fValue;
88 TObject* AliSimpleValue::UIntHolder::Clone(const char* /*name*/) const {
89 return new UIntHolder(fValue);
92 Bool_t AliSimpleValue::UIntHolder::IsEqual(const TObject* obj) const {
98 if (UIntHolder::Class() != obj->IsA()) {
102 return fValue == ((const UIntHolder*) obj)->fValue;
105 TObject* AliSimpleValue::FloatHolder::Clone(const char* /*name*/) const {
106 return new FloatHolder(fValue);
109 Bool_t AliSimpleValue::FloatHolder::IsEqual(const TObject* obj) const {
115 if (FloatHolder::Class() != obj->IsA()) {
119 return fValue == ((const FloatHolder*) obj)->fValue;
122 TObject* AliSimpleValue::DynBoolHolder::Clone(const char* /*name*/) const {
123 return new DynBoolHolder(fSize, fValues);
126 Bool_t AliSimpleValue::DynBoolHolder::IsEqual(const TObject* obj) const {
132 if (DynBoolHolder::Class() != obj->IsA()) {
136 const DynBoolHolder* other = ((const DynBoolHolder*) obj);
138 if (fSize != other->fSize) {
142 return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t));
145 TObject* AliSimpleValue::DynByteHolder::Clone(const char* /*name*/) const {
146 return new DynByteHolder(fSize, fValues);
149 Bool_t AliSimpleValue::DynByteHolder::IsEqual(const TObject* obj) const {
155 if (DynByteHolder::Class() != obj->IsA()) {
159 const DynByteHolder* other = ((const DynByteHolder*) obj);
161 if (fSize != other->fSize) {
165 return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t));
168 TObject* AliSimpleValue::DynIntHolder::Clone(const char* /*name*/) const {
169 return new DynIntHolder(fSize, fValues);
172 Bool_t AliSimpleValue::DynIntHolder::IsEqual(const TObject* obj) const {
178 if (DynIntHolder::Class() != obj->IsA()) {
182 const DynIntHolder* other = ((const DynIntHolder*) obj);
184 if (fSize != other->fSize) {
188 return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t));
191 TObject* AliSimpleValue::DynUIntHolder::Clone(const char* /*name*/) const {
192 return new DynUIntHolder(fSize, fValues);
195 Bool_t AliSimpleValue::DynUIntHolder::IsEqual(const TObject* obj) const {
201 if (DynUIntHolder::Class() != obj->IsA()) {
205 const DynUIntHolder* other = ((const DynUIntHolder*) obj);
207 if (fSize != other->fSize) {
211 return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t));
214 TObject* AliSimpleValue::DynFloatHolder::Clone(const char* /*name*/) const {
215 return new DynFloatHolder(fSize, fValues);
218 Bool_t AliSimpleValue::DynFloatHolder::IsEqual(const TObject* obj) const {
224 if (DynFloatHolder::Class() != obj->IsA()) {
228 const DynFloatHolder* other = ((const DynFloatHolder*) obj);
230 if (fSize != other->fSize) {
234 return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t));
237 ClassImp(AliSimpleValue)
239 AliSimpleValue::AliSimpleValue():
240 fHolder(NULL), fType(kInvalid)
245 AliSimpleValue::AliSimpleValue(const AliSimpleValue& other):
246 TObject(other), fHolder(NULL), fType(other.fType)
249 fHolder = other.fHolder->Clone();
253 AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size):
254 fHolder(NULL), fType(type)
259 fHolder = new BoolHolder();
262 fHolder = new ByteHolder();
265 fHolder = new IntHolder();
268 fHolder = new UIntHolder();
271 fHolder = new FloatHolder();
274 fHolder = new DynBoolHolder(size);
277 fHolder = new DynByteHolder(size);
280 fHolder = new DynIntHolder(size);
283 fHolder = new DynUIntHolder(size);
286 fHolder = new DynFloatHolder(size);
293 AliSimpleValue::AliSimpleValue(Bool_t val) {
296 fHolder = new BoolHolder(val);
299 AliSimpleValue::AliSimpleValue(Char_t val) {
302 fHolder = new ByteHolder(val);
305 AliSimpleValue::AliSimpleValue(Int_t val) {
308 fHolder = new IntHolder(val);
311 AliSimpleValue::AliSimpleValue(UInt_t val) {
314 fHolder = new UIntHolder(val);
317 AliSimpleValue::AliSimpleValue(Float_t val) {
320 fHolder = new FloatHolder(val);
323 AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) {
326 fHolder = new DynBoolHolder(size, buf);
329 AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) {
332 fHolder = new DynByteHolder(size, buf);
335 AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) {
338 fHolder = new DynIntHolder(size, buf);
341 AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) {
344 fHolder = new DynUIntHolder(size, buf);
347 AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) {
350 fHolder = new DynFloatHolder(size, buf);
353 AliSimpleValue::~AliSimpleValue() {
360 AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) {
369 fHolder = other.fHolder->Clone();
377 Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const {
379 if (fType != other.fType) {
383 if (!(fHolder && other.fHolder)) {
387 return fHolder->IsEqual(other.fHolder);
390 void AliSimpleValue::SetBool(Bool_t val) {
392 if (!TypeOk(kBool)) {
396 ((BoolHolder*) fHolder)->fValue = val;
399 void AliSimpleValue::SetByte(Char_t val) {
401 if (!TypeOk(kByte)) {
405 ((ByteHolder*) fHolder)->fValue = val;
408 void AliSimpleValue::SetInt(Int_t val) {
414 ((IntHolder*) fHolder)->fValue = val;
417 void AliSimpleValue::SetUInt(UInt_t val) {
419 if (!TypeOk(kUInt)) {
423 ((UIntHolder*) fHolder)->fValue = val;
426 void AliSimpleValue::SetFloat(Float_t val) {
428 if (!TypeOk(kFloat)) {
432 ((FloatHolder*) fHolder)->fValue = val;
435 Bool_t AliSimpleValue::GetBool() const {
437 if (!TypeOk(kBool)) {
441 return ((BoolHolder*) fHolder)->fValue;
444 Char_t AliSimpleValue::GetByte() const {
446 if (!TypeOk(kByte)) {
450 return ((ByteHolder*) fHolder)->fValue;
453 Int_t AliSimpleValue::GetInt() const {
458 return ((IntHolder*) fHolder)->fValue;
461 UInt_t AliSimpleValue::GetUInt() const {
463 if (!TypeOk(kUInt)) {
467 return ((UIntHolder*) fHolder)->fValue;
470 Float_t AliSimpleValue::GetFloat() const {
472 if (!TypeOk(kFloat)) {
476 return ((FloatHolder*) fHolder)->fValue;
479 void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) {
481 if (!TypeOk(kDynBool)) {
489 ((DynBoolHolder*) fHolder)->fValues[n] = val;
492 void AliSimpleValue::SetDynByte(Int_t n, Char_t val) {
494 if (!TypeOk(kDynByte)) {
502 ((DynByteHolder*) fHolder)->fValues[n] = val;
505 void AliSimpleValue::SetDynInt(Int_t n, Int_t val) {
507 if (!TypeOk(kDynInt)) {
515 ((DynIntHolder*) fHolder)->fValues[n] = val;
518 void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) {
520 if (!TypeOk(kDynUInt)) {
528 ((DynUIntHolder*) fHolder)->fValues[n] = val;
531 void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) {
533 if (!TypeOk(kDynFloat)) {
541 ((DynFloatHolder*) fHolder)->fValues[n] = val;
544 Bool_t AliSimpleValue::GetDynBool(Int_t n) const {
546 if (!TypeOk(kDynBool)) {
554 return ((DynBoolHolder*) fHolder)->fValues[n];
557 Char_t AliSimpleValue::GetDynByte(Int_t n) const {
559 if (!TypeOk(kDynByte)) {
567 return ((DynByteHolder*) fHolder)->fValues[n];
570 Int_t AliSimpleValue::GetDynInt(Int_t n) const {
572 if (!TypeOk(kDynInt)) {
580 return ((DynIntHolder*) fHolder)->fValues[n];
583 UInt_t AliSimpleValue::GetDynUInt(Int_t n) const {
585 if (!TypeOk(kDynUInt)) {
593 return ((DynUIntHolder*) fHolder)->fValues[n];
596 Float_t AliSimpleValue::GetDynFloat(Int_t n) const {
598 if (!TypeOk(kDynFloat)) {
606 return ((DynFloatHolder*) fHolder)->fValues[n];
609 Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const {
612 AliError(Form("SimpleValue type is not %s!",
613 GetTypeString(type)));
620 Bool_t AliSimpleValue::BoundsOk(Int_t n) const {
628 Int_t size = ((DynHolder*) fHolder)->fSize;
629 if (n < 0 || n >= size) {
630 AliError(Form("Index %d out of bounds!", n));
640 AliError(Form("SimpleValue type %s is not dynamic!",
641 GetTypeString(fType)));
644 AliError("Invalid or unknown type!");
649 Int_t AliSimpleValue::GetDynamicSize() const {
651 // returns the size of dynamic type or 0 in case of
652 // none dynamic type.
659 if (!fHolder->IsA()->InheritsFrom(DynHolder::Class())) {
663 return ((DynHolder*) fHolder)->fSize;
666 TString AliSimpleValue::ToString() const {
671 result += GetTypeString(fType);
673 result += ", Value: ";
679 result += (Int_t) GetByte();
688 result += GetFloat();
692 Int_t size = GetDynamicSize();
693 for (Int_t k = 0; k < size; k ++) {
694 result += GetDynBool(k);
704 Int_t size = GetDynamicSize();
705 for (Int_t k = 0; k < size; k ++) {
706 result += GetDynByte(k);
716 Int_t size = GetDynamicSize();
717 for (Int_t k = 0; k < size; k ++) {
718 result += GetDynInt(k);
728 Int_t size = GetDynamicSize();
729 for (Int_t k = 0; k < size; k ++) {
730 result += GetDynUInt(k);
740 Int_t size = GetDynamicSize();
741 for (Int_t k = 0; k < size; k ++) {
742 result += GetDynFloat(k);
757 Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) {
771 Int_t AliSimpleValue::GetSize() const {
773 // return the number of bytes used by this value.
774 // In case of dynamic type it returns dynamic size multiplied
775 // by the size of corresponding primitive type.
778 return IsDynamic(fType) ?
779 GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType):
780 AliSimpleValue::GetPrimitiveSize(fType);
783 Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) {
785 // returns the number of bytes used by particular primitive type
786 // or by the corresponding primitive type in case of dynamic type.
793 case kDynBool: return sizeof(Bool_t);
795 case kDynByte: return sizeof(Char_t);
797 case kDynInt: return sizeof(Int_t);
799 case kDynUInt: return sizeof(UInt_t);
801 case kDynFloat: return sizeof(Float_t);
807 const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type type) {
810 case kBool: return "Bool";
811 case kByte: return "Byte";
812 case kInt: return "Int";
813 case kUInt: return "UInt";
814 case kFloat: return "Float";
815 case kDynBool: return "DynBool";
816 case kDynByte: return "DynByte";
817 case kDynInt: return "DynInt";
818 case kDynUInt: return "DynUInt";
819 case kDynFloat: return "DynFloat";