OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SConstant.h
Go to the documentation of this file.
1#ifndef OPAL_SConstant_HH
2#define OPAL_SConstant_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: SConstant.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.2 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Template class: SConstant<T>
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2001/08/13 15:12:35 $
17// $Author: jowett $
18//
19// ------------------------------------------------------------------------
20
22#include "Parser/Token.h"
23#include <iomanip>
24#include <iostream>
25#include <list>
26
27
28namespace Expressions {
29
30 // Class SConstant
31 // ----------------------------------------------------------------------
33 // This expression returns a scalar constant.
34
35 template <class T> class SConstant: public Scalar<T> {
36
37 public:
38
40 // Use the value of the constant.
41 explicit SConstant(T value);
42
43 virtual ~SConstant();
44
46 virtual Scalar<T> *clone() const;
47
49 virtual T evaluate() const;
50
52 // Always true.
53 virtual bool isConstant() const;
54
56 virtual void print(std::ostream &str, int precedence) const;
57
58 private:
59
60 // Not implemented.
63 void operator=(const SConstant<T> &);
64
66 };
67
68
69 // Implementation
70 // ----------------------------------------------------------------------
71
72 template <class T> inline
74 value(val)
75 {}
76
77
78 template <class T> inline
80 {}
81
82
83 template <class T> inline
85 return new SConstant<T>(value);
86 }
87
88
89 template <class T> inline
91 return value;
92 }
93
94
95 template <class T> inline
97 return true;
98 }
99
100
101 // All print() methods must be specialised.
102 // ----------------------------------------------------------------------
103
104 template<> inline
105 void SConstant<bool>::print(std::ostream &os, int) const {
106 os << (value ? "TRUE" : "FALSE");
107 }
108
109
110 template<> inline
111 void SConstant<double>::print(std::ostream &os, int) const {
112 //std::streamsize old_prec = os.precision(12);
113 os << value;
114 // ada 15-6-2000 statement unreachable os.precision(old_prec);
115 }
116
117
118 template<> inline
119 void SConstant<std::string>::print(std::ostream &os, int) const {
120 os << '"' << value << '"';
121 }
122
123
124 template<> inline
125 void SConstant<std::list<Token> >::print(std::ostream &os, int) const {
126 for(std::list<Token>::const_iterator token = value.begin();
127 token != value.end(); ++token) {
128 os << *token;
129 }
130 }
131
132}
133
134#endif // OPAL_SConstant_HH
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
A scalar expression.
Definition: Expressions.h:71
A scalar constant expression.
Definition: SConstant.h:35
virtual void print(std::ostream &str, int precedence) const
Print expression.
virtual bool isConstant() const
Test for constant.
Definition: SConstant.h:96
virtual T evaluate() const
Evaluate.
Definition: SConstant.h:90
virtual ~SConstant()
Definition: SConstant.h:79
SConstant(const SConstant< T > &)
virtual Scalar< T > * clone() const
Make clone.
Definition: SConstant.h:84
void operator=(const SConstant< T > &)