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

view.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 __VIEW_H__
00025 #define __VIEW_H__
00026 
00027 // STL includes
00028 #include <string>
00029 #include <set>
00030 
00031 #include "classad_stl.h"
00032 #include "exprTree.h"
00033 #include "matchClassad.h"
00034 
00035 BEGIN_NAMESPACE( classad )
00036 
00037         // class declarations
00038 class ExprTree;
00039 class ClassAd;
00040 class View;
00041 class ClassAdCollection;
00042 class ClassAdCollectionServer;
00043 
00044 
00045 class ViewMember {
00046 public:
00047         ViewMember( );
00048         ViewMember(const ViewMember &other);
00049         ~ViewMember( );
00050 
00051         void SetKey( const std::string &key );
00052         void SetRankValue( const Value &rankValue );
00053 
00054         void GetKey( std::string &key ) const;
00055         void GetRankValue( Value &rankValue ) const;
00056 
00057         ViewMember      operator=( const ViewMember& );
00058         friend bool operator<(const ViewMember &vm1, const ViewMember &vm2);
00059 private:
00060         std::string     key;
00061         Value   rank;
00062 };
00063 
00064 
00065 struct ViewMemberLT {
00066         bool operator()( const ViewMember &vm1, const ViewMember &vm2 ) const;
00067 };
00068 
00069 
00070 typedef std::string ViewName;
00071 typedef std::multiset<ViewMember, ViewMemberLT> ViewMembers;
00072 typedef classad_slist<View*> SubordinateViews;
00073 typedef classad_hash_map<std::string,View*,StringHash> PartitionedViews;
00074 typedef classad_hash_map<std::string,ViewMembers::iterator,StringHash> MemberIndex;
00075 
00076 
00077 /* View class */
00078 class View {
00079 public:
00080         View( View *parent );
00081         ~View( );
00082 
00083                 // view control
00084         bool SetViewName( const ViewName &viewName );
00085         bool SetConstraintExpr( ClassAdCollection *coll,
00086                         const std::string &constraint );
00087         bool SetConstraintExpr( ClassAdCollection *coll,
00088                         ExprTree *constraint );
00089         bool SetRankExpr( ClassAdCollection *coll, const std::string &expr );
00090         bool SetRankExpr( ClassAdCollection *coll, ExprTree *tree );
00091         bool SetPartitionExprs( ClassAdCollection *coll, 
00092                         const std::string &exprList );
00093         bool SetPartitionExprs( ClassAdCollection *coll, ExprList *el );
00094         bool SetViewInfo( ClassAdCollection *coll, ClassAd *viewInfo );
00095 
00096                 // view interrogation
00097         inline ViewName GetViewName( ) const { return( viewName ); }
00098         inline View     *GetParent( ) const { return parent; }
00099         inline int      Size( ) const { return( viewMembers.size( ) ); }
00100         ExprTree        *GetConstraintExpr( );
00101         ExprTree        *GetRankExpr( );
00102         ExprList        *GetPartitionAttributes( );
00103         ClassAd         *GetViewInfo( );
00104         bool            IsMember( const std::string &key );
00105         void            GetSubordinateViewNames( std::vector<std::string>& );
00106         void            GetPartitionedViewNames( std::vector<std::string>& );
00107         bool            FindPartition( ClassAd *rep, ViewName &partition );
00108 
00109                 // child view manipulation
00110         bool InsertSubordinateView( ClassAdCollection *coll, ClassAd *vInfo );
00111         bool InsertPartitionedView( ClassAdCollection *coll, ClassAd *vInfo, 
00112                         ClassAd *rep );
00113         bool DeleteChildView( ClassAdCollection *coll,
00114                         const ViewName &viewName );
00115         bool DeleteSubordinateView( ClassAdCollection *coll,
00116                         const ViewName &viewName );
00117         bool DeletePartitionedView( ClassAdCollection *coll,
00118                         const ViewName &viewName );
00119         bool DeletePartitionedView( ClassAdCollection *coll, ClassAd *rep );
00120                         
00121                 // classad manipulation
00122         bool ClassAdInserted ( ClassAdCollection *coll, 
00123                         const std::string &key, ClassAd *ad );
00124         void ClassAdPreModify( ClassAdCollection *coll, ClassAd *ad );
00125         bool ClassAdModified ( ClassAdCollection *coll, 
00126                         const std::string &key, ClassAd *ad );
00127         void ClassAdDeleted  ( ClassAdCollection *coll, 
00128                         const std::string &key, ClassAd *ad );
00129 
00130                 // misc
00131         bool Display( FILE * );
00132 
00134         typedef ViewMembers::iterator iterator;
00135 
00137         typedef ViewMembers::const_iterator const_iterator;
00138 
00141         iterator begin() { return viewMembers.begin(); }
00142 
00145         const_iterator begin() const { return viewMembers.begin(); }
00146         
00149         iterator end() { return viewMembers.end(); }
00150         
00153         const_iterator end() const { return viewMembers.end(); }
00154 
00155 private:
00156         friend class ClassAdCollection;
00157         friend class ClassAdCollectionServer;
00158         friend class LocalCollectionQuery;
00159 
00160                 // private helper function
00161         std::string makePartitionSignature( ClassAd *ad );
00162         void        DeleteView( ClassAdCollection * );
00163 
00164         ViewName                        viewName;                       // name of the view
00165         View                            *parent;                        // pointer to parent view
00166         ViewMembers                     viewMembers;            // the classads in this view
00167         MemberIndex                     memberIndex;            // keys->ViewMember mapping
00168         PartitionedViews        partitionedViews;       // views created by partitioning
00169         SubordinateViews        subordinateViews;       // views explicitly added
00170         std::string                     oldAdSignature;         // old signature of ad to be changed
00171         MatchClassAd            evalEnviron;            // also stores view info
00172 };
00173 
00174 END_NAMESPACE
00175 
00176 #endif // VIEW_H