OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
AValue.h
Go to the documentation of this file.
1 #ifndef OPAL_AValue_HH
2 #define OPAL_AValue_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: AValue.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: AValue<T>
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2000/03/27 09:33:42 $
17 // $Author: Andreas Adelmann $
18 //
19 // ------------------------------------------------------------------------
20 
22 #include "Expressions/SConstant.h"
23 #include "Parser/Token.h"
24 #include <iosfwd>
25 #include <iostream>
26 #include <vector>
27 
28 
29 namespace Expressions {
30 
31  // Template class AValue
32  // ----------------------------------------------------------------------
34 
35  template <class T> class AValue: public AttributeBase {
36 
37  public:
38 
40  // Construct empty array.
41  AValue();
42 
44  // Use the vector of values.
45  explicit AValue(const std::vector<T> &val);
46 
47  AValue(const AValue &);
48  virtual ~AValue();
49 
51  virtual AValue *clone() const;
52 
54  // Return the (already known) value.
55  virtual std::vector<T> evaluate();
56 
58  virtual void print(std::ostream &) const;
59 
60  protected:
61 
63  mutable std::vector<T> value;
64 
65  private:
66 
67  // Not implemented.
68  void operator=(const AValue<T> &);
69  };
70 
71 
72  // Implementation
73  // ----------------------------------------------------------------------
74 
75  template <class T>
77  value()
78  {}
79 
80 
81  template <class T>
83  value(rhs.value)
84  {}
85 
86 
87  template <class T>
88  AValue<T>::AValue(const std::vector<T> &val):
89  value(val)
90  {}
91 
92 
93  template <class T>
95  {}
96 
97 
98  template <class T>
100  return new AValue<T>(value);
101  }
102 
103 
104  template <class T>
105  std::vector<T> AValue<T>::evaluate() {
106  return value;
107  }
108 
109 
110  // Print methods are specialised.
111  // ------------------------------------------------------------------------
112 
113  template<> inline
114  void AValue<bool>::print(std::ostream &os) const {
115  os << '{';
116  std::vector<bool>::const_iterator i = value.begin();
117 
118  while(i != value.end()) {
119  os << (*i ? "TRUE" : "FALSE");
120  if(++i == value.end()) break;
121  os << ',';
122  }
123 
124  os << '}';
125  return;
126  }
127 
128 
129  template<> inline
130  void AValue<double>::print(std::ostream &os) const {
131  std::streamsize old_prec = os.precision(12);
132  os << '{';
133  std::vector<double>::const_iterator i = value.begin();
134 
135  while(i != value.end()) {
136  os << *i;
137  if(++i == value.end()) break;
138  os << ',';
139  }
140 
141  os << '}';
142  os.precision(old_prec);
143  return;
144  }
145 
146 
147  template<> inline
148  void AValue<std::string>::print(std::ostream &os) const {
149  os << '{';
150  std::vector<std::string>::const_iterator i = value.begin();
151 
152  while(i != value.end()) {
153  os << '"' << *i << '"';
154  if(++i == value.end()) break;
155  os << ',';
156  }
157 
158  os << '}';
159  return;
160  }
161 
162 
163  template<> inline
164  void AValue<std::list<Token> >::print(std::ostream &os) const {
165  os << '{';
166  std::vector<std::list<Token> >::const_iterator i = value.begin();
167 
168  while(i != value.end()) {
169  for(std::list<Token>::const_iterator j = i->begin();
170  j != i->end(); ++j) {
171  os << *j;
172  }
173 
174  if(++i == value.end()) break;
175  os << ',';
176  }
177 
178  os << '}';
179  return;
180  }
181 
182 }
183 
184 #endif // OPAL_AValue_HH
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
Object attribute with a constant array value.
Definition: AValue.h:35
virtual ~AValue()
Definition: AValue.h:94
void operator=(const AValue< T > &)
AValue()
Default constructor.
Definition: AValue.h:76
virtual void print(std::ostream &) const
Print the attribute value.
virtual std::vector< T > evaluate()
Evaluate.
Definition: AValue.h:105
std::vector< T > value
The value of the attribute.
Definition: AValue.h:63
virtual AValue * clone() const
Make clone.
Definition: AValue.h:99