00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __CLASSAD_H__
00025 #define __CLASSAD_H__
00026
00027
00028 #include <set>
00029 #include <map>
00030 #include <vector>
00031 #include "classad_stl.h"
00032 #include "exprTree.h"
00033
00034 BEGIN_NAMESPACE( classad )
00035
00036 typedef std::set<std::string, CaseIgnLTStr> References;
00037 typedef std::map<const ClassAd*, References> PortReferences;
00038
00039 #if defined( EXPERIMENTAL )
00040 #include "rectangle.h"
00041 #endif
00042
00043 #ifdef CLASSAD_DEPRECATED
00044 #include "stream.h"
00045 #endif
00046
00047 typedef classad_hash_map<std::string, ExprTree*, StringCaseIgnHash, CaseIgnEqStr> AttrList;
00048 typedef std::set<std::string, CaseIgnLTStr> DirtyAttrList;
00049
00050 void ClassAdLibraryVersion(int &major, int &minor, int &patch);
00051 void ClassAdLibraryVersion(std::string &version_string);
00052
00054 class ClassAd : public ExprTree
00055 {
00067 public:
00070
00071 ClassAd ();
00072
00075 ClassAd (const ClassAd &ad);
00076
00078 ~ClassAd ();
00080
00090 bool Insert( const std::string &attrName, ExprTree *expr );
00091
00102 bool DeepInsert( ExprTree *scopeExpr, const std::string &attrName,
00103 ExprTree *expr );
00104
00113 bool InsertAttr( const std::string &attrName,int value,
00114 Value::NumberFactor f=Value::NO_FACTOR );
00115
00127 bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00128 int value, Value::NumberFactor f=Value::NO_FACTOR );
00129
00139 bool InsertAttr( const std::string &attrName,double value,
00140 Value::NumberFactor f=Value::NO_FACTOR);
00141
00154 bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00155 double value, Value::NumberFactor f=Value::NO_FACTOR);
00156
00163 bool InsertAttr( const std::string &attrName, bool value );
00164
00175 bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00176 bool value );
00177
00184 bool InsertAttr( const std::string &attrName, const char *value );
00185
00195 bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00196 const char *value );
00197
00204 bool InsertAttr( const std::string &attrName, const std::string &value );
00205
00215 bool DeepInsertAttr( ExprTree *scopeExpr, const std::string &attrName,
00216 const std::string &value );
00218
00227 ExprTree *Lookup( const std::string &attrName ) const;
00228
00240 ExprTree *LookupInScope(const std::string &attrName,const ClassAd *&ad)const;
00242
00246 void Clear( );
00247
00255 bool Delete( const std::string &attrName );
00256
00267 bool DeepDelete( const std::string &scopeExpr, const std::string &attrName );
00268
00279 bool DeepDelete( ExprTree *scopeExpr, const std::string &attrName );
00280
00288 ExprTree *Remove( const std::string &attrName );
00289
00298 ExprTree *DeepRemove( const std::string &scopeExpr, const std::string &attrName );
00299
00308 ExprTree *DeepRemove( ExprTree *scopeExpr, const std::string &attrName );
00310
00317 bool EvaluateAttr( const std::string& attrName, Value &result ) const;
00318
00326 bool EvaluateExpr( const std::string& buf, Value &result ) const;
00327
00334 bool EvaluateExpr( const ExprTree* expr, Value &result ) const;
00335
00344 bool EvaluateExpr( const ExprTree* expr, Value &result, ExprTree *&sig) const;
00345
00351 bool EvaluateAttrInt( const std::string &attr, int& intValue ) const;
00352
00358 bool EvaluateAttrReal( const std::string &attr, double& realValue )const;
00359
00366 bool EvaluateAttrNumber( const std::string &attr, int& intValue ) const;
00367
00374 bool EvaluateAttrNumber(const std::string &attr,double& realValue) const;
00375
00384 bool EvaluateAttrString( const std::string &attr, char *buf, int len)
00385 const;
00386
00394 bool EvaluateAttrString( const std::string &attr, std::string &buf ) const;
00395
00403 bool EvaluateAttrBool( const std::string &attr, bool& boolValue ) const;
00404
00412 bool EvaluateAttrClassAd( const std::string &attr, ClassAd *&classad ) const;
00413
00421 bool EvaluateAttrList( const std::string &attr, ExprList *&l ) const;
00423
00426
00428 typedef AttrList::iterator iterator;
00429
00431 typedef AttrList::const_iterator const_iterator;
00432
00435 iterator begin() { return attrList.begin(); }
00436
00439 const_iterator begin() const { return attrList.begin(); }
00440
00443 iterator end() { return attrList.end(); }
00444
00447 const_iterator end() const { return attrList.end(); }
00448
00451 iterator find(std::string const& attrName);
00452
00455 const_iterator find(std::string const& attrName) const;
00456
00459 int size(void) const { return attrList.size(); }
00461
00468 static ClassAd *MakeClassAd( std::vector< std::pair< std::string, ExprTree* > > &vec );
00469
00474 void GetComponents( std::vector< std::pair< std::string, ExprTree *> > &vec ) const;
00475
00482 void Update( const ClassAd& ad );
00483
00492 void Modify( ClassAd& ad );
00493
00497 virtual ExprTree* Copy( ) const;
00498
00501 ClassAd &operator=(const ClassAd &rhs);
00502
00507 bool CopyFrom( const ClassAd &ad );
00508
00515 virtual bool SameAs(const ExprTree *tree) const;
00516
00521 friend bool operator==(ClassAd &list1, ClassAd &list2);
00522
00533 bool Flatten( const ExprTree* expr, Value& val, ExprTree *&fexpr )const;
00534
00535 bool FlattenAndInline( const ExprTree* expr, Value& val,
00536 ExprTree *&fexpr )const;
00537
00546 bool GetExternalReferences( const ExprTree *tree, References &refs, bool fullNames );
00547
00555 bool GetExternalReferences(const ExprTree *tree, PortReferences &refs);
00557
00558 #if defined( EXPERIMENTAL )
00559 bool AddRectangle( const ExprTree *tree, Rectangles &r,
00560 const std::string &allowed, const References &imported );
00561 #endif
00562
00563 #if defined( CLASSAD_DEPRECATED )
00564
00569 int Insert(const char *str);
00573 int InsertOrUpdate(const char *expr) { return Insert(expr); }
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00592 int LookupString(const char *name, char *value) const;
00599 int LookupString(const char *name, char *value, int max_len) const;
00605 int LookupString (const char *name, char **value) const;
00611 int LookupInteger(const char *name, int &value) const;
00617 int LookupFloat(const char *name, float &value) const;
00623 int LookupBool(const char *name, int &value) const;
00629 int LookupBool(const char *name, bool &value) const;
00630
00638 int EvalString (const char *name, class ClassAd *target, char *value);
00646 int EvalInteger (const char *name, class ClassAd *target, int &value);
00654 int EvalFloat (const char *name, class ClassAd *target, float &value);
00662 int EvalBool (const char *name, class ClassAd *target, int &value);
00663
00665 ClassAd(FILE*,char*,int&,int&,int&);
00666
00668 void SetMyTypeName(const char *);
00670 const char* GetMyTypeName();
00672 void SetTargetTypeName(const char *);
00674 const char* GetTargetTypeName();
00675
00679 int put(Stream& s);
00680
00684 int initFromStream(Stream& s);
00685
00690 virtual int fPrint(FILE *file);
00691
00695 void dPrint( int level);
00696
00697 bool AddExplicitConditionals( ExprTree *expr, ExprTree *&newExpr );
00698 ClassAd *AddExplicitTargetRefs( );
00700 #endif
00701
00714 void ChainToAd(ClassAd *new_chain_parent_ad);
00717 void Unchain(void);
00719
00727 void EnableDirtyTracking(void) { do_dirty_tracking = true; }
00730 void DisableDirtyTracking(void) { do_dirty_tracking = false; }
00733 void ClearAllDirtyFlags(void);
00737 void MarkAttributeDirty(const std::string &name);
00741 void MarkAttributeClean(const std::string &name);
00746 bool IsAttributeDirty(const std::string &name);
00747
00748 typedef DirtyAttrList::iterator dirtyIterator;
00752 dirtyIterator dirtyBegin() { return dirtyAttrList.begin(); }
00755 dirtyIterator dirtyEnd() { return dirtyAttrList.end(); }
00757
00758 private:
00759 friend class AttributeReference;
00760 friend class ExprTree;
00761 friend class EvalState;
00762 friend class ClassAdIterator;
00763
00764 bool _GetExternalReferences( const ExprTree *, ClassAd *,
00765 EvalState &, References&, bool fullNames );
00766
00767 bool _GetExternalReferences( const ExprTree *, ClassAd *,
00768 EvalState &, PortReferences& );
00769 #if defined( EXPERIMENTAL )
00770 bool _MakeRectangles(const ExprTree*,const std::string&,Rectangles&, bool);
00771 bool _CheckRef( ExprTree *, const std::string & );
00772 #endif
00773
00774 #if defined( CLASSAD_DEPRECATED )
00775 void evalFromEnvironment( const char *name, Value val );
00776 ExprTree *AddExplicitConditionals( ExprTree * );
00777 ExprTree *AddExplicitTargetRefs( ExprTree *,
00778 std::set < std::string, CaseIgnLTStr > & );
00779 #endif
00780
00781 ClassAd *_GetDeepScope( const std::string& ) const;
00782 ClassAd *_GetDeepScope( ExprTree * ) const;
00783
00784 virtual void _SetParentScope( const ClassAd* p );
00785 virtual bool _Evaluate( EvalState& , Value& ) const;
00786 virtual bool _Evaluate( EvalState&, Value&, ExprTree*& ) const;
00787 virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00788
00789 int LookupInScope( const std::string&, ExprTree*&, EvalState& ) const;
00790 AttrList attrList;
00791 DirtyAttrList dirtyAttrList;
00792 bool do_dirty_tracking;
00793 ClassAd *chained_parent_ad;
00794 };
00795
00796 END_NAMESPACE
00797
00798 #include "classadItor.h"
00799
00800 #endif//__CLASSAD_H__