exprList.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  ***************************************************************/
00019 
00020 
00021 #ifndef __CLASSAD_EXPR_LIST_H__
00022 #define __CLASSAD_EXPR_LIST_H__
00023 
00024 #include <vector>
00025 
00026 BEGIN_NAMESPACE( classad )
00027 
00028 class ExprListIterator;
00029 
00031 class ExprList : public ExprTree
00032 {
00033     public:
00034         ExprList();
00035         ExprList(const std::vector<ExprTree*>& exprs);
00036 
00038         ExprList(const ExprList &other_list);
00039 
00041         virtual ~ExprList();
00042 
00043         ExprList &operator=(const ExprList &other_list);
00044 
00050         static ExprList *MakeExprList( const std::vector< ExprTree* > &list );
00051 
00055         void GetComponents( std::vector<ExprTree*>& list) const;
00056 
00057         virtual ExprTree* Copy( ) const;
00058 
00059         bool CopyFrom(const ExprList &other_list);
00060 
00061         virtual bool SameAs(const ExprTree *tree) const;
00062 
00063         friend bool operator==(ExprList &list1, ExprList &list2);
00064 
00065         // STL-like iterators and functions
00066         typedef std::vector<ExprTree*>::iterator       iterator;
00067         typedef std::vector<ExprTree*>::const_iterator const_iterator;
00068 
00069         int size() const             { return exprList.size();  }
00070         iterator begin()             { return exprList.begin(); }
00071         iterator end()               { return exprList.end();   }
00072         const_iterator begin() const { return exprList.begin(); }
00073         const_iterator end() const   { return exprList.end();   }
00074 
00075         void insert(iterator it, ExprTree* t);
00076         void push_back(ExprTree* t);
00077         void erase(iterator it);
00078         void erase(iterator f, iterator l);
00079     
00080     private:
00081         friend class ExprListIterator;
00082 
00083         std::vector<ExprTree*> exprList;
00084 
00085         void Clear (void);
00086         virtual void _SetParentScope( const ClassAd* p );
00087         virtual bool _Evaluate (EvalState &, Value &) const;
00088         virtual bool _Evaluate (EvalState &, Value &, ExprTree *&) const;
00089         virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00090         void CopyList(const std::vector<ExprTree*> &exprs);
00091 };
00092 
00093 
00095 class ExprListIterator
00096 {
00097     public:
00099         ExprListIterator( );
00100 
00105         ExprListIterator( const ExprList* l );
00106 
00108         ~ExprListIterator( );
00109 
00118         void Initialize( const ExprList* l );
00119 
00121         void ToFirst( );
00122 
00124         void ToAfterLast( );
00125 
00132         bool ToNth( int n );
00133 
00138         const ExprTree* NextExpr( );
00139 
00143         const ExprTree* CurrentExpr( ) const;
00144 
00149         const ExprTree* PrevExpr( );
00150     
00159         bool NextValue( Value& v, EvalState *es=NULL );
00160 
00168         bool CurrentValue( Value& v, EvalState *es=NULL );
00169 
00178         bool PrevValue( Value& v, EvalState *es=NULL  );
00179 
00190         bool NextValue( Value& v, ExprTree*& t, EvalState *es=NULL );
00191 
00201         bool CurrentValue( Value& v, ExprTree*& t, EvalState *es=NULL );
00202 
00213         bool PrevValue( Value& v, ExprTree*& t, EvalState *es=NULL  );
00214 
00218         bool IsAtFirst( ) const;
00219 
00223         bool IsAfterLast( ) const;
00224 
00225     private:
00226         const ExprList                          *l;
00227         EvalState                               state;
00228         std::vector<ExprTree*>::const_iterator  itr;
00229 
00230         bool GetValue( Value& v, const ExprTree *tree, EvalState *es=NULL );
00231         bool GetValue( Value& v, ExprTree*& t, const ExprTree *tree, EvalState *es=NULL );
00232 
00233 };  
00234 
00235 
00236 END_NAMESPACE // classad
00237 
00238 #endif//__CLASSAD_EXPR_LIST_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends