OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
21#include <iomanip>
22#include <iostream>
23#include <list>
25#include "OpalParser/Token.h"
26
27namespace Expressions {
28
29 // Class SConstant
30 // ----------------------------------------------------------------------
32 // This expression returns a scalar constant.
33
34 template <class T>
35 class SConstant : public Scalar<T> {
36 public:
38 // Use the value of the constant.
39 explicit SConstant(T value);
40
41 virtual ~SConstant();
42
44 virtual Scalar<T>* clone() const;
45
47 virtual T evaluate() const;
48
50 // Always true.
51 virtual bool isConstant() const;
52
54 virtual void print(std::ostream& str, int precedence) const;
55
56 private:
57 // Not implemented.
60 void operator=(const SConstant<T>&);
61
63 };
64
65 // Implementation
66 // ----------------------------------------------------------------------
67
68 template <class T>
69 inline SConstant<T>::SConstant(T val) : value(val) {}
70
71 template <class T>
73
74 template <class T>
76 return new SConstant<T>(value);
77 }
78
79 template <class T>
80 inline T SConstant<T>::evaluate() const {
81 return value;
82 }
83
84 template <class T>
85 inline bool SConstant<T>::isConstant() const {
86 return true;
87 }
88
89 // All print() methods must be specialised.
90 // ----------------------------------------------------------------------
91
92 template <>
93 inline void SConstant<bool>::print(std::ostream& os, int) const {
94 os << (value ? "TRUE" : "FALSE");
95 }
96
97 template <>
98 inline void SConstant<double>::print(std::ostream& os, int) const {
99 // std::streamsize old_prec = os.precision(12);
100 os << value;
101 // ada 15-6-2000 statement unreachable os.precision(old_prec);
102 }
103
104 template <>
105 inline void SConstant<std::string>::print(std::ostream& os, int) const {
106 os << '"' << value << '"';
107 }
108
109 template <>
110 inline void SConstant<std::list<Token> >::print(std::ostream& os, int) const {
111 for (std::list<Token>::const_iterator token = value.begin(); token != value.end();
112 ++token) {
113 os << *token;
114 }
115 }
116
117} // namespace Expressions
118
119#endif // OPAL_SConstant_HH
double T
Definition OPALTypes.h:8
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:85
virtual T evaluate() const
Evaluate.
Definition SConstant.h:80
SConstant(const SConstant< T > &)
virtual Scalar< T > * clone() const
Make clone.
Definition SConstant.h:75
void operator=(const SConstant< T > &)
Representation objects and parsers for attribute expressions.