Sierra Toolkit Version of the Day
Selector.hpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #ifndef stk_mesh_Selector_hpp
00011 #define stk_mesh_Selector_hpp
00012 
00013 #include <iosfwd>
00014 #include <stk_mesh/base/Types.hpp>
00015 
00016 namespace stk {
00017 namespace mesh {
00018 
00019 enum Op{
00020         INVALID = 0,
00021         COMPOUND = 1,
00022         PART_ID = 2
00023        };
00024 
00025 struct OpType {
00026   unsigned       m_part_id ; 
00027   unsigned short m_unary ;   
00028   unsigned short m_count ;   
00029   Op             m_op      ; 
00030 
00031   OpType() : m_part_id(0), m_unary(0), m_count(0), m_op(INVALID) {}
00032   OpType( unsigned part_id , unsigned unary , unsigned count, Op op=INVALID )
00033     : m_part_id( part_id ), m_unary( unary ), m_count( count ), m_op(op)  {}
00034   OpType( const OpType & opType )
00035     : m_part_id(opType.m_part_id), m_unary(opType.m_unary), m_count(opType.m_count), m_op(opType.m_op) {}
00036   OpType & operator = ( const OpType & opType )
00037   { this->m_part_id = opType.m_part_id;
00038     this->m_unary = opType.m_unary;
00039     this->m_count = opType.m_count;
00040     this->m_op    = opType.m_op;
00041     return *this;
00042   }
00043 };
00044 
00063 class Selector {
00064 public:
00066   ~Selector();
00067 
00069   Selector();
00070 
00072   Selector( const Selector & selector);
00073 
00075   Selector & operator = ( const Selector & B );
00076 
00078   Selector( const Part & part);
00079 
00081   Selector & operator &= ( const Selector & selector);
00082 
00084   Selector & operator |= ( const Selector & selector);
00085 
00089   Selector & complement();
00090 
00092   Selector operator ! () const
00093     { Selector S( *this ); return S.complement(); }
00094 
00098   bool operator()( const Bucket & candidate ) const ;
00099 
00103   bool operator()( const Bucket * candidate ) const{
00104     return operator()(*candidate);
00105   }
00106 
00110   bool operator()( const Entity & candidate ) const ;
00111 
00113   friend std::ostream & operator << ( std::ostream & out, const Selector & selector);
00114 
00115   const std::vector<OpType>& get_ops() const { return m_op; }
00116   void set_ops(const std::vector<OpType>& ops) { m_op = ops; }
00117 
00118 private:
00119 
00121   friend class std::vector<OpType> ;
00122 
00124   const MetaData * m_mesh_meta_data ;
00125 
00127   std::vector< OpType > m_op ;
00128 
00130   void verify_compatible( const Selector & B ) const;
00131 
00133   void verify_compatible( const Bucket & B ) const;
00134 
00136   bool apply(
00137       unsigned part_id ,
00138       const Bucket & candidate
00139       ) const;
00140 
00142   bool apply(
00143       std::vector<OpType>::const_iterator start,
00144       std::vector<OpType>::const_iterator finish,
00145       const Bucket & candidate
00146       ) const;
00147 
00149   void compoundAll();
00150 
00152   std::string printExpression(
00153       const std::vector<OpType>::const_iterator start,
00154       const std::vector<OpType>::const_iterator finish
00155       ) const;
00156 
00157 };
00158 
00162 Selector operator & ( const Part & A , const Part & B );
00163 
00167 Selector operator & ( const Part & A , const Selector & B );
00168 
00172 Selector operator & ( const Selector & A, const Part & B );
00173 
00177 Selector operator & ( const Selector & A, const Selector & B );
00178 
00182 Selector operator | ( const Part & A , const Part & B );
00183 
00187 Selector operator | ( const Part & A , const Selector & B );
00188 
00192 Selector operator | ( const Selector & A, const Part & B  );
00193 
00197 Selector operator | ( const Selector & A , const Selector & B );
00198 
00202 Selector operator ! ( const Part & A );
00203 
00204 
00208 Selector selectUnion( const PartVector& union_part_vector );
00209 
00213 Selector selectIntersection( const PartVector& intersection_part_vector );
00214 
00218 Selector selectField( const FieldBase& field );
00219 
00222 } // namespace mesh
00223 } // namespace stk
00224 
00225 #endif // stk_mesh_Selector_hpp
00226 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends