MOAB: Mesh Oriented datABase  (version 5.2.1)
VarLenSparseTag.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 #ifndef VAR_LEN_SPARSE_TAG_HPP
00017 #define VAR_LEN_SPARSE_TAG_HPP
00018 
00019 #ifndef IS_BUILDING_MB
00020 #error "VarLenSparseTag.hpp isn't supposed to be included into an application"
00021 #endif
00022 
00023 #ifdef WIN32
00024 #pragma warning( disable : 4786 )
00025 #endif
00026 
00027 #include "moab/MOABConfig.h"
00028 #define STRINGIFY_( X ) #X
00029 #define STRINGIFY( X )  STRINGIFY_( X )
00030 #ifdef MOAB_HAVE_UNORDERED_MAP
00031 #include STRINGIFY( MOAB_HAVE_UNORDERED_MAP )
00032 #else
00033 #include <map>
00034 #endif
00035 #include <vector>
00036 
00037 #include "TagInfo.hpp"
00038 #include "VarLenTag.hpp"
00039 #include <stdlib.h>
00040 
00041 namespace moab
00042 {
00043 
00044 //! Sparse tag variable-length data
00045 class VarLenSparseTag : public TagInfo
00046 {
00047   public:
00048     VarLenSparseTag( const char* name, DataType type, const void* default_value, int default_value_bytes );
00049 
00050     ~VarLenSparseTag();
00051 
00052     virtual TagType get_storage_type() const;
00053 
00054     /**\brief Remove/clear tag data for all entities
00055      *
00056      * Remove tag values from entities.
00057      *
00058      *\param delete_pending  If true, then release any global
00059      *          data associated with the tag in preparation for deleting
00060      *          the tag itself.
00061      *
00062      *\Note Invalidates tag if \c tag_delete_pending is true.  The only
00063      *        valid method that can be invoked that is is the destructor.
00064      *
00065      *\param seqman    Pointer to mesh entity database
00066      */
00067     virtual ErrorCode release_all_data( SequenceManager* seqman, Error* error_handler, bool delete_pending );
00068 
00069     /**\brief Get tag value for passed entities
00070      *
00071      * Get tag values for specified entities.
00072      *
00073      *\Note Will fail for variable-length data.
00074      *\param seqman Pointer to mesh entity database
00075      *\param entities Entity handles for which to retrieve tag data
00076      *\param num_entities Length of \c entities array
00077      *\param data Pointer to memory in which to store consecutive tag values,
00078      *            one for each passed entity.
00079      */
00080     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00081                                 size_t num_entities, void* data ) const;
00082 
00083     /**\brief Get tag value for passed entities
00084      *
00085      * Get tag values for specified entities.
00086      *
00087      *\Note Will fail for variable-length data.
00088      *\param seqman Pointer to mesh entity database
00089      *\param entities Entity handles for which to retrieve tag data
00090      *\param data Pointer to memory in which to store consecutive tag values,
00091      *            one for each passed entity.
00092      */
00093     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const Range& entities,
00094                                 void* data ) const;
00095 
00096     /**\brief Get tag value for passed entities
00097      *
00098      * Get tag values for specified entities.
00099      *
00100      *\param seqman    Pointer to mesh entity database
00101      *\param entities  Entity handles for which to retrieve tag data
00102      *\param num_entities Length of \c entities array
00103      *\param data_ptrs Array of pointers to tag values, one pointer
00104      *                 for each passed entity.
00105      *\param data_lengths One value for each entity specifying the
00106      *                length of the tag value for the corresponding
00107      *                entity.
00108      */
00109     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00110                                 size_t num_entities, const void** data_ptrs, int* data_lengths ) const;
00111 
00112     /**\brief Get tag value for passed entities
00113      *
00114      * Get tag values for specified entities.
00115      *
00116      *\param seqman    Pointer to mesh entity database
00117      *\param entities  Entity handles for which to retrieve tag data
00118      *\param data_ptrs Array of pointers to tag values, one pointer
00119      *                 for each passed entity.
00120      *\param data_lengths One value for each entity specifying the
00121      *                length of the tag value for the corresponding
00122      *                entity.
00123      */
00124     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const Range& entities,
00125                                 const void** data_ptrs, int* data_lengths ) const;
00126 
00127     /**\brief Set tag value for passed entities
00128      *
00129      * Store tag data or update stored tag values
00130      *\Note Will fail for variable-length data.
00131      *\param seqman Pointer to mesh entity database
00132      *\param entities Entity handles for which to store tag data
00133      *\param num_entities Length of \c entities array
00134      *\param data Pointer to memory holding consecutive tag values,
00135      *            one for each passed entity.
00136      */
00137     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00138                                 size_t num_entities, const void* data );
00139 
00140     /**\brief Set tag value for passed entities
00141      *
00142      * Store tag data or update stored tag values
00143      *\Note Will fail for variable-length data.
00144      *\param seqman Pointer to mesh entity database
00145      *\param entities Entity handles for which to store tag data
00146      *\param data Pointer to memory holding consecutive tag values,
00147      *            one for each passed entity.
00148      */
00149     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
00150                                 const void* data );
00151 
00152     /**\brief Set tag value for passed entities
00153      *
00154      * Store tag data or update stored tag values
00155      *
00156      *\param seqman    Pointer to mesh entity database
00157      *\param entities  Entity handles for which to store tag data
00158      *\param num_entities Length of \c entities array
00159      *\param data_ptrs Array of pointers to tag values, one pointer
00160      *                 for each passed entity.
00161      *\param data_lengths One value for each entity specifying the
00162      *                length of the tag value for the corresponding
00163      *                entity.  Array is required for variable-length
00164      *                tags and is ignored for fixed-length tags.
00165      */
00166     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00167                                 size_t num_entities, void const* const* data_ptrs, const int* data_lengths );
00168 
00169     /**\brief Set tag value for passed entities
00170      *
00171      * Store tag data or update stored tag values
00172      *
00173      *\param seqman    Pointer to mesh entity database
00174      *\param entities  Entity handles for which to store tag data
00175      *\param data_ptrs Array of pointers to tag values, one pointer
00176      *                 for each passed entity.
00177      *\param data_lengths One value for each entity specifying the
00178      *                length of the tag value for the corresponding
00179      *                entity.  Array is required for variable-length
00180      *                tags and is ignored for fixed-length tags.
00181      */
00182     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
00183                                 void const* const* data_ptrs, const int* data_lengths );
00184 
00185     /**\brief Set tag value for passed entities
00186      *
00187      * Store tag data or update stored tag values.
00188      *
00189      *\param seqman    Pointer to mesh entity database
00190      *\param entities  Entity handles for which to store tag data
00191      *\param num_entities Length of \c entities array
00192      *\param value_ptr Pointer to a single tag value which is to be
00193      *                 stored for each of the passed entities.
00194      *\param value_len Length of tag value in bytes.  Ignored for
00195      *                 fixed-length tags.  Required for variable-
00196      *                 length tags.
00197      */
00198     virtual ErrorCode clear_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00199                                   size_t num_entities, const void* value_ptr, int value_len = 0 );
00200 
00201     /**\brief Set tag value for passed entities
00202      *
00203      * Store tag data or update stored tag values.
00204      *
00205      *\param seqman    Pointer to mesh entity database
00206      *\param entities  Entity handles for which to store tag data
00207      *\param value_ptr Pointer to a single tag value which is to be
00208      *                 stored for each of the passed entities.
00209      *\param value_len Length of tag value in bytes.  Ignored for
00210      *                 fixed-length tags.  Required for variable-
00211      *                 length tags.
00212      */
00213     virtual ErrorCode clear_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
00214                                   const void* value_ptr, int value_len = 0 );
00215 
00216     /**\brief Remove/clear tag data for entities
00217      *
00218      * Remove tag values from entities.
00219      *
00220      *\param seqman    Pointer to mesh entity database
00221      *\param entities  Entity handles for which to store tag data
00222      *\param num_entities Length of \c entities array
00223      */
00224     virtual ErrorCode remove_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
00225                                    size_t num_entities );
00226 
00227     /**\brief Remove/clear tag data for entities
00228      *
00229      * Remove tag values from entities.
00230      *
00231      *\param seqman    Pointer to mesh entity database
00232      *\param entities  Entity handles for which to store tag data
00233      */
00234     virtual ErrorCode remove_data( SequenceManager* seqman, Error* error_handler, const Range& entities );
00235 
00236     /**\brief Access tag data via direct pointer into contiguous blocks
00237      *
00238      * Iteratively obtain direct access to contiguous blocks of tag
00239      * storage.  This function cannot be used with bit tags because
00240      * of the compressed bit storage.  This function cannot be used
00241      * with variable length tags because it does not provide a mechanism
00242      * to determine the length of the value for each entity.  This
00243      * function may be used with sparse tags, but if it is used, it
00244      * will return data for a single entity at a time.
00245      *
00246      *\param iter        As input, the first entity for which to return
00247      *                   data.  As output, one past the last entity for
00248      *                   which data was returned.
00249      *\param end         One past the last entity for which data is desired
00250      *\param data_ptr    Output: pointer to tag storage.
00251      *
00252      *\Note If this function is called for entities for which no tag value
00253      *      has been set, but for which a default value exists, it will
00254      *      force the allocation of explicit storage for each such entity
00255      *      even though MOAB would normally not explicitly store tag values
00256      *      for such entities.
00257      */
00258     virtual ErrorCode tag_iterate( SequenceManager* seqman, Error* error_handler, Range::iterator& iter,
00259                                    const Range::iterator& end, void*& data_ptr, bool allocate = true );
00260 
00261     /**\brief Get all tagged entities
00262      *
00263      * Get the list of entities for which the a tag value has been set,
00264      * or a close approximation if the tag storage scheme cannot
00265      * accurately determine exactly which entities have explicit values.
00266      *
00267      *\param seqman   Pointer to entity storage database
00268      *\param output_entities Results *appended* to this range
00269      *\param type     Optional entity type.  If specified, search is
00270      *                limited to entities of specified type.
00271      *\param intersect Optional intersect list.  If specified,
00272      *                search is restricted to entities in this list.
00273      */
00274     virtual ErrorCode get_tagged_entities( const SequenceManager* seqman, Range& output_entities,
00275                                            EntityType type = MBMAXTYPE, const Range* intersect = 0 ) const;
00276 
00277     /**\brief Count all tagged entities
00278      *
00279      * Count the entities for which the a tag value has been set,
00280      * or a close approximation if the tag storage scheme cannot
00281      * accurately determine exactly which entities have explicit values.
00282      *
00283      *\param seqman   Pointer to entity storage database
00284      *\param output_count This is *incremented* for each detected entity.
00285      *\param type     Optional entity type.  If specified, search is
00286      *                limited to entities of specified type.
00287      *\param intersect Optional intersect list.  If specified,
00288      *                search is restricted to entities in this list.
00289      */
00290     virtual ErrorCode num_tagged_entities( const SequenceManager* seqman, size_t& output_count,
00291                                            EntityType type = MBMAXTYPE, const Range* intersect = 0 ) const;
00292 
00293     /**\brief Get all tagged entities with tag value
00294      *
00295      * Get the list of entities which have the specified tag value.
00296      *
00297      *\param seqman   Pointer to entity storage database
00298      *\param output_entities Results *appended* to this range
00299      *\param value    Pointer to tag value
00300      *\param value_bytes Size of tag value in bytes.
00301      *\param type     Optional entity type.  If specified, search is
00302      *                limited to entities of specified type.
00303      *\param intersect_entities Optional intersect list.  If specified,
00304      *                search is restricted to entities in this list.
00305      */
00306     virtual ErrorCode find_entities_with_value( const SequenceManager* seqman, Error* error_handler,
00307                                                 Range& output_entities, const void* value, int value_bytes = 0,
00308                                                 EntityType type                 = MBMAXTYPE,
00309                                                 const Range* intersect_entities = 0 ) const;
00310 
00311     /**\brief Check if entity is tagged */
00312     virtual bool is_tagged( const SequenceManager*, EntityHandle h ) const;
00313 
00314     /**\brief Get memory use for tag data.
00315      *
00316      */
00317     virtual ErrorCode get_memory_use( const SequenceManager* seqman, unsigned long& total,
00318                                       unsigned long& per_entity ) const;
00319 
00320     //! get number of entities
00321     unsigned long get_number_entities()
00322     {
00323         return mData.size();
00324     }
00325 
00326     //! map of entity id and tag data
00327 #ifdef MOAB_HAVE_UNORDERED_MAP
00328     typedef MOAB_UNORDERED_MAP_NS::unordered_map< EntityHandle, VarLenTag > MapType;
00329 #else
00330     typedef std::map< EntityHandle, VarLenTag > MapType;
00331 #endif
00332 
00333   private:
00334     VarLenSparseTag( const VarLenSparseTag& );
00335     VarLenSparseTag& operator=( const VarLenSparseTag& );
00336 
00337     //! get the variable-length data for an entity id
00338     inline ErrorCode get_data_ptr( Error* error_handler, EntityHandle entity_handle, const void*& data,
00339                                    int& size ) const;
00340 
00341     MapType mData;
00342 };
00343 
00344 }  // namespace moab
00345 
00346 #endif  // VAR_LEN_SPARSE_TAG_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines