OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
AList.h
Go to the documentation of this file.
1#ifndef OPAL_AList_HH
2#define OPAL_AList_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: AList.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.2 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Template class: AList<T>
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2002/01/17 22:18:36 $
17// $Author: jsberg $
18//
19// ------------------------------------------------------------------------
20
23#include <iostream>
24#include <vector>
25
26
27namespace Expressions {
28
29 // Template Class AList
30 // ----------------------------------------------------------------------
32 // Each scalar expression is evaluated separately, and its result is
33 // appended to the result array.
34
35 template <class T>
36 class AList: public OArray<T> {
37
38 public:
39
41 // Construct empty array.
42 AList();
43
45 // Use an array of scalar expressions.
46 explicit AList(const ArrayOfPtrs<T> &);
47
48 AList(const AList &);
49 virtual ~AList();
50
52 virtual OArray<T> *clone() const;
53
55 virtual std::vector<T> evaluate() const;
56
58 virtual void print(std::ostream &, int precedence = 99) const;
59
60 protected:
61
64
65 private:
66
67 // Not implemented.
68 void operator=(const AList &);
69 };
70
71
72 // Implementation
73 // ------------------------------------------------------------------------
74
75 template <class T>
77 itsValue()
78 {}
79
80
81 template <class T>
83 OArray<T>(rhs),
84 itsValue(rhs.itsValue)
85 {}
86
87
88 template <class T>
90 itsValue(value)
91 {}
92
93
94 template <class T>
96 {}
97
98
99 template <class T>
101 return new AList<T>(*this);
102 }
103
104
105 template <class T>
106 std::vector<T> AList<T>::evaluate() const {
107 std::vector<T> result(itsValue.size(), T(0));
108
109 for(typename ArrayOfPtrs<T>::size_type i = 0; i < itsValue.size(); ++i) {
110 result[i] = itsValue[i]->evaluate();
111 }
112
113 return result;
114 }
115
116
117 template <class T>
118 void AList<T>::print(std::ostream &os, int /*precedence*/) const {
119 os << '{';
120 typename ArrayOfPtrs<T>::const_iterator i = itsValue.begin();
121
122 while(i != itsValue.end()) {
123 (*i)->print(os, 0);
124 if(++i == itsValue.end()) break;
125 os << ',';
126 }
127
128 os << '}';
129 }
130
131}
132
133#endif // OPAL_AList_HH
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
An array of pointers to scalar expressions.
Definition: Expressions.h:127
An array expression.
Definition: Expressions.h:142
An array expression defined by a list of scalar expressions.
Definition: AList.h:36
AList()
Default constructor.
Definition: AList.h:76
virtual OArray< T > * clone() const
Make clone.
Definition: AList.h:100
virtual void print(std::ostream &, int precedence=99) const
Print array expression.
Definition: AList.h:118
virtual ~AList()
Definition: AList.h:95
virtual std::vector< T > evaluate() const
Evaluate.
Definition: AList.h:106
void operator=(const AList &)
ArrayOfPtrs< T > itsValue
The vector of expressions.
Definition: AList.h:63