OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
28 namespace 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.
61  SConstant();
62  SConstant(const SConstant<T> &);
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
96  bool SConstant<T>::isConstant() const {
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
virtual void print(std::ostream &str, int precedence) const
Print expression.
A scalar expression.
Definition: Expressions.h:79
void operator=(const SConstant< T > &)
virtual Scalar< T > * clone() const
Make clone.
Definition: SConstant.h:84
A scalar constant expression.
Definition: SConstant.h:35
Definition: rbendmap.h:8
virtual T evaluate() const
Evaluate.
Definition: SConstant.h:90
virtual bool isConstant() const
Test for constant.
Definition: SConstant.h:96
virtual ~SConstant()
Definition: SConstant.h:79