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

classad.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 __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; // eval'n
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,        // NAC
00536                                                            ExprTree *&fexpr )const;                             // NAC
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                 // for iteration through expressions
00576 //              void            ResetExpr();
00577 //              ExprTree*       NextExpr();
00578 
00579                 // for iteration through names (i.e., lhs of the expressions)
00580 //              void            ResetName() { this->ptrName = exprList; }
00581 //              const char* NextNameOriginal();
00582 
00583                 // lookup values in classads  (for simple assignments)
00584 //              ExprTree*   Lookup(char *) const;               // for convenience
00585 //      ExprTree*       Lookup(const char*) const;      // look up an expression
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&);    // Constructor, read from file.
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 // classad
00797 
00798 #include "classadItor.h"
00799 
00800 #endif//__CLASSAD_H__