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 
00030     typedef std::vector<Bucket *>                 BucketList;
00031 
00037 //----------------------------------------------------------------------
00047 class Transaction
00048 {
00049   public:
00050     /* \brief The following are the variable type and valid values for
00051      * defining the type of transaction bucket.
00052      */
00053     typedef unsigned char                State;
00054     enum { NOT_IN_TRANSACTION = 0 , MODIFIED = 1, INSERTED = 2, DELETED = 3 };
00055 
00056     /* \brief There are two different types of transactions:
00057      * incremental and bulk.  This can be set when reseting a
00058      * transaction.
00059      */
00060     enum TransactionType { INCREMENTAL = 1 , BULK = 2 };
00061 
00062   public:
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;
00128 
00129     Transaction ();
00130     Transaction ( BulkData & , TransactionType );
00131     Transaction & operator = ( const Transaction & );
00132    ~Transaction ();
00133 
00140     void allocate_bucket_lists ();
00141 
00142     TransactionType     m_transaction_type;
00143 
00144     BulkData           &m_bulk_data;
00145     BucketListByType    m_modified;
00146     BucketListByType    m_deleted;
00147     BucketListByType    m_inserted;
00148 
00149     PartSet            m_modified_parts;
00150     PartSet            m_deleted_parts;
00151     PartSet            m_inserted_parts;
00152 
00153     std::set<Entity *>   m_to_delete;
00154 
00155 
00156     void   flush_deletes ();
00157 
00162     void   reset ( TransactionType type = BULK );
00163     void   flush ();
00164 
00165 
00169     void   modify_sole_entity ( Entity &e );
00170 
00175     void   modify_entity ( Entity & e );
00176 
00180     void   insert_entity ( Entity & e );
00181 
00185     void   delete_entity ( Entity & e );
00186 
00189     void   purge_map ( BucketListByType & );
00190 
00193     void   purge_and_erase_map ( BucketListByType & );
00194 
00199     Bucket *get_unfilled_transaction_bucket ( const unsigned *const , EntityRank , BucketList & , State );
00200 
00206     template <class ENTITY>
00207     Bucket *get_unfilled_transaction_bucket ( const ENTITY &e , BucketList &bm , State s )
00208      { return get_unfilled_transaction_bucket ( e.bucket().key() , e.entity_rank() , bm , s ); }
00209 
00212     void   add_entity_to_transaction_bucket ( Entity & , Bucket * );
00213 
00217     void   swap_entity_between_transaction_buckets ( Entity & , BucketList & , BucketList & , State );
00218 
00222     void   remove_entity_from_bucket ( Entity & , BucketList & );
00223 
00224 
00229     void   add_parts_to_partset ( Entity & , PartSet & );
00230 
00233     void   translate_partset_to_partvector ( const PartSet & , PartVector & ) const;
00234 
00235     // BulkData needs access to modify_entity, insert_entity, and
00236     // delete_entity.
00237     friend class BulkData;
00238     friend std::ostream & operator<< ( std::ostream &os , const Transaction &rhs );
00239 
00240 };
00241 
00242 inline std::ostream &operator<< ( std::ostream &os , const Transaction &rhs )
00243 {
00244   return rhs.print_stream ( os );
00245 }
00246 
00249 void  print_bucket_list ( const BucketList & , std::ostream & );
00250 /*
00251  * \}
00252  */
00253 
00254 }
00255 }
00256 
00257 
00258 
00259 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends