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.2 2006/03/07 07:52:34 hristov
19 New version (B.Yordanov)
21 Revision 1.2 2005/11/17 14:43:23 byordano
24 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
25 Initial import as subdirectory in AliRoot
27 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
30 Revision 1.2 2005/08/30 10:53:23 byordano
31 some more descriptions added
36 // This class is a simple wrapper of
37 // all primitive types used in PVSS SCADA system.
41 #include "AliSimpleValue.h"
46 TObject* AliSimpleValue::BoolHolder::Clone(const char* /*name*/) const {
47 return new BoolHolder(fValue);
50 Bool_t AliSimpleValue::BoolHolder::IsEqual(const TObject* obj) const {
56 if (BoolHolder::Class() != obj->IsA()) {
60 return fValue == ((const BoolHolder*) obj)->fValue;
63 TObject* AliSimpleValue::ByteHolder::Clone(const char* /*name*/) const {
64 return new ByteHolder(fValue);
67 Bool_t AliSimpleValue::ByteHolder::IsEqual(const TObject* obj) const {
73 if (ByteHolder::Class() != obj->IsA()) {
77 return fValue == ((const ByteHolder*) obj)->fValue;
80 TObject* AliSimpleValue::IntHolder::Clone(const char* /*name*/) const {
81 return new IntHolder(fValue);
84 Bool_t AliSimpleValue::IntHolder::IsEqual(const TObject* obj) const {
90 if (IntHolder::Class() != obj->IsA()) {
94 return fValue == ((const IntHolder*) obj)->fValue;
97 TObject* AliSimpleValue::UIntHolder::Clone(const char* /*name*/) const {
98 return new UIntHolder(fValue);
101 Bool_t AliSimpleValue::UIntHolder::IsEqual(const TObject* obj) const {
107 if (UIntHolder::Class() != obj->IsA()) {
111 return fValue == ((const UIntHolder*) obj)->fValue;
114 TObject* AliSimpleValue::FloatHolder::Clone(const char* /*name*/) const {
115 return new FloatHolder(fValue);
118 Bool_t AliSimpleValue::FloatHolder::IsEqual(const TObject* obj) const {
124 if (FloatHolder::Class() != obj->IsA()) {
128 return fValue == ((const FloatHolder*) obj)->fValue;
131 TObject* AliSimpleValue::DynBoolHolder::Clone(const char* /*name*/) const {
132 return new DynBoolHolder(fSize, fValues);
135 Bool_t AliSimpleValue::DynBoolHolder::IsEqual(const TObject* obj) const {
141 if (DynBoolHolder::Class() != obj->IsA()) {
145 const DynBoolHolder* other = ((const DynBoolHolder*) obj);
147 if (fSize != other->fSize) {
151 return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t));
154 TObject* AliSimpleValue::DynByteHolder::Clone(const char* /*name*/) const {
155 return new DynByteHolder(fSize, fValues);
158 Bool_t AliSimpleValue::DynByteHolder::IsEqual(const TObject* obj) const {
164 if (DynByteHolder::Class() != obj->IsA()) {
168 const DynByteHolder* other = ((const DynByteHolder*) obj);
170 if (fSize != other->fSize) {
174 return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t));
177 TObject* AliSimpleValue::DynIntHolder::Clone(const char* /*name*/) const {
178 return new DynIntHolder(fSize, fValues);
181 Bool_t AliSimpleValue::DynIntHolder::IsEqual(const TObject* obj) const {
187 if (DynIntHolder::Class() != obj->IsA()) {
191 const DynIntHolder* other = ((const DynIntHolder*) obj);
193 if (fSize != other->fSize) {
197 return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t));
200 TObject* AliSimpleValue::DynUIntHolder::Clone(const char* /*name*/) const {
201 return new DynUIntHolder(fSize, fValues);
204 Bool_t AliSimpleValue::DynUIntHolder::IsEqual(const TObject* obj) const {
210 if (DynUIntHolder::Class() != obj->IsA()) {
214 const DynUIntHolder* other = ((const DynUIntHolder*) obj);
216 if (fSize != other->fSize) {
220 return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t));
223 TObject* AliSimpleValue::DynFloatHolder::Clone(const char* /*name*/) const {
224 return new DynFloatHolder(fSize, fValues);
227 Bool_t AliSimpleValue::DynFloatHolder::IsEqual(const TObject* obj) const {
233 if (DynFloatHolder::Class() != obj->IsA()) {
237 const DynFloatHolder* other = ((const DynFloatHolder*) obj);
239 if (fSize != other->fSize) {
243 return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t));
246 ClassImp(AliSimpleValue)
248 AliSimpleValue::AliSimpleValue():
249 fHolder(NULL), fType(kInvalid)
254 AliSimpleValue::AliSimpleValue(const AliSimpleValue& other):
255 TObject(other), fHolder(NULL), fType(other.fType)
258 fHolder = other.fHolder->Clone();
262 AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size):
263 fHolder(NULL), fType(type)
268 fHolder = new BoolHolder();
271 fHolder = new ByteHolder();
274 fHolder = new IntHolder();
277 fHolder = new UIntHolder();
280 fHolder = new FloatHolder();
283 fHolder = new DynBoolHolder(size);
286 fHolder = new DynByteHolder(size);
289 fHolder = new DynIntHolder(size);
292 fHolder = new DynUIntHolder(size);
295 fHolder = new DynFloatHolder(size);
302 AliSimpleValue::AliSimpleValue(Bool_t val) {
305 fHolder = new BoolHolder(val);
308 AliSimpleValue::AliSimpleValue(Char_t val) {
311 fHolder = new ByteHolder(val);
314 AliSimpleValue::AliSimpleValue(Int_t val) {
317 fHolder = new IntHolder(val);
320 AliSimpleValue::AliSimpleValue(UInt_t val) {
323 fHolder = new UIntHolder(val);
326 AliSimpleValue::AliSimpleValue(Float_t val) {
329 fHolder = new FloatHolder(val);
332 AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) {
335 fHolder = new DynBoolHolder(size, buf);
338 AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) {
341 fHolder = new DynByteHolder(size, buf);
344 AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) {
347 fHolder = new DynIntHolder(size, buf);
350 AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) {
353 fHolder = new DynUIntHolder(size, buf);
356 AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) {
359 fHolder = new DynFloatHolder(size, buf);
362 AliSimpleValue::~AliSimpleValue() {
369 AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) {
378 fHolder = other.fHolder->Clone();
386 Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const {
388 if (fType != other.fType) {
392 if (!(fHolder && other.fHolder)) {
396 return fHolder->IsEqual(other.fHolder);
399 void AliSimpleValue::SetBool(Bool_t val) {
401 if (!TypeOk(kBool)) {
405 ((BoolHolder*) fHolder)->fValue = val;
408 void AliSimpleValue::SetByte(Char_t val) {
410 if (!TypeOk(kByte)) {
414 ((ByteHolder*) fHolder)->fValue = val;
417 void AliSimpleValue::SetInt(Int_t val) {
423 ((IntHolder*) fHolder)->fValue = val;
426 void AliSimpleValue::SetUInt(UInt_t val) {
428 if (!TypeOk(kUInt)) {
432 ((UIntHolder*) fHolder)->fValue = val;
435 void AliSimpleValue::SetFloat(Float_t val) {
437 if (!TypeOk(kFloat)) {
441 ((FloatHolder*) fHolder)->fValue = val;
444 Bool_t AliSimpleValue::GetBool() const {
446 if (!TypeOk(kBool)) {
450 return ((BoolHolder*) fHolder)->fValue;
453 Char_t AliSimpleValue::GetByte() const {
455 if (!TypeOk(kByte)) {
459 return ((ByteHolder*) fHolder)->fValue;
462 Int_t AliSimpleValue::GetInt() const {
467 return ((IntHolder*) fHolder)->fValue;
470 UInt_t AliSimpleValue::GetUInt() const {
472 if (!TypeOk(kUInt)) {
476 return ((UIntHolder*) fHolder)->fValue;
479 Float_t AliSimpleValue::GetFloat() const {
481 if (!TypeOk(kFloat)) {
485 return ((FloatHolder*) fHolder)->fValue;
488 void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) {
490 if (!TypeOk(kDynBool)) {
498 ((DynBoolHolder*) fHolder)->fValues[n] = val;
501 void AliSimpleValue::SetDynByte(Int_t n, Char_t val) {
503 if (!TypeOk(kDynByte)) {
511 ((DynByteHolder*) fHolder)->fValues[n] = val;
514 void AliSimpleValue::SetDynInt(Int_t n, Int_t val) {
516 if (!TypeOk(kDynInt)) {
524 ((DynIntHolder*) fHolder)->fValues[n] = val;
527 void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) {
529 if (!TypeOk(kDynUInt)) {
537 ((DynUIntHolder*) fHolder)->fValues[n] = val;
540 void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) {
542 if (!TypeOk(kDynFloat)) {
550 ((DynFloatHolder*) fHolder)->fValues[n] = val;
553 Bool_t AliSimpleValue::GetDynBool(Int_t n) const {
555 if (!TypeOk(kDynBool)) {
563 return ((DynBoolHolder*) fHolder)->fValues[n];
566 Char_t AliSimpleValue::GetDynByte(Int_t n) const {
568 if (!TypeOk(kDynByte)) {
576 return ((DynByteHolder*) fHolder)->fValues[n];
579 Int_t AliSimpleValue::GetDynInt(Int_t n) const {
581 if (!TypeOk(kDynInt)) {
589 return ((DynIntHolder*) fHolder)->fValues[n];
592 UInt_t AliSimpleValue::GetDynUInt(Int_t n) const {
594 if (!TypeOk(kDynUInt)) {
602 return ((DynUIntHolder*) fHolder)->fValues[n];
605 Float_t AliSimpleValue::GetDynFloat(Int_t n) const {
607 if (!TypeOk(kDynFloat)) {
615 return ((DynFloatHolder*) fHolder)->fValues[n];
618 Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const {
621 AliError(Form("SimpleValue type is not %s!",
622 GetTypeString(type)));
629 Bool_t AliSimpleValue::BoundsOk(Int_t n) const {
637 Int_t size = ((DynHolder*) fHolder)->fSize;
638 if (n < 0 || n >= size) {
639 AliError(Form("Index %d out of bounds!", n));
649 AliError(Form("SimpleValue type %s is not dynamic!",
650 GetTypeString(fType)));
653 AliError("Invalid or unknown type!");
658 Int_t AliSimpleValue::GetDynamicSize() const {
660 // returns the size of dynamic type or 0 in case of
661 // none dynamic type.
668 if (!fHolder->IsA()->InheritsFrom(DynHolder::Class())) {
672 return ((DynHolder*) fHolder)->fSize;
675 TString AliSimpleValue::ToString() const {
680 result += GetTypeString(fType);
682 result += ", Value: ";
688 result += (Int_t) GetByte();
697 result += GetFloat();
701 Int_t size = GetDynamicSize();
702 for (Int_t k = 0; k < size; k ++) {
703 result += GetDynBool(k);
713 Int_t size = GetDynamicSize();
714 for (Int_t k = 0; k < size; k ++) {
715 result += GetDynByte(k);
725 Int_t size = GetDynamicSize();
726 for (Int_t k = 0; k < size; k ++) {
727 result += GetDynInt(k);
737 Int_t size = GetDynamicSize();
738 for (Int_t k = 0; k < size; k ++) {
739 result += GetDynUInt(k);
749 Int_t size = GetDynamicSize();
750 for (Int_t k = 0; k < size; k ++) {
751 result += GetDynFloat(k);
766 Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) {
780 Int_t AliSimpleValue::GetSize() const {
782 // return the number of bytes used by this value.
783 // In case of dynamic type it returns dynamic size multiplied
784 // by the size of corresponding primitive type.
787 return IsDynamic(fType) ?
788 GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType):
789 AliSimpleValue::GetPrimitiveSize(fType);
792 Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) {
794 // returns the number of bytes used by particular primitive type
795 // or by the corresponding primitive type in case of dynamic type.
802 case kDynBool: return sizeof(Bool_t);
804 case kDynByte: return sizeof(Char_t);
806 case kDynInt: return sizeof(Int_t);
808 case kDynUInt: return sizeof(UInt_t);
810 case kDynFloat: return sizeof(Float_t);
816 const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type type) {
819 case kBool: return "Bool";
820 case kByte: return "Byte";
821 case kInt: return "Int";
822 case kUInt: return "UInt";
823 case kFloat: return "Float";
824 case kDynBool: return "DynBool";
825 case kDynByte: return "DynByte";
826 case kDynInt: return "DynInt";
827 case kDynUInt: return "DynUInt";
828 case kDynFloat: return "DynFloat";