#ifndef OPAL_AList_HH #define OPAL_AList_HH // ------------------------------------------------------------------------ // $RCSfile: AList.h,v $ // ------------------------------------------------------------------------ // $Revision: 1.2 $ // ------------------------------------------------------------------------ // Copyright: see Copyright.readme // ------------------------------------------------------------------------ // // Template class: AList // // ------------------------------------------------------------------------ // // $Date: 2002/01/17 22:18:36 $ // $Author: jsberg $ // // ------------------------------------------------------------------------ #include "AbstractObjects/Expressions.h" #include "Expressions/SConstant.h" #include #include namespace Expressions { // Template Class AList // ---------------------------------------------------------------------- /// An array expression defined by a list of scalar expressions. // Each scalar expression is evaluated separately, and its result is // appended to the result array. template class AList: public OArray { public: /// Default constructor. // Construct empty array. AList(); /// Constructor. // Use an array of scalar expressions. explicit AList(const ArrayOfPtrs &); AList(const AList &); virtual ~AList(); /// Make clone. virtual OArray *clone() const; /// Evaluate. virtual std::vector evaluate() const; /// Print array expression. virtual void print(std::ostream &, int precedence = 99) const; protected: /// The vector of expressions. ArrayOfPtrs itsValue; private: // Not implemented. void operator=(const AList &); }; // Implementation // ------------------------------------------------------------------------ template AList::AList(): itsValue() {} template AList::AList(const AList &rhs): OArray(rhs), itsValue(rhs.itsValue) {} template AList::AList(const ArrayOfPtrs &value): itsValue(value) {} template AList::~AList() {} template OArray *AList::clone() const { return new AList(*this); } template std::vector AList::evaluate() const { std::vector result(itsValue.size(), T(0)); for(typename ArrayOfPtrs::size_type i = 0; i < itsValue.size(); ++i) { result[i] = itsValue[i]->evaluate(); } return result; } template void AList::print(std::ostream &os, int precedence) const { os << '{'; typename ArrayOfPtrs::const_iterator i = itsValue.begin(); while(i != itsValue.end()) { (*i)->print(os, 0); if(++i == itsValue.end()) break; os << ','; } os << '}'; } } #endif // OPAL_AList_HH