QDP++
Scalar.h
Go to the documentation of this file.
1// -*- C++ -*-
2// ACL:license
3// ----------------------------------------------------------------------
4// This software and ancillary information (herein called "SOFTWARE")
5// called PETE (Portable Expression Template Engine) is
6// made available under the terms described here. The SOFTWARE has been
7// approved for release with associated LA-CC Number LA-CC-99-5.
8//
9// Unless otherwise indicated, this SOFTWARE has been authored by an
10// employee or employees of the University of California, operator of the
11// Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
12// the U.S. Department of Energy. The U.S. Government has rights to use,
13// reproduce, and distribute this SOFTWARE. The public may copy, distribute,
14// prepare derivative works and publicly display this SOFTWARE without
15// charge, provided that this Notice and any statement of authorship are
16// reproduced on all copies. Neither the Government nor the University
17// makes any warranty, express or implied, or assumes any liability or
18// responsibility for the use of this SOFTWARE.
19//
20// If SOFTWARE is modified to produce derivative works, such modified
21// SOFTWARE should be clearly marked, so as not to confuse it with the
22// version available from LANL.
23//
24// For more information about PETE, send e-mail to pete@acl.lanl.gov,
25// or visit the PETE web page at http://www.acl.lanl.gov/pete/.
26// ----------------------------------------------------------------------
27// ACL:license
28
29#ifndef PETE_PETE_SCALAR_H
30#define PETE_PETE_SCALAR_H
31
33//
34// WARNING: THIS FILE IS FOR INTERNAL PETE USE. DON'T INCLUDE IT YOURSELF
35//
37
38//-----------------------------------------------------------------------------
39//
40// CLASS NAME
41// Scalar<T>
42//
43// DESCRIPTION
44// A wrapper around a scalar to be used in PETE expressions.
45//
46//-----------------------------------------------------------------------------
47
48template<class T>
49class Scalar
50{
51public:
52
53 //---------------------------------------------------------------------------
54 // Default constructor takes no action.
55
56 inline
57 Scalar() { }
58
59 //---------------------------------------------------------------------------
60 // Constructor from a single value.
61
62 inline
63 Scalar(const T &t) : scalar_m(t) { }
64
65 template<class T1>
66 inline
67 explicit Scalar(const T1 &t) : scalar_m(t) { }
68
69 //---------------------------------------------------------------------------
70 // Constructor with arbitary second/third arguments, which is/are ignored.
71 // Needed for compatibility with tree node constructors taking an
72 // arbitrary argument.
73
74 template<class Arg>
75 inline
76 Scalar(const Scalar<T> &s, const Arg &)
77 : scalar_m(s.scalar_m) { }
78
79 template<class Arg1, class Arg2>
80 inline
81 Scalar(const Scalar<T> &s, const Arg1 &, const Arg2 &)
82 : scalar_m(s.scalar_m) { }
83
84 //---------------------------------------------------------------------------
85 // Copy constructor
86
87 inline
88 Scalar(const Scalar<T> &s) : scalar_m(s.scalar_m) { }
89
90 //---------------------------------------------------------------------------
91 // Return value.
92
93 inline
94 const T &value() const { return scalar_m; }
95
96 //---------------------------------------------------------------------------
97 // Assignment operators.
98
99 inline
101 {
102 scalar_m = rhs.scalar_m;
103
104 return *this;
105 }
106
107 inline
108 Scalar<T> &operator=(const T &rhs)
109 {
110 scalar_m = rhs;
111
112 return *this;
113 }
114
115private:
116
117 //---------------------------------------------------------------------------
118 // The scalar value is stored here.
119
120 T scalar_m;
121};
122
123
124#endif // PETE_PETE_SCALAR_H
125
126// ACL:rcsinfo
127// ----------------------------------------------------------------------
128// $RCSfile: Scalar.h,v $ $Author: edwards $
129// $Revision: 1.1 $ $Date: 2002-09-12 18:22:16 $
130// ----------------------------------------------------------------------
131// ACL:rcsinfo
Scalar(const Scalar< T > &s, const Arg1 &, const Arg2 &)
Definition Scalar.h:81
Scalar(const T1 &t)
Definition Scalar.h:67
Scalar< T > & operator=(const T &rhs)
Definition Scalar.h:108
Scalar(const Scalar< T > &s, const Arg &)
Definition Scalar.h:76
Scalar(const T &t)
Definition Scalar.h:63
const T & value() const
Definition Scalar.h:94
Scalar()
Definition Scalar.h:57
Scalar(const Scalar< T > &s)
Definition Scalar.h:88
Scalar< T > & operator=(const Scalar< T > &rhs)
Definition Scalar.h:100