GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
33 #ifndef GW_DATA_H
34 #define GW_DATA_H
35 
36 #ifndef ROOT_TString
37 #include <TString.h>
38 #endif
39 
40 #include <iostream>
41 #include <sstream>
42 
43 #ifndef GW_INFODATA_H
44 #include "InfoData.h"
45 #endif
46 
47 
48 namespace Gw {
49 
58 template<typename Data_T> class Data : public InfoData
59 {
60 protected:
61  Data_T fValue; // data value
62 
63 public:
64  Data() { fValue = 0 ; }
65  Data(Data_T data) { SetValue(data); }
66  Data(const Data & data) : InfoData(data) { fValue = data.fValue; }
67  virtual ~Data() { ; }
68 
70  virtual Data_T Get() const { return fValue; }
72  virtual void Set(Data_T data) { fValue = data; }
73 
75  virtual void Set(const char *s)
76  {
77  std::istringstream input; input.clear(); TString st = s;
78  switch( WhatIs(s) ){
79  case kKnown:
80  input.str(s); input >> fValue;
81  if ( input.fail() ) SetInfo(kUnknown);
82  else SetInfo(kKnown);
83  break;
84  case kUnknown:
86  break;
87  case kAbout:
88  st.ReplaceAll('~',' ');
89  input.str(st.Data()); input >> fValue;
90  if ( input.fail() ) SetInfo(kUnknown);
91  else SetInfo(kAbout);
92  break;
93  case kTentative:
94  st.ReplaceAll('(',' ');
95  st.ReplaceAll(')',' ');
96  input.str(st.Data()); input >> fValue;
97  if ( input.fail() ) SetInfo(kUnknown);
98  else SetInfo(kTentative);
99  break;
100  case kTheo:
101  st.ReplaceAll('[',' ');
102  st.ReplaceAll(']',' ');
103  input.str(st.Data()); input >> fValue;
104  if ( input.fail() ) SetInfo(kUnknown);
105  else SetInfo(kTheo);
106  break;
107  default:
108  SetInfo(kUnknown);
109  break;
110  }
111  }
112 
114  Data_T GetValue() const { return fValue; }
116  void SetValue(Data_T data) { fValue = data; }
117 
118  // virtual Data_T & operator () () { return fValue; }
119  virtual Data_T & operator [] (int /*i*/) { return fValue; }
120 
122  ClassDef(Data,1); // A general data
123 };
124 // inline members
125 }
126 
127 #endif
A single value data.
Definition: Data.h:58
static EData WhatIs(const char *)
It deduces from a string the kind of data.
Definition: InfoData.cpp:45
header file for InfoData
void SetValue(Data_T data)
set the value, cannot be overloaded
Definition: Data.h:116
virtual ~Data()
Definition: Data.h:67
virtual void Set(const char *s)
set the value, can be overloaded
Definition: Data.h:75
Data()
Definition: Data.h:64
virtual Data_T Get() const
get the value, can be overloaded
Definition: Data.h:70
ClassDef(Data, 1)
rootcint dictionary
Data_T fValue
Definition: Data.h:61
Base class to get/set some flag informations concerning any data.
Definition: InfoData.h:46
Data(Data_T data)
Definition: Data.h:65
Data(const Data &data)
Definition: Data.h:66
virtual void Set(Data_T data)
set the value, can be overloaded
Definition: Data.h:72
virtual void SetInfo(InfoData::EData)
to set some information about this data
Definition: InfoData.h:83
virtual Data_T & operator[](int)
Definition: Data.h:119
Data_T GetValue() const
get the value, cannot be overloaded
Definition: Data.h:114