Sierra Toolkit Version of the Day
Transaction.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_Transaction_hpp
00011 #define stk_mesh_Transaction_hpp
00012 
00013 
00014 #include <set>
00015 #include <vector>
00016 #include <iosfwd>
00017 
00018 
00019 namespace stk{
00020 namespace mesh {
00021 
00022 class Bucket;
00023 class BulkData;
00024 class Entity;
00025 class Part;
00026 
00027 
00033 //----------------------------------------------------------------------
00043 class Transaction
00044 {
00045   public:
00046     /* \brief The following are the variable type and valid values for
00047      * defining the type of transaction bucket.
00048      */
00049     typedef unsigned char                State;
00050     enum { NOT_IN_TRANSACTION = 0 , MODIFIED = 1, INSERTED = 2, DELETED = 3 };
00051 
00052     /* \brief There are two different types of transactions:
00053      * incremental and bulk.  This can be set when reseting a
00054      * transaction.
00055      */
00056     enum TransactionType { INCREMENTAL = 1 , BULK = 2 };
00057 
00058   public:
00062     typedef std::vector<Bucket *>                 BucketList;
00063 
00067     typedef std::vector<BucketList>               BucketListByType;
00068 
00071     typedef std::set<Part *>                      PartSet;
00072 
00073 
00076     std::ostream & print_stream ( std::ostream &os ) const;
00077 
00081     const BucketList & get_modified_buckets ( unsigned type ) const { return m_modified[type]; }
00082 
00083 
00084 
00088     const BucketList & get_deleted_buckets ( unsigned type ) const { return m_deleted[type]; }
00089 
00093     const BucketList & get_inserted_buckets ( unsigned type ) const { return m_inserted[type]; }
00094 
00095 
00099     void get_parts_with_modified_entities ( PartVector &pv ) const
00100     {
00101       translate_partset_to_partvector ( m_modified_parts , pv );
00102     }
00103 
00107     void get_parts_with_deleted_entities ( PartVector &pv ) const
00108     {
00109       translate_partset_to_partvector ( m_deleted_parts , pv );
00110     }
00111 
00115     void get_parts_with_inserted_entities ( PartVector &pv ) const
00116     {
00117       translate_partset_to_partvector ( m_inserted_parts , pv );
00118     }
00119 
00120   private:
00121 
00124     void      print_proc_transaction ( unsigned , std::ostream & ) const;
00127     void  print_transaction ( unsigned , std::ostream & ) const;
00130     void  print_bucket_list ( const BucketList & , std::ostream & ) const;
00131 
00132     Transaction ();
00133     Transaction ( BulkData & , TransactionType );
00134     Transaction & operator = ( const Transaction & );
00135    ~Transaction ();
00136 
00143     void allocate_bucket_lists ();
00144 
00145     TransactionType     m_transaction_type;
00146 
00147     BulkData           &m_bulk_data;
00148     BucketListByType    m_modified;
00149     BucketListByType    m_deleted;
00150     BucketListByType    m_inserted;
00151 
00152     PartSet            m_modified_parts;
00153     PartSet            m_deleted_parts;
00154     PartSet            m_inserted_parts;
00155 
00156     std::set<Entity *>   m_to_delete;
00157 
00158 
00159     void   flush_deletes ();
00160 
00165     void   reset ( TransactionType type = BULK );
00166     void   flush ();
00167 
00168 
00172     void   modify_sole_entity ( Entity &e );
00173 
00178     void   modify_entity ( Entity & e );
00179 
00183     void   insert_entity ( Entity & e );
00184 
00188     void   delete_entity ( Entity & e );
00189 
00192     void   purge_map ( BucketListByType & );
00193 
00196     void   purge_and_erase_map ( BucketListByType & );
00197 
00202     Bucket *get_unfilled_transaction_bucket ( const unsigned *const , EntityRank , BucketList & , State );
00203 
00209     template <class ENTITY>
00210     Bucket *get_unfilled_transaction_bucket ( const ENTITY &e , BucketList &bm , State s )
00211      { return get_unfilled_transaction_bucket ( e.bucket().key() , e.entity_rank() , bm , s ); }
00212 
00215     void   add_entity_to_transaction_bucket ( Entity & , Bucket * );
00216 
00220     void   swap_entity_between_transaction_buckets ( Entity & , BucketList & , BucketList & , State );
00221 
00225     void   remove_entity_from_bucket ( Entity & , BucketList & );
00226 
00227 
00232     void   add_parts_to_partset ( Entity & , PartSet & );
00233 
00236     void   translate_partset_to_partvector ( const PartSet & , PartVector & ) const;
00237 
00238     // BulkData needs access to modify_entity, insert_entity, and
00239     // delete_entity.
00240     friend class BulkData;
00241     friend std::ostream & operator<< ( std::ostream &os , const Transaction &rhs );
00242 
00243 };
00244 
00245 inline std::ostream &operator<< ( std::ostream &os , const Transaction &rhs )
00246 {
00247   return rhs.print_stream ( os );
00248 }
00249 
00250 /*
00251  * \}
00252  */
00253 
00254 }
00255 }
00256 
00257 
00258 
00259 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends