Main Page | Class Hierarchy | Class List | File List | Class Members

exprList.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
00021  *
00022  *********************************************************************/
00023 
00024 #ifndef __EXPR_LIST_H__
00025 #define __EXPR_LIST_H__
00026 
00027 #include <vector>
00028 
00029 BEGIN_NAMESPACE( classad )
00030 
00031 class ExprListIterator;
00032 
00034 class ExprList : public ExprTree
00035 {
00036         public:
00037                 ExprList();
00038                 ExprList(const std::vector<ExprTree*>& exprs);
00039 
00041         ExprList(const ExprList &other_list);
00042 
00044                 ~ExprList();
00045 
00046         ExprList &operator=(const ExprList &other_list);
00047 
00053                 static ExprList *MakeExprList( const std::vector< ExprTree* > &list );
00054 
00058                 void GetComponents( std::vector<ExprTree*>& list) const;
00059 
00060                 virtual ExprTree* Copy( ) const;
00061 
00062         bool CopyFrom(const ExprList &other_list);
00063 
00064         virtual bool SameAs(const ExprTree *tree) const;
00065 
00066         friend bool operator==(ExprList &list1, ExprList &list2);
00067 
00068                 // STL-like iterators and functions
00069             typedef std::vector<ExprTree*>::iterator       iterator;
00070         typedef std::vector<ExprTree*>::const_iterator const_iterator;
00071 
00072         int size()                   { return exprList.size();  }
00073         iterator begin()             { return exprList.begin(); }
00074                 iterator end()               { return exprList.end();   }
00075                 const_iterator begin() const { return exprList.begin(); }
00076                 const_iterator end() const   { return exprList.end();   }
00077 
00078                 void insert(iterator it, ExprTree* t);
00079                 void push_back(ExprTree* t);
00080                 void erase(iterator it);
00081                 void erase(iterator f, iterator l);
00082         
00083         private:
00084                 friend class ExprListIterator;
00085 
00086                 std::vector<ExprTree*> exprList;
00087 
00088                 void Clear (void);
00089                 virtual void _SetParentScope( const ClassAd* p );
00090                 virtual bool _Evaluate (EvalState &, Value &) const;
00091                 virtual bool _Evaluate (EvalState &, Value &, ExprTree *&) const;
00092                 virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00093         void CopyList(const vector<ExprTree*> &exprs);
00094 };
00095 
00096 
00098 class ExprListIterator
00099 {
00100         public:
00102                 ExprListIterator( );
00103 
00108                 ExprListIterator( const ExprList* l );
00109 
00111                 ~ExprListIterator( );
00112 
00121             void Initialize( const ExprList* l );
00122 
00124         void ToFirst( );
00125 
00127         void ToAfterLast( );
00128 
00135                 bool ToNth( int n );
00136 
00141         const ExprTree* NextExpr( );
00142 
00146         const ExprTree* CurrentExpr( ) const;
00147 
00152         const ExprTree* PrevExpr( );
00153     
00162         bool NextValue( Value& v, EvalState *es=NULL );
00163 
00171         bool CurrentValue( Value& v, EvalState *es=NULL );
00172 
00181         bool PrevValue( Value& v, EvalState *es=NULL  );
00182 
00193         bool NextValue( Value& v, ExprTree*& t, EvalState *es=NULL );
00194 
00204         bool CurrentValue( Value& v, ExprTree*& t, EvalState *es=NULL );
00205 
00216         bool PrevValue( Value& v, ExprTree*& t, EvalState *es=NULL  );
00217 
00221         bool IsAtFirst( ) const;
00222 
00226         bool IsAfterLast( ) const;
00227 
00228         private:
00229                 const ExprList                          *l;
00230                 EvalState                               state;
00231                 std::vector<ExprTree*>::const_iterator  itr;
00232 
00233         bool GetValue( Value& v, const ExprTree *tree, EvalState *es=NULL );
00234                 bool GetValue( Value& v, ExprTree*& t, const ExprTree *tree, EvalState *es=NULL );
00235 
00236 };      
00237 
00238 
00239 END_NAMESPACE // classad
00240 
00241 #endif//__EXPR_LIST_H__