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 2005/11/17 14:43:23 byordano
21 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
22 Initial import as subdirectory in AliRoot
24 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
27 Revision 1.2 2005/08/30 10:53:23 byordano
28 some more descriptions added
33 // This class is a simple wrapper of
34 // all primitive types used in PVSS SCADA system.
38 #include "AliSimpleValue.h"
43 TObject* AliSimpleValue::BoolHolder::Clone(const char* /*name*/) const {
44 return new BoolHolder(fValue);
47 Bool_t AliSimpleValue::BoolHolder::IsEqual(const TObject* obj) const {
53 if (BoolHolder::Class() != obj->IsA()) {
57 return fValue == ((const BoolHolder*) obj)->fValue;
60 TObject* AliSimpleValue::ByteHolder::Clone(const char* /*name*/) const {
61 return new ByteHolder(fValue);
64 Bool_t AliSimpleValue::ByteHolder::IsEqual(const TObject* obj) const {
70 if (ByteHolder::Class() != obj->IsA()) {
74 return fValue == ((const ByteHolder*) obj)->fValue;
77 TObject* AliSimpleValue::IntHolder::Clone(const char* /*name*/) const {
78 return new IntHolder(fValue);
81 Bool_t AliSimpleValue::IntHolder::IsEqual(const TObject* obj) const {
87 if (IntHolder::Class() != obj->IsA()) {
91 return fValue == ((const IntHolder*) obj)->fValue;
94 TObject* AliSimpleValue::UIntHolder::Clone(const char* /*name*/) const {
95 return new UIntHolder(fValue);
98 Bool_t AliSimpleValue::UIntHolder::IsEqual(const TObject* obj) const {
104 if (UIntHolder::Class() != obj->IsA()) {
108 return fValue == ((const UIntHolder*) obj)->fValue;
111 TObject* AliSimpleValue::FloatHolder::Clone(const char* /*name*/) const {
112 return new FloatHolder(fValue);
115 Bool_t AliSimpleValue::FloatHolder::IsEqual(const TObject* obj) const {
121 if (FloatHolder::Class() != obj->IsA()) {
125 return fValue == ((const FloatHolder*) obj)->fValue;
128 TObject* AliSimpleValue::DynBoolHolder::Clone(const char* /*name*/) const {
129 return new DynBoolHolder(fSize, fValues);
132 Bool_t AliSimpleValue::DynBoolHolder::IsEqual(const TObject* obj) const {
138 if (DynBoolHolder::Class() != obj->IsA()) {
142 const DynBoolHolder* other = ((const DynBoolHolder*) obj);
144 if (fSize != other->fSize) {
148 return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t));
151 TObject* AliSimpleValue::DynByteHolder::Clone(const char* /*name*/) const {
152 return new DynByteHolder(fSize, fValues);
155 Bool_t AliSimpleValue::DynByteHolder::IsEqual(const TObject* obj) const {
161 if (DynByteHolder::Class() != obj->IsA()) {
165 const DynByteHolder* other = ((const DynByteHolder*) obj);
167 if (fSize != other->fSize) {
171 return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t));
174 TObject* AliSimpleValue::DynIntHolder::Clone(const char* /*name*/) const {
175 return new DynIntHolder(fSize, fValues);
178 Bool_t AliSimpleValue::DynIntHolder::IsEqual(const TObject* obj) const {
184 if (DynIntHolder::Class() != obj->IsA()) {
188 const DynIntHolder* other = ((const DynIntHolder*) obj);
190 if (fSize != other->fSize) {
194 return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t));
197 TObject* AliSimpleValue::DynUIntHolder::Clone(const char* /*name*/) const {
198 return new DynUIntHolder(fSize, fValues);
201 Bool_t AliSimpleValue::DynUIntHolder::IsEqual(const TObject* obj) const {
207 if (DynUIntHolder::Class() != obj->IsA()) {
211 const DynUIntHolder* other = ((const DynUIntHolder*) obj);
213 if (fSize != other->fSize) {
217 return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t));
220 TObject* AliSimpleValue::DynFloatHolder::Clone(const char* /*name*/) const {
221 return new DynFloatHolder(fSize, fValues);
224 Bool_t AliSimpleValue::DynFloatHolder::IsEqual(const TObject* obj) const {
230 if (DynFloatHolder::Class() != obj->IsA()) {
234 const DynFloatHolder* other = ((const DynFloatHolder*) obj);
236 if (fSize != other->fSize) {
240 return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t));
243 ClassImp(AliSimpleValue)
245 AliSimpleValue::AliSimpleValue():
246 fHolder(NULL), fType(kInvalid)
251 AliSimpleValue::AliSimpleValue(const AliSimpleValue& other):
252 TObject(other), fHolder(NULL), fType(other.fType)
255 fHolder = other.fHolder->Clone();
259 AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size):
260 fHolder(NULL), fType(type)
265 fHolder = new BoolHolder();
268 fHolder = new ByteHolder();
271 fHolder = new IntHolder();
274 fHolder = new UIntHolder();
277 fHolder = new FloatHolder();
280 fHolder = new DynBoolHolder(size);
283 fHolder = new DynByteHolder(size);
286 fHolder = new DynIntHolder(size);
289 fHolder = new DynUIntHolder(size);
292 fHolder = new DynFloatHolder(size);
299 AliSimpleValue::AliSimpleValue(Bool_t val) {
302 fHolder = new BoolHolder(val);
305 AliSimpleValue::AliSimpleValue(Char_t val) {
308 fHolder = new ByteHolder(val);
311 AliSimpleValue::AliSimpleValue(Int_t val) {
314 fHolder = new IntHolder(val);
317 AliSimpleValue::AliSimpleValue(UInt_t val) {
320 fHolder = new UIntHolder(val);
323 AliSimpleValue::AliSimpleValue(Float_t val) {
326 fHolder = new FloatHolder(val);
329 AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) {
332 fHolder = new DynBoolHolder(size, buf);
335 AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) {
338 fHolder = new DynByteHolder(size, buf);
341 AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) {
344 fHolder = new DynIntHolder(size, buf);
347 AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) {
350 fHolder = new DynUIntHolder(size, buf);
353 AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) {
356 fHolder = new DynFloatHolder(size, buf);
359 AliSimpleValue::~AliSimpleValue() {
366 AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) {
375 fHolder = other.fHolder->Clone();
383 Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const {
385 if (fType != other.fType) {
389 if (!(fHolder && other.fHolder)) {
393 return fHolder->IsEqual(other.fHolder);
396 void AliSimpleValue::SetBool(Bool_t val) {
398 if (!TypeOk(kBool)) {
402 ((BoolHolder*) fHolder)->fValue = val;
405 void AliSimpleValue::SetByte(Char_t val) {
407 if (!TypeOk(kByte)) {
411 ((ByteHolder*) fHolder)->fValue = val;
414 void AliSimpleValue::SetInt(Int_t val) {
420 ((IntHolder*) fHolder)->fValue = val;
423 void AliSimpleValue::SetUInt(UInt_t val) {
425 if (!TypeOk(kUInt)) {
429 ((UIntHolder*) fHolder)->fValue = val;
432 void AliSimpleValue::SetFloat(Float_t val) {
434 if (!TypeOk(kFloat)) {
438 ((FloatHolder*) fHolder)->fValue = val;
441 Bool_t AliSimpleValue::GetBool() const {
443 if (!TypeOk(kBool)) {
447 return ((BoolHolder*) fHolder)->fValue;
450 Char_t AliSimpleValue::GetByte() const {
452 if (!TypeOk(kByte)) {
456 return ((ByteHolder*) fHolder)->fValue;
459 Int_t AliSimpleValue::GetInt() const {
464 return ((IntHolder*) fHolder)->fValue;
467 UInt_t AliSimpleValue::GetUInt() const {
469 if (!TypeOk(kUInt)) {
473 return ((UIntHolder*) fHolder)->fValue;
476 Float_t AliSimpleValue::GetFloat() const {
478 if (!TypeOk(kFloat)) {
482 return ((FloatHolder*) fHolder)->fValue;
485 void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) {
487 if (!TypeOk(kDynBool)) {
495 ((DynBoolHolder*) fHolder)->fValues[n] = val;
498 void AliSimpleValue::SetDynByte(Int_t n, Char_t val) {
500 if (!TypeOk(kDynByte)) {
508 ((DynByteHolder*) fHolder)->fValues[n] = val;
511 void AliSimpleValue::SetDynInt(Int_t n, Int_t val) {
513 if (!TypeOk(kDynInt)) {
521 ((DynIntHolder*) fHolder)->fValues[n] = val;
524 void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) {
526 if (!TypeOk(kDynUInt)) {
534 ((DynUIntHolder*) fHolder)->fValues[n] = val;
537 void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) {
539 if (!TypeOk(kDynFloat)) {
547 ((DynFloatHolder*) fHolder)->fValues[n] = val;
550 Bool_t AliSimpleValue::GetDynBool(Int_t n) const {
552 if (!TypeOk(kDynBool)) {
560 return ((DynBoolHolder*) fHolder)->fValues[n];
563 Char_t AliSimpleValue::GetDynByte(Int_t n) const {
565 if (!TypeOk(kDynByte)) {
573 return ((DynByteHolder*) fHolder)->fValues[n];
576 Int_t AliSimpleValue::GetDynInt(Int_t n) const {
578 if (!TypeOk(kDynInt)) {
586 return ((DynIntHolder*) fHolder)->fValues[n];
589 UInt_t AliSimpleValue::GetDynUInt(Int_t n) const {
591 if (!TypeOk(kDynUInt)) {
599 return ((DynUIntHolder*) fHolder)->fValues[n];
602 Float_t AliSimpleValue::GetDynFloat(Int_t n) const {
604 if (!TypeOk(kDynFloat)) {
612 return ((DynFloatHolder*) fHolder)->fValues[n];
615 Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const {
618 AliError(Form("SimpleValue type is not %s!",
619 GetTypeString(type)));
626 Bool_t AliSimpleValue::BoundsOk(Int_t n) const {
634 Int_t size = ((DynHolder*) fHolder)->fSize;
635 if (n < 0 || n >= size) {
636 AliError(Form("Index %d out of bounds!", n));
646 AliError(Form("SimpleValue type %s is not dynamic!",
647 GetTypeString(fType)));
650 AliError("Invalid or unknown type!");
655 Int_t AliSimpleValue::GetDynamicSize() const {
657 // returns the size of dynamic type or 0 in case of
658 // none dynamic type.
665 if (!fHolder->IsA()->InheritsFrom(DynHolder::Class())) {
669 return ((DynHolder*) fHolder)->fSize;
672 TString AliSimpleValue::ToString() const {
677 result += GetTypeString(fType);
679 result += ", Value: ";
685 result += (Int_t) GetByte();
694 result += GetFloat();
698 Int_t size = GetDynamicSize();
699 for (Int_t k = 0; k < size; k ++) {
700 result += GetDynBool(k);
710 Int_t size = GetDynamicSize();
711 for (Int_t k = 0; k < size; k ++) {
712 result += GetDynByte(k);
722 Int_t size = GetDynamicSize();
723 for (Int_t k = 0; k < size; k ++) {
724 result += GetDynInt(k);
734 Int_t size = GetDynamicSize();
735 for (Int_t k = 0; k < size; k ++) {
736 result += GetDynUInt(k);
746 Int_t size = GetDynamicSize();
747 for (Int_t k = 0; k < size; k ++) {
748 result += GetDynFloat(k);
763 Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) {
777 Int_t AliSimpleValue::GetSize() const {
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.
784 return IsDynamic(fType) ?
785 GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType):
786 AliSimpleValue::GetPrimitiveSize(fType);
789 Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) {
791 // returns the number of bytes used by particular primitive type
792 // or by the corresponding primitive type in case of dynamic type.
799 case kDynBool: return sizeof(Bool_t);
801 case kDynByte: return sizeof(Char_t);
803 case kDynInt: return sizeof(Int_t);
805 case kDynUInt: return sizeof(UInt_t);
807 case kDynFloat: return sizeof(Float_t);
813 const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type 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";