OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
21#include <iosfwd>
22#include <iostream>
23#include <vector>
26#include "OpalParser/Token.h"
27
28namespace Expressions {
29
30 // Template class AValue
31 // ----------------------------------------------------------------------
33
34 template <class T>
35 class AValue : public AttributeBase {
36 public:
38 // Construct empty array.
39 AValue();
40
42 // Use the vector of values.
43 explicit AValue(const std::vector<T>& val);
44
45 AValue(const AValue&);
46 virtual ~AValue();
47
49 virtual AValue* clone() const;
50
52 // Return the (already known) value.
53 virtual std::vector<T> evaluate();
54
56 virtual void print(std::ostream&) const;
57
58 protected:
60 mutable std::vector<T> value;
61
62 private:
63 // Not implemented.
64 void operator=(const AValue<T>&);
65 };
66
67 // Implementation
68 // ----------------------------------------------------------------------
69
70 template <class T>
71 AValue<T>::AValue() : value() {}
72
73 template <class T>
74 AValue<T>::AValue(const AValue<T>& rhs) : value(rhs.value) {}
75
76 template <class T>
77 AValue<T>::AValue(const std::vector<T>& val) : value(val) {}
78
79 template <class T>
81
82 template <class T>
84 return new AValue<T>(value);
85 }
86
87 template <class T>
88 std::vector<T> AValue<T>::evaluate() {
89 return value;
90 }
91
92 // Print methods are specialised.
93 // ------------------------------------------------------------------------
94
95 template <>
96 inline void AValue<bool>::print(std::ostream& os) const {
97 os << '{';
98 std::vector<bool>::const_iterator i = value.begin();
99
100 while (i != value.end()) {
101 os << (*i ? "TRUE" : "FALSE");
102 if (++i == value.end()) break;
103 os << ',';
104 }
105
106 os << '}';
107 return;
108 }
109
110 template <>
111 inline void AValue<double>::print(std::ostream& os) const {
112 std::streamsize old_prec = os.precision(12);
113 os << '{';
114 std::vector<double>::const_iterator i = value.begin();
115
116 while (i != value.end()) {
117 os << *i;
118 if (++i == value.end()) break;
119 os << ',';
120 }
121
122 os << '}';
123 os.precision(old_prec);
124 return;
125 }
126
127 template <>
128 inline void AValue<std::string>::print(std::ostream& os) const {
129 os << '{';
130 std::vector<std::string>::const_iterator i = value.begin();
131
132 while (i != value.end()) {
133 os << '"' << *i << '"';
134 if (++i == value.end()) break;
135 os << ',';
136 }
137
138 os << '}';
139 return;
140 }
141
142 template <>
143 inline void AValue<std::list<Token> >::print(std::ostream& os) const {
144 os << '{';
145 std::vector<std::list<Token> >::const_iterator i = value.begin();
146
147 while (i != value.end()) {
148 for (std::list<Token>::const_iterator j = i->begin(); j != i->end(); ++j) {
149 os << *j;
150 }
151
152 if (++i == value.end()) break;
153 os << ',';
154 }
155
156 os << '}';
157 return;
158 }
159
160} // namespace Expressions
161
162#endif // OPAL_AValue_HH
Abstract base class for attribute values of different types.
Object attribute with a constant array value.
Definition AValue.h:35
virtual ~AValue()
Definition AValue.h:80
AValue(const AValue &)
void operator=(const AValue< T > &)
AValue()
Default constructor.
Definition AValue.h:71
virtual void print(std::ostream &) const
Print the attribute value.
virtual std::vector< T > evaluate()
Evaluate.
Definition AValue.h:88
std::vector< T > value
The value of the attribute.
Definition AValue.h:60
virtual AValue * clone() const
Make clone.
Definition AValue.h:83
Representation objects and parsers for attribute expressions.