MOAB: Mesh Oriented datABase  (version 5.1.1)
SparseTagSuperCollection.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 /**********************************************
00017  * Filename   :     SparseTagSuperCollection.hpp
00018  *
00019  * Purpose    :     To store any size data with
00020  *                  any entity handle
00021  *
00022  * Creator    :     Clinton Stimpson
00023  *
00024  * Date       :     3 April 2002
00025  *
00026  * ********************************************/
00027 
00028 #ifndef SPARSE_TAG_SUPER_COLLECTION_HPP
00029 #define SPARSE_TAG_SUPER_COLLECTION_HPP
00030 
00031 #ifndef IS_BUILDING_MB
00032 #error "SparseTagSuperCollection.hpp isn't supposed to be included into an application"
00033 #endif
00034 
00035 #ifdef WIN32
00036 #pragma warning( disable : 4786 )
00037 #endif
00038 
00039 #include <map>
00040 #include <vector>
00041 
00042 #include "moab/Types.hpp"
00043 #include "Internals.hpp"
00044 #include "moab/Range.hpp"
00045 #include "TagInfo.hpp"
00046 
00047 #define get_collection( A ) ( ( A ) < mDataTags.size() ? mDataTags[( A )] : 0 )
00048 
00049 namespace moab
00050 {
00051 
00052 class SparseTagCollection;
00053 
00054 //! a collection of SparseTagCollections
00055 class SparseTagSuperCollection
00056 {
00057   public:
00058     //! constructor
00059     SparseTagSuperCollection() {}
00060 
00061     //! destructor
00062     virtual ~SparseTagSuperCollection();
00063 
00064     void reset_data();
00065 
00066     //! allocate new tag id
00067     ErrorCode reserve_tag_id( int data_size, TagId tag_id );
00068 
00069     //! releases an TagId
00070     ErrorCode release_tag_id( TagId tag_id );
00071 
00072     //! size of data tag
00073     int tag_size( const TagId tag_id ) const;
00074 
00075     /** Set fixed-length tag values.
00076      *\NOTE Will fail for variable-length tag data.
00077      */
00078     ErrorCode set_data( TagId tag_handle, const EntityHandle* handles, int num_handles, const void* data );
00079 
00080     /** Set tag values for array of entity handles
00081      *\param tag_id      The tag.
00082      *\param handles     Array of entity handles.
00083      *\param num_handles Length of 'handles' array.
00084      *\param values      Array of pointers to tag values, one pointer for each handle
00085      *\param lengths     Length of each tag value.  Ignored for fixed-length tags.
00086      *\param one_value   If true, tag on all entities is set to the (same)
00087      *                   first passed tag value.
00088      */
00089     ErrorCode set_data( TagId tag_handle, const EntityHandle* handles, int num_handles,
00090                         void const* const* data_pointers, const int* lengths = 0, bool one_value = false );
00091 
00092     /** Set fixed-length tag value for an Range of entities
00093      *\NOTE Will fail for variable-length tag data
00094      */
00095     ErrorCode set_data( TagId tag_handle, const Range& handles, const void* data );
00096 
00097     /** Set tag data for an Range of entities.
00098      *
00099      *\param tag_id  The tag
00100      *\param handles The entities
00101      *\param values  An array of pointers, one per entity, pointing to the
00102      *               tag value for the corresponding entity.
00103      *\param lengths An array of integers, one per entity, indicating the
00104      *               length of the tag value for each entity.  Ingored
00105      *               for fixed-length tags.
00106      *\param one_value   If true, tag on all entities is set to the (same)
00107      *                   first passed tag value.
00108      */
00109     ErrorCode set_data( TagId tag_handle, const Range& handles, void const* const* data_pointers,
00110                         const int* lengths = 0, bool one_value = false );
00111 
00112     /**\brief Access tag data via direct pointer into contiguous blocks
00113      *
00114      * Iteratively obtain direct access to contiguous blocks of tag
00115      * storage.  This function cannot be used with bit tags because
00116      * of the compressed bit storage.  This function cannot be used
00117      * with variable length tags because it does not provide a mechanism
00118      * to determine the length of the value for each entity.  This
00119      * function may be used with sparse tags, but if it is used, it
00120      * will return data for a single entity at a time.
00121      *
00122      *\param tag_handle  The handle of the tag for which to access data
00123      *\param iter        As input, the first entity for which to return
00124      *                   data.  As output, one past the last entity for
00125      *                   which data was returned.
00126      *\param end         One past the last entity for which data is desired
00127      *\param data_ptr    Output: pointer to tag storage.
00128      *
00129      *\Note If this function is called for entities for which no tag value
00130      *      has been set, but for which a default value exists, it will
00131      *      force the allocation of explicit storage for each such entity
00132      *      even though MOAB would normally not explicitly store tag values
00133      *      for such entities.
00134      */
00135     ErrorCode tag_iterate( TagId tag_handle, Range::iterator& iter, const Range::iterator& end, void*& data_ptr,
00136                            const void* default_value );
00137 
00138     /** Get fixed-length tag values for array of entities
00139      *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
00140      *      for variable-length tag.
00141      */
00142     ErrorCode get_data( TagId tag_handle, const EntityHandle* handles, int num_handles, void* data,
00143                         const void* default_value ) const;
00144 
00145     /** Get pointers to tag data for array of entities
00146      *\param tag_id      The Tag.
00147      *\param handles     Array of entity handles.
00148      *\param num_handles Length of 'handles' array.
00149      *\param tag_ptrs    Pointers to tag values, one pointer for each input handle.
00150      *\param lengths     Length of each tag value.  Ignored for fixed-length tags.
00151      *\param default_value Pointer to default value for tag, or NULL if none.
00152      *\param default_value_length  Length of default tag value.  Ingored for
00153      *                   fixed-length tags.
00154      */
00155     ErrorCode get_data( TagId tag_handle, const EntityHandle* handles, int num_handles, const void** data, int* lengths,
00156                         const void* default_value, int default_value_length ) const;
00157 
00158     /** Get fixed-length tag value for an Range of entities
00159      *\NOTE Will fail with MB_VARIABLE_DATA_LENGTH if called
00160      *      for variable-length tag.
00161      */
00162     ErrorCode get_data( TagId tag_handle, const Range& handles, void* data, const void* default_value ) const;
00163 
00164     /** Get pointers to tag data for an Range of entities.
00165      *
00166      *\param tag_id   The tag.
00167      *\param handles  The entities.
00168      *\param values   Array of pointers of type 'const void*'.  Array
00169      *                must be the same length as the size of 'entities'.
00170      *                The array will be populated with pointers to the
00171      *                internal storage of the tag data for each entity.
00172      *\param lengths  Array of integers.  Will be populated with the
00173      *                length of the tag value for each entity.  Argument
00174      *                is optional for fixed-length tags.
00175      *\param default_value The default value for the tag.
00176      *\param default_value_length The length of the default tag value.
00177      */
00178     ErrorCode get_data( TagId tag_handle, const Range& handles, const void** data, int* lengths,
00179                         const void* default_value, int default_value_length ) const;
00180 
00181     //! removes data
00182     ErrorCode remove_data( const TagId tag_handle, const EntityHandle entity_handle );
00183 
00184     //! gets all entity handles that match a type and tag
00185     ErrorCode get_entities( const TagId tag_handle, Range& entities );
00186 
00187     //! gets all entity handles that match a tag
00188     ErrorCode get_entities( const TagId tag_handle, const EntityType type, Range& entities );
00189 
00190     //! gets all entity handles that match a tag
00191     ErrorCode get_entities( const Range& range, const TagId tag_handle, const EntityType type, Range& entities );
00192 
00193     //! gets all tags on a given entity handle
00194     ErrorCode get_tags( const EntityHandle entity, std::vector< Tag >& all_tags );
00195 
00196     //! gets all entity handles that match a tag
00197     ErrorCode get_entities_with_tag_value( const TagId tag_handle, const TagInfo& tag_info, const EntityType type,
00198                                            Range& entities, const void* tag_value, int value_size );
00199 
00200     //! gets all entity handles that match a tag
00201     ErrorCode get_entities_with_tag_value( const Range& range, const TagId tag_handle, const TagInfo& tag_info,
00202                                            const EntityType type, Range& entities, const void* tag_value,
00203                                            int value_size );
00204 
00205     //! gets the number of entities that match a tag
00206     ErrorCode get_number_entities( const TagId tag_handle, const EntityType type, int& num_ent );
00207 
00208     //! gets the number of entities that match a tag
00209     ErrorCode get_number_entities( const Range& range, const TagId tag_handle, const EntityType type, int& num_ent );
00210 
00211     ErrorCode get_memory_use( TagId tag_id, unsigned long& total, unsigned long& per_entity );
00212 
00213   private:
00214     std::vector< SparseTagCollection* > mDataTags;
00215 };
00216 
00217 }  // namespace moab
00218 
00219 #endif  // SPARSE_TAG_SUPER_COLLECTION_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines