00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef __CLASSAD_CLASSAD_H__
00022 #define __CLASSAD_CLASSAD_H__
00023 
00024 
00025 #include <set>
00026 #include <map>
00027 #include <vector>
00028 #include "classad/classad_stl.h"
00029 #include "classad/exprTree.h"
00030 
00031 BEGIN_NAMESPACE( classad )
00032 
00033 typedef std::set<std::string, CaseIgnLTStr> References;
00034 typedef std::map<const ClassAd*, References> PortReferences;
00035 
00036 #if defined( EXPERIMENTAL )
00037 #include "classad/rectangle.h"
00038 #endif
00039 
00040 #ifdef WIN32
00041 typedef classad_hash_map<std::string, ExprTree*, StringCaseIgnHash> AttrList;
00042 #else
00043 typedef classad_hash_map<std::string, ExprTree*, StringCaseIgnHash, CaseIgnEqStr> AttrList;
00044 #endif
00045 typedef std::set<std::string, CaseIgnLTStr> DirtyAttrList;
00046 
00047 void ClassAdLibraryVersion(int &major, int &minor, int &patch);
00048 void ClassAdLibraryVersion(std::string &version_string);
00049 
00050 
00051 
00052 
00053 extern bool _useOldClassAdSemantics;
00054 
00056 class ClassAd : public ExprTree
00057 {
00069     public:
00072 
00073         ClassAd ();
00074 
00078         ClassAd (const ClassAd &ad);
00079 
00081         virtual ~ClassAd ();
00083 
00093         bool Insert( const std::string &attrName, ExprTree *expr );
00094 
00105         bool DeepInsert( ExprTree *scopeExpr, const std::string &attrName, 
00106                 ExprTree *expr );
00107 
00116         bool InsertAttr( const std::string &attrName,int value, 
00117                 Value::NumberFactor f=Value::NO_FACTOR );
00118 
00130         bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00131                 int value, Value::NumberFactor f=Value::NO_FACTOR );
00132 
00142         bool InsertAttr( const std::string &attrName,double value, 
00143                 Value::NumberFactor f=Value::NO_FACTOR);
00144 
00157         bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00158                 double value, Value::NumberFactor f=Value::NO_FACTOR);
00159 
00166         bool InsertAttr( const std::string &attrName, bool value );
00167 
00178         bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName, 
00179                 bool value );
00180 
00187         bool InsertAttr( const std::string &attrName, const char *value );
00188 
00198         bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName, 
00199                 const char *value );
00200 
00207         bool InsertAttr( const std::string &attrName, const std::string &value );
00208 
00218         bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName, 
00219                 const std::string &value );
00221 
00230         ExprTree *Lookup( const std::string &attrName ) const;
00231 
00243         ExprTree *LookupInScope(const std::string &attrName,const ClassAd *&ad)const;
00245 
00249         void Clear( );
00250 
00258         bool Delete( const std::string &attrName );
00259 
00270         bool DeepDelete( const std::string &scopeExpr, const std::string &attrName );
00271 
00282         bool DeepDelete( ExprTree *scopeExpr, const std::string &attrName );
00283     
00291         ExprTree *Remove( const std::string &attrName );
00292 
00301         ExprTree *DeepRemove( const std::string &scopeExpr, const std::string &attrName );
00302 
00311         ExprTree *DeepRemove( ExprTree *scopeExpr, const std::string &attrName );
00313 
00320         bool EvaluateAttr( const std::string& attrName, Value &result ) const;
00321 
00329         bool EvaluateExpr( const std::string& buf, Value &result ) const;
00330 
00337         bool EvaluateExpr( const ExprTree* expr, Value &result ) const; 
00338 
00347         bool EvaluateExpr( const ExprTree* expr, Value &result, ExprTree *&sig) const;
00348 
00354         bool EvaluateAttrInt( const std::string &attr, int& intValue ) const;
00355 
00361         bool EvaluateAttrReal( const std::string &attr, double& realValue )const;
00362 
00369         bool EvaluateAttrNumber( const std::string &attr, int& intValue ) const;
00370 
00377         bool EvaluateAttrNumber(const std::string &attr,double& realValue) const;
00378 
00387         bool EvaluateAttrString( const std::string &attr, char *buf, int len) 
00388                 const;
00389 
00397         bool EvaluateAttrString( const std::string &attr, std::string &buf ) const;
00398 
00406         bool EvaluateAttrBool( const std::string &attr, bool& boolValue ) const;
00407 
00415         bool EvaluateAttrClassAd( const std::string &attr, ClassAd *&classad ) const;
00416 
00424         bool EvaluateAttrList( const std::string &attr, ExprList *&l ) const;
00426 
00429 
00431         typedef AttrList::iterator iterator;
00432 
00434         typedef AttrList::const_iterator const_iterator;
00435 
00438         iterator begin() { return attrList.begin(); }
00439 
00442         const_iterator begin() const { return attrList.begin(); }
00443 
00446         iterator end() { return attrList.end(); }
00447 
00450         const_iterator end() const { return attrList.end(); }
00451 
00454         iterator find(std::string const& attrName);
00455 
00458         const_iterator find(std::string const& attrName) const;
00459 
00462         int size(void) const { return attrList.size(); }
00464 
00471         static ClassAd *MakeClassAd( std::vector< std::pair< std::string, ExprTree* > > &vec );
00472 
00477         void GetComponents( std::vector< std::pair< std::string, ExprTree *> > &vec ) const;
00478 
00485         bool Update( const ClassAd& ad );   
00486 
00495         void Modify( ClassAd& ad );
00496 
00500         virtual ExprTree* Copy( ) const;
00501 
00504         ClassAd &operator=(const ClassAd &rhs);
00505 
00510         bool CopyFrom( const ClassAd &ad );
00511 
00518         virtual bool SameAs(const ExprTree *tree) const;
00519 
00524         friend bool operator==(ClassAd &list1, ClassAd &list2);
00525 
00536         bool Flatten( const ExprTree* expr, Value& val, ExprTree *&fexpr )const;
00537 
00538         bool FlattenAndInline( const ExprTree* expr, Value& val,    
00539                                ExprTree *&fexpr )const;             
00540         
00549         bool GetExternalReferences( const ExprTree *tree, References &refs, bool fullNames );
00550 
00558         bool GetExternalReferences(const ExprTree *tree, PortReferences &refs);
00560 
00561 
00570         bool GetInternalReferences( const ExprTree *tree, References &refs, bool fullNames);
00571 
00572 #if defined( EXPERIMENTAL )
00573         bool AddRectangle( const ExprTree *tree, Rectangles &r, 
00574                     const std::string &allowed, const References &imported );
00575 #endif
00576 
00589         void        ChainToAd(ClassAd *new_chain_parent_ad);
00592         void        Unchain(void);
00593 
00596         ClassAd *   GetChainedParentAd(void);
00597 
00603         bool CopyFromChain( const ClassAd &ad );
00604 
00610         bool UpdateFromChain( const ClassAd &ad );
00612 
00620         void        EnableDirtyTracking(void)  { do_dirty_tracking = true;  }
00623         void        DisableDirtyTracking(void) { do_dirty_tracking = false; }
00626         void        ClearAllDirtyFlags(void);
00630         void        MarkAttributeDirty(const std::string &name);
00634         void        MarkAttributeClean(const std::string &name);
00639         bool        IsAttributeDirty(const std::string &name);
00640 
00641         typedef DirtyAttrList::iterator dirtyIterator;
00645         dirtyIterator dirtyBegin() { return dirtyAttrList.begin(); }
00648         dirtyIterator dirtyEnd() { return dirtyAttrList.end(); }
00650 
00651         
00652 
00653 
00654 
00655 
00656 
00657 
00658         ClassAd *alternateScope;
00659 
00660     private:
00661         friend  class AttributeReference;
00662         friend  class ExprTree;
00663         friend  class EvalState;
00664         friend  class ClassAdIterator;
00665 
00666         bool _GetExternalReferences( const ExprTree *, ClassAd *, 
00667                     EvalState &, References&, bool fullNames );
00668 
00669         bool _GetExternalReferences( const ExprTree *, ClassAd *, 
00670                     EvalState &, PortReferences& );
00671 
00672         bool _GetInternalReferences(const ExprTree *expr, ClassAd *ad,
00673             EvalState &state, References& refs, bool fullNames);
00674 #if defined( EXPERIMENTAL )
00675         bool _MakeRectangles(const ExprTree*,const std::string&,Rectangles&, bool);
00676         bool _CheckRef( ExprTree *, const std::string & );
00677 #endif
00678 
00679         ClassAd *_GetDeepScope( const std::string& ) const;
00680         ClassAd *_GetDeepScope( ExprTree * ) const;
00681 
00682         virtual void _SetParentScope( const ClassAd* p );
00683         virtual bool _Evaluate( EvalState& , Value& ) const;
00684         virtual bool _Evaluate( EvalState&, Value&, ExprTree*& ) const;
00685         virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00686     
00687         int LookupInScope( const std::string&, ExprTree*&, EvalState& ) const;
00688         AttrList      attrList;
00689         DirtyAttrList dirtyAttrList;
00690         bool          do_dirty_tracking;
00691         ClassAd       *chained_parent_ad;
00692 };
00693 
00694 END_NAMESPACE 
00695 
00696 #include "classad/classadItor.h"
00697 
00698 #endif//__CLASSAD_CLASSAD_H__