1 #ifndef ENTITY_SEQUENCE_HPP
2 #define ENTITY_SEQUENCE_HPP
3 
4 #include "moab/Types.hpp"
5 #include "Internals.hpp"
6 
7 namespace moab {
8 
9 class SequenceData;
10 
11 class EntitySequence {
12 private:
13   EntityHandle startHandle, endHandle;
14   SequenceData* sequenceData;
15 
16 protected:
17 
EntitySequence(EntityHandle h)18   EntitySequence( EntityHandle h )
19     : startHandle(h), endHandle(h), sequenceData(NULL) {}
20 
EntitySequence(EntitySequence & split_from,EntityHandle here)21   EntitySequence( EntitySequence& split_from, EntityHandle here )
22     : startHandle( here ),
23       endHandle( split_from.endHandle ),
24       sequenceData( split_from.sequenceData )
25   {
26     split_from.endHandle = here - 1;
27   }
28 
29   SequenceData* create_data_subset( EntityHandle start_handle,
30                                     EntityHandle end_handle,
31                                     int num_sequence_arrays,
32                                     unsigned const* bytes_per_element ) const;
33 
34   ErrorCode prepend_entities( EntityID count );
35   ErrorCode append_entities( EntityID count );
36 
37 public:
38 
EntitySequence(EntityHandle start,EntityID count,SequenceData * dat)39   EntitySequence( EntityHandle start, EntityID count, SequenceData* dat )
40     : startHandle(start), endHandle( start + count - 1 ), sequenceData( dat )
41     {}
42 
~EntitySequence()43   virtual ~EntitySequence() {}
44 
type() const45   EntityType type() const
46     { return TYPE_FROM_HANDLE(start_handle()); }
47 
start_handle() const48   EntityHandle start_handle() const
49     { return startHandle; }
50 
end_handle() const51   EntityHandle end_handle() const
52     { return endHandle; }
53 
data() const54   SequenceData* data() const
55     { return sequenceData; }
56 
data(SequenceData * ptr)57   void data( SequenceData* ptr )
58     { sequenceData = ptr; }
59 
size() const60   EntityID size() const
61     { return endHandle - startHandle + 1; }
62 
63     /**\brief True if SequenceData has no holes and is used only
64      *        by this EntitySequence */
65   bool using_entire_data() const;
66 
67     /**\brief Integer value used in finding appropriate SequenceData
68      *
69      * This value is matched to input values by TypeSequenceManager to
70      * determine if an available, unused portino of a SequenceData can
71      * be used for a specific entity allocation.  For example, it is
72      * used to find a SequenceData with the appropriate number of vertices
73      * per element when allocating elements.  The default value is zero.
74      */
75   virtual int values_per_entity() const;
76 
77     /**\brief Split this sequence into two consecutive sequences
78      *
79      * Split this sequence into two sequences.
80      *\param here New sequences should be [start_handle(),here) & [here,end_handle()]
81      *\return New sequence containing [here,end_handle()]
82      */
83   virtual EntitySequence* split( EntityHandle here ) = 0;
84 
85     /**\brief Merge this sequence with another
86      *
87      * Combine two adjacent sequences.  Sequence handle blocks must be
88      * consective and sequences must share a common SequenceData.
89      */
90   virtual ErrorCode merge( EntitySequence& other );
91 
92     /**\brief Erase entities in range: (end_handle()-count, end_handle()] */
93   virtual ErrorCode pop_back( EntityID count );
94 
95     /**\brief Erase entities in range: [start_handle(), start_handle()+count) */
96   virtual ErrorCode pop_front( EntityID count );
97 
98     /**\brief Create a new SequenceData that is a copy of a subset of
99     *         the one referenced by this sequence.
100     *
101     * Create a new SequenceData that is a copy of a subset of the
102     * SequenceData referenced by this EntitySequence.  Do not make any
103     * changes to this EntitySequence or the current SequenceData.
104     */
105   virtual SequenceData* create_data_subset( EntityHandle start_handle,
106                                             EntityHandle end_handle ) const = 0;
107 
108     /**\brief Get memory characteristcs that are the same for all entities
109      *
110      * Get charactersitic constant memory use for all entities in sequence.
111      *\param bytes_per_entity The total bytes consumed for each entity in
112      *                        the underlying SequenceData.  It is assumed
113      *                        that the same amount of memory is consumed
114      *                        for unused portions of the SequenceData.
115      *\param size_of_sequence The size of the leaf subclass of this class
116      */
117   virtual void get_const_memory_use( unsigned long& bytes_per_entity,
118                                      unsigned long& size_of_sequence ) const = 0;
119     /**\brief Get portion of memory use that varies per entity
120      *
121      *\return Any per-entity memory use not accounted for in the results
122      *        of get_const_memory_use.
123      */
124   virtual unsigned long get_per_entity_memory_use( EntityHandle first,
125                                                    EntityHandle last ) const;
126 };
127 
128 } // namespace moab
129 
130 #endif
131