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