OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
21#include <iosfwd>
22#include <iostream>
23#include <list>
25#include "OpalParser/Token.h"
26
27namespace Expressions {
28
29 // Template class SValue
30 // ----------------------------------------------------------------------
32
33 template <class T>
34 class SValue : public AttributeBase {
35 public:
37 // Construct zero value.
38 SValue();
39
41 // Use constant value.
42 explicit SValue(const T& val);
43
44 SValue(const SValue<T>&);
45 virtual ~SValue();
46
48 virtual SValue<T>* clone() const;
49
51 // Return the (already known) value.
52 virtual T evaluate();
53
55 virtual void print(std::ostream&) const;
56
57 protected:
59 mutable T value;
60
61 private:
62 // Not implemented.
63 void operator=(const SValue<T>&);
64 };
65
66 // Implementation
67 // ------------------------------------------------------------------------
68
69 template <class T>
70 SValue<T>::SValue() : value(T(0)) {}
71
72 template <class T>
73 SValue<T>::SValue(const SValue<T>& rhs) : value(rhs.value) {}
74
75 template <class T>
76 SValue<T>::SValue(const T& val) : value(val) {}
77
78 template <class T>
80
81 template <class T>
83 return new SValue<T>(value);
84 }
85
86 template <class T>
88 return value;
89 }
90
91 // Print methods are specialised.
92 // ------------------------------------------------------------------------
93
94 template <class T>
95 void SValue<T>::print(std::ostream& os) const {
96 os << value;
97 return;
98 }
99
100 template <>
101 inline void SValue<std::list<Token> >::print(std::ostream& os) const {
102 for (std::list<Token>::iterator token = value.begin(); token != value.end(); ++token) {
103 os << *token;
104 }
105
106 return;
107 }
108
109 template <>
110 inline void SValue<bool>::print(std::ostream& os) const {
111 os << (value ? "TRUE" : "FALSE");
112 return;
113 }
114
115 template <>
116 inline void SValue<std::string>::print(std::ostream& os) const {
117 os << '"' << value << '"';
118 return;
119 }
120
121} // namespace Expressions
122
123#endif // OPAL_SValue_HH
double T
Definition OPALTypes.h:8
Abstract base class for attribute values of different types.
Object attribute with a constant scalar value.
Definition SValue.h:34
virtual SValue< T > * clone() const
Make clone.
Definition SValue.h:82
virtual T evaluate()
Evaluate.
Definition SValue.h:87
virtual ~SValue()
Definition SValue.h:79
T value
The value of the attribute.
Definition SValue.h:59
virtual void print(std::ostream &) const
Print the attribute value.
Definition SValue.h:95
void operator=(const SValue< T > &)
SValue()
Default constructor.
Definition SValue.h:70
Representation objects and parsers for attribute expressions.