OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SValue.h
Go to the documentation of this file.
1#ifndef OPAL_SValue_HH
2#define OPAL_SValue_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: SValue.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Template class: SValue<T>
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:33:42 $
17// $Author: Andreas Adelmann $
18//
19// ------------------------------------------------------------------------
20
22#include "Parser/Token.h"
23#include <iosfwd>
24#include <iostream>
25#include <list>
26
27
28namespace Expressions {
29
30 // Template class SValue
31 // ----------------------------------------------------------------------
33
34 template <class T> class SValue: public AttributeBase {
35
36 public:
37
39 // Construct zero value.
40 SValue();
41
43 // Use constant value.
44 explicit SValue(const T &val);
45
46 SValue(const SValue<T> &);
47 virtual ~SValue();
48
50 virtual SValue<T> *clone() const;
51
53 // Return the (already known) value.
54 virtual T evaluate();
55
57 virtual void print(std::ostream &) const;
58
59 protected:
60
62 mutable T value;
63
64 private:
65
66 // Not implemented.
67 void operator=(const SValue<T> &);
68 };
69
70
71 // Implementation
72 // ------------------------------------------------------------------------
73
74 template <class T>
76 value(T(0))
77 {}
78
79
80 template <class T>
82 value(rhs.value)
83 {}
84
85
86 template <class T>
87 SValue<T>::SValue(const T &val):
88 value(val)
89 {}
90
91
92 template <class T>
94 {}
95
96
97 template <class T>
99 return new SValue<T>(value);
100 }
101
102
103 template <class T>
105 return value;
106 }
107
108
109 // Print methods are specialised.
110 // ------------------------------------------------------------------------
111
112 template <class T>
113 void SValue<T>::print(std::ostream &os) const {
114 os << value;
115 return;
116 }
117
118
119 template<> inline
120 void SValue<std::list<Token> >::print(std::ostream &os) const {
121 for(std::list<Token>::iterator token = value.begin();
122 token != value.end(); ++token) {
123 os << *token;
124 }
125
126 return;
127 }
128
129
130 template<> inline
131 void SValue<bool>::print(std::ostream &os) const {
132 os << (value ? "TRUE" : "FALSE");
133 return;
134 }
135
136
137 template<> inline
138 void SValue<std::string>::print(std::ostream &os) const {
139 os << '"' << value << '"';
140 return;
141 }
142
143}
144
145#endif // OPAL_SValue_HH
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
std::string::iterator iterator
Definition: MSLang.h:16
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
Object attribute with a constant scalar value.
Definition: SValue.h:34
virtual SValue< T > * clone() const
Make clone.
Definition: SValue.h:98
virtual T evaluate()
Evaluate.
Definition: SValue.h:104
virtual ~SValue()
Definition: SValue.h:93
T value
The value of the attribute.
Definition: SValue.h:62
virtual void print(std::ostream &) const
Print the attribute value.
Definition: SValue.h:113
void operator=(const SValue< T > &)
SValue()
Default constructor.
Definition: SValue.h:75