OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
21#include <iostream>
22#include <vector>
25
26namespace Expressions {
27
28 // Template Class AList
29 // ----------------------------------------------------------------------
31 // Each scalar expression is evaluated separately, and its result is
32 // appended to the result array.
33
34 template <class T>
35 class AList : public OArray<T> {
36 public:
38 // Construct empty array.
39 AList();
40
42 // Use an array of scalar expressions.
43 explicit AList(const ArrayOfPtrs<T>&);
44
45 AList(const AList&);
46 virtual ~AList();
47
49 virtual OArray<T>* clone() const;
50
52 virtual std::vector<T> evaluate() const;
53
55 virtual void print(std::ostream&, int precedence = 99) const;
56
57 protected:
60
61 private:
62 // Not implemented.
63 void operator=(const AList&);
64 };
65
66 // Implementation
67 // ------------------------------------------------------------------------
68
69 template <class T>
70 AList<T>::AList() : itsValue() {}
71
72 template <class T>
73 AList<T>::AList(const AList<T>& rhs) : OArray<T>(rhs), itsValue(rhs.itsValue) {}
74
75 template <class T>
76 AList<T>::AList(const ArrayOfPtrs<T>& value) : itsValue(value) {}
77
78 template <class T>
80
81 template <class T>
83 return new AList<T>(*this);
84 }
85
86 template <class T>
87 std::vector<T> AList<T>::evaluate() const {
88 std::vector<T> result(itsValue.size(), T(0));
89
90 for (typename ArrayOfPtrs<T>::size_type i = 0; i < itsValue.size(); ++i) {
91 result[i] = itsValue[i]->evaluate();
92 }
93
94 return result;
95 }
96
97 template <class T>
98 void AList<T>::print(std::ostream& os, int /*precedence*/) const {
99 os << '{';
100 typename ArrayOfPtrs<T>::const_iterator i = itsValue.begin();
101
102 while (i != itsValue.end()) {
103 (*i)->print(os, 0);
104 if (++i == itsValue.end()) break;
105 os << ',';
106 }
107
108 os << '}';
109 }
110
111} // namespace Expressions
112
113#endif // OPAL_AList_HH
double T
Definition OPALTypes.h:8
An array expression defined by a list of scalar expressions.
Definition AList.h:35
AList()
Default constructor.
Definition AList.h:70
AList(const AList &)
virtual OArray< T > * clone() const
Make clone.
Definition AList.h:82
virtual void print(std::ostream &, int precedence=99) const
Print array expression.
Definition AList.h:98
virtual ~AList()
Definition AList.h:79
virtual std::vector< T > evaluate() const
Evaluate.
Definition AList.h:87
void operator=(const AList &)
ArrayOfPtrs< T > itsValue
The vector of expressions.
Definition AList.h:59
An array of pointers to scalar expressions.
Representation objects and parsers for attribute expressions.