LCOV - code coverage report
Current view: top level - src - TagInfo.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 14 14 100.0 %
Date: 2020-12-16 07:07:30 Functions: 7 7 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #ifndef TAG_INFO_HPP
       2                 :            : #define TAG_INFO_HPP
       3                 :            : 
       4                 :            : #include "moab/Range.hpp"
       5                 :            : #include <string>
       6                 :            : 
       7                 :            : namespace moab
       8                 :            : {
       9                 :            : 
      10                 :            : class SequenceManager;
      11                 :            : class Range;
      12                 :            : class Error;
      13                 :            : 
      14                 :            : // ! stores information about a tag
      15                 :            : class TagInfo
      16                 :            : {
      17                 :            :   public:
      18                 :            :     //! constructor
      19                 :            :     TagInfo()
      20                 :            :         : mDefaultValue( NULL ), mMeshValue( NULL ), mDefaultValueSize( 0 ), mMeshValueSize( 0 ), mDataSize( 0 ),
      21                 :            :           dataType( MB_TYPE_OPAQUE )
      22                 :            :     {
      23                 :            :     }
      24                 :            : 
      25                 :            :     //! constructor that takes all parameters
      26                 :            :     TagInfo( const char* name, int size, DataType type, const void* default_value, int default_value_size );
      27                 :            : 
      28                 :            :     virtual ~TagInfo();
      29                 :            : 
      30                 :            :     /**\brief Remove/clear tag data for all entities
      31                 :            :      *
      32                 :            :      * Remove tag values from entities.
      33                 :            :      *
      34                 :            :      *\param tag_delete_pending  If true, then release any global
      35                 :            :      *          data associated with the tag in preparation for deleting
      36                 :            :      *          the tag itself.
      37                 :            :      *
      38                 :            :      *\Note Invalidates tag if \c tag_delete_pending is true.  The only
      39                 :            :      *        valid method that can be invoked that is is the destructor.
      40                 :            :      *
      41                 :            :      *\param seqman    Pointer to mesh entity database
      42                 :            :      */
      43                 :            :     virtual ErrorCode release_all_data( SequenceManager* seqman, Error* error_handler, bool tag_delete_pending ) = 0;
      44                 :            : 
      45                 :            :     //! set the name of the tag
      46                 :            :     void set_name( const std::string& name )
      47                 :            :     {
      48                 :            :         mTagName = name;
      49                 :            :     }
      50                 :            : 
      51                 :            :     //! get the name of the tag
      52                 :      61299 :     const std::string& get_name() const
      53                 :            :     {
      54                 :      61299 :         return mTagName;
      55                 :            :     }
      56                 :            : 
      57                 :            :     //! get length of default value
      58                 :       1801 :     int get_default_value_size() const
      59                 :            :     {
      60                 :       1801 :         return mDefaultValueSize;
      61                 :            :     }
      62                 :            : 
      63                 :            :     //! get the default data
      64                 :    2639848 :     const void* get_default_value() const
      65                 :            :     {
      66                 :    2639848 :         return mDefaultValue;
      67                 :            :     }
      68                 :            : 
      69                 :            :     //! compare the passed value to the default value.
      70                 :            :     //! returns false if no default value.
      71                 :            :     bool equals_default_value( const void* data, int size = -1 ) const;
      72                 :            : 
      73                 :      33609 :     inline DataType get_data_type() const
      74                 :            :     {
      75                 :      33609 :         return dataType;
      76                 :            :     }
      77                 :            : 
      78                 :            :     //! get the size of the data in bytes
      79                 :   21728924 :     int get_size() const
      80                 :            :     {
      81                 :   21728924 :         return mDataSize;
      82                 :            :     }
      83                 :            : 
      84                 :            :     //! Check if variable-length tag
      85                 :       9834 :     bool variable_length() const
      86                 :            :     {
      87                 :       9834 :         return get_size() == MB_VARIABLE_LENGTH;
      88                 :            :     }
      89                 :            : 
      90                 :            :     static int size_from_data_type( DataType t );
      91                 :            : 
      92                 :            :     // Check that all lengths are valid multiples of the type size.
      93                 :            :     // Returns true if all lengths are valid, false otherwise.
      94                 :            :     bool check_valid_sizes( const int* sizes, int num_sizes ) const;
      95                 :            : 
      96                 :            :     /**\return MB_VARIABLE_LENGTH_DATA If variable_length() && lengths is NULL
      97                 :            :      *         MB_INVALID_SIZE         If variable_length() && lengths is not
      98                 :            :      *                                 NULL && any size is not a multiple of
      99                 :            :      *                                 type size.
     100                 :            :      *         MB_INVALID_SIZE         If !variable_length() && lengths is not
     101                 :            :      *                                 NULL && any size is not the tag size.
     102                 :            :      *         MB_SUCCESS              Otherwise.
     103                 :            :      */
     104                 :            :     ErrorCode validate_lengths( Error* error_handler, const int* lengths, size_t num_lengths ) const;
     105                 :            : 
     106                 :            :     virtual TagType get_storage_type() const = 0;
     107                 :            : 
     108                 :            :     /**\brief Get tag value for passed entities
     109                 :            :      *
     110                 :            :      * Get tag values for specified entities.
     111                 :            :      *
     112                 :            :      *\Note Will fail for variable-length data.
     113                 :            :      *\param seqman Pointer to mesh entity database
     114                 :            :      *\param entities Entity handles for which to retrieve tag data
     115                 :            :      *\param num_entities Length of \c entities array
     116                 :            :      *\param data Pointer to memory in which to store consecutive tag values,
     117                 :            :      *            one for each passed entity.
     118                 :            :      */
     119                 :            :     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     120                 :            :                                 size_t num_entities, void* data ) const = 0;
     121                 :            : 
     122                 :            :     /**\brief Get tag value for passed entities
     123                 :            :      *
     124                 :            :      * Get tag values for specified entities.
     125                 :            :      *
     126                 :            :      *\Note Will fail for variable-length data.
     127                 :            :      *\param seqman Pointer to mesh entity database
     128                 :            :      *\param entities Entity handles for which to retrieve tag data
     129                 :            :      *\param data Pointer to memory in which to store consecutive tag values,
     130                 :            :      *            one for each passed entity.
     131                 :            :      */
     132                 :            :     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const Range& entities,
     133                 :            :                                 void* data ) const = 0;
     134                 :            : 
     135                 :            :     /**\brief Get tag value for passed entities
     136                 :            :      *
     137                 :            :      * Get tag values for specified entities.
     138                 :            :      *
     139                 :            :      *\param seqman    Pointer to mesh entity database
     140                 :            :      *\param entities  Entity handles for which to retrieve tag data
     141                 :            :      *\param num_entities Length of \c entities array
     142                 :            :      *\param data_ptrs Array of pointers to tag values, one pointer
     143                 :            :      *                 for each passed entity.
     144                 :            :      *\param data_lengths One value for each entity specifying the
     145                 :            :      *                length of the tag value for the corresponding
     146                 :            :      *                entity.
     147                 :            :      */
     148                 :            :     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     149                 :            :                                 size_t num_entities, const void** data_ptrs, int* data_lengths ) const = 0;
     150                 :            : 
     151                 :            :     /**\brief Get tag value for passed entities
     152                 :            :      *
     153                 :            :      * Get tag values for specified entities.
     154                 :            :      *
     155                 :            :      *\param seqman    Pointer to mesh entity database
     156                 :            :      *\param entities  Entity handles for which to retrieve tag data
     157                 :            :      *\param data_ptrs Array of pointers to tag values, one pointer
     158                 :            :      *                 for each passed entity.
     159                 :            :      *\param data_lengths One value for each entity specifying the
     160                 :            :      *                length of the tag value for the corresponding
     161                 :            :      *                entity.
     162                 :            :      */
     163                 :            :     virtual ErrorCode get_data( const SequenceManager* seqman, Error* error_handler, const Range& entities,
     164                 :            :                                 const void** data_ptrs, int* data_lengths ) const = 0;
     165                 :            : 
     166                 :            :     /**\brief Set tag value for passed entities
     167                 :            :      *
     168                 :            :      * Store tag data or update stored tag values
     169                 :            :      *\Note Will fail for variable-length data.
     170                 :            :      *\param seqman Pointer to mesh entity database
     171                 :            :      *\param entities Entity handles for which to store tag data
     172                 :            :      *\param num_entities Length of \c entities array
     173                 :            :      *\param data Pointer to memory holding consecutive tag values,
     174                 :            :      *            one for each passed entity.
     175                 :            :      */
     176                 :            :     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     177                 :            :                                 size_t num_entities, const void* data ) = 0;
     178                 :            : 
     179                 :            :     /**\brief Set tag value for passed entities
     180                 :            :      *
     181                 :            :      * Store tag data or update stored tag values
     182                 :            :      *\Note Will fail for variable-length data.
     183                 :            :      *\param seqman Pointer to mesh entity database
     184                 :            :      *\param entities Entity handles for which to store tag data
     185                 :            :      *\param data Pointer to memory holding consecutive tag values,
     186                 :            :      *            one for each passed entity.
     187                 :            :      */
     188                 :            :     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
     189                 :            :                                 const void* data ) = 0;
     190                 :            : 
     191                 :            :     /**\brief Set tag value for passed entities
     192                 :            :      *
     193                 :            :      * Store tag data or update stored tag values
     194                 :            :      *
     195                 :            :      *\param seqman    Pointer to mesh entity database
     196                 :            :      *\param entities  Entity handles for which to store tag data
     197                 :            :      *\param num_entities Length of \c entities array
     198                 :            :      *\param data_ptrs Array of pointers to tag values, one pointer
     199                 :            :      *                 for each passed entity.
     200                 :            :      *\param data_lengths One value for each entity specifying the
     201                 :            :      *                length of the tag value for the corresponding
     202                 :            :      *                entity.  Array is required for variable-length
     203                 :            :      *                tags and is ignored for fixed-length tags.
     204                 :            :      */
     205                 :            :     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     206                 :            :                                 size_t num_entities, void const* const* data_ptrs, const int* data_lengths ) = 0;
     207                 :            : 
     208                 :            :     /**\brief Set tag value for passed entities
     209                 :            :      *
     210                 :            :      * Store tag data or update stored tag values
     211                 :            :      *
     212                 :            :      *\param seqman    Pointer to mesh entity database
     213                 :            :      *\param entities  Entity handles for which to store tag data
     214                 :            :      *\param data_ptrs Array of pointers to tag values, one pointer
     215                 :            :      *                 for each passed entity.
     216                 :            :      *\param data_lengths One value for each entity specifying the
     217                 :            :      *                length of the tag value for the corresponding
     218                 :            :      *                entity.  Array is required for variable-length
     219                 :            :      *                tags and is ignored for fixed-length tags.
     220                 :            :      */
     221                 :            :     virtual ErrorCode set_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
     222                 :            :                                 void const* const* data_ptrs, const int* data_lengths ) = 0;
     223                 :            : 
     224                 :            :     /**\brief Set tag value for passed entities
     225                 :            :      *
     226                 :            :      * Store tag data or update stored tag values.
     227                 :            :      *
     228                 :            :      *\param seqman    Pointer to mesh entity database
     229                 :            :      *\param entities  Entity handles for which to store tag data
     230                 :            :      *\param num_entities Length of \c entities array
     231                 :            :      *\param value_ptr Pointer to a single tag value which is to be
     232                 :            :      *                 stored for each of the passed entities.
     233                 :            :      *\param value_len Length of tag value in bytes.  Ignored for
     234                 :            :      *                 fixed-length tags.  Required for variable-
     235                 :            :      *                 length tags.
     236                 :            :      */
     237                 :            :     virtual ErrorCode clear_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     238                 :            :                                   size_t num_entities, const void* value_ptr, int value_len = 0 ) = 0;
     239                 :            : 
     240                 :            :     /**\brief Set tag value for passed entities
     241                 :            :      *
     242                 :            :      * Store tag data or update stored tag values.
     243                 :            :      *
     244                 :            :      *\param seqman    Pointer to mesh entity database
     245                 :            :      *\param entities  Entity handles for which to store tag data
     246                 :            :      *\param value_ptr Pointer to a single tag value which is to be
     247                 :            :      *                 stored for each of the passed entities.
     248                 :            :      *\param value_len Length of tag value in bytes.  Ignored for
     249                 :            :      *                 fixed-length tags.  Required for variable-
     250                 :            :      *                 length tags.
     251                 :            :      */
     252                 :            :     virtual ErrorCode clear_data( SequenceManager* seqman, Error* error_handler, const Range& entities,
     253                 :            :                                   const void* value_ptr, int value_len = 0 ) = 0;
     254                 :            : 
     255                 :            :     /**\brief Remove/clear tag data for entities
     256                 :            :      *
     257                 :            :      * Remove tag values from entities.
     258                 :            :      *
     259                 :            :      *\param seqman    Pointer to mesh entity database
     260                 :            :      *\param entities  Entity handles for which to store tag data
     261                 :            :      *\param num_entities Length of \c entities array
     262                 :            :      */
     263                 :            :     virtual ErrorCode remove_data( SequenceManager* seqman, Error* error_handler, const EntityHandle* entities,
     264                 :            :                                    size_t num_entities ) = 0;
     265                 :            : 
     266                 :            :     /**\brief Remove/clear tag data for entities
     267                 :            :      *
     268                 :            :      * Remove tag values from entities.
     269                 :            :      *
     270                 :            :      *\param seqman    Pointer to mesh entity database
     271                 :            :      *\param entities  Entity handles for which to store tag data
     272                 :            :      */
     273                 :            :     virtual ErrorCode remove_data( SequenceManager* seqman, Error* error_handler, const Range& entities ) = 0;
     274                 :            : 
     275                 :            :     /**\brief Access tag data via direct pointer into contiguous blocks
     276                 :            :      *
     277                 :            :      * Iteratively obtain direct access to contiguous blocks of tag
     278                 :            :      * storage.  This function cannot be used with bit tags because
     279                 :            :      * of the compressed bit storage.  This function cannot be used
     280                 :            :      * with variable length tags because it does not provide a mechanism
     281                 :            :      * to determine the length of the value for each entity.  This
     282                 :            :      * function may be used with sparse tags, but if it is used, it
     283                 :            :      * will return data for a single entity at a time.
     284                 :            :      *
     285                 :            :      *\param iter        As input, the first entity for which to return
     286                 :            :      *                   data.  As output, one past the last entity for
     287                 :            :      *                   which data was returned.
     288                 :            :      *\param end         One past the last entity for which data is desired
     289                 :            :      *\param data_ptr    Output: pointer to tag storage.
     290                 :            :      *\param allocate    If true, space for this tag will be allocated, if not it wont
     291                 :            :      *
     292                 :            :      *\Note If this function is called for entities for which no tag value
     293                 :            :      *      has been set, but for which a default value exists, it will
     294                 :            :      *      force the allocation of explicit storage for each such entity
     295                 :            :      *      even though MOAB would normally not explicitly store tag values
     296                 :            :      *      for such entities.
     297                 :            :      */
     298                 :            :     virtual ErrorCode tag_iterate( SequenceManager* seqman, Error* error_handler, Range::iterator& iter,
     299                 :            :                                    const Range::iterator& end, void*& data_ptr, bool allocate = true ) = 0;
     300                 :            : 
     301                 :            :     /**\brief Get all tagged entities
     302                 :            :      *
     303                 :            :      * Get the list of entities for which the a tag value has been set,
     304                 :            :      * or a close approximation if the tag storage scheme cannot
     305                 :            :      * accurately determine exactly which entities have explicit values.
     306                 :            :      *
     307                 :            :      *\param seqman   Pointer to entity storage database
     308                 :            :      *\param output_entities Results *appended* to this range
     309                 :            :      *\param type     Optional entity type.  If specified, search is
     310                 :            :      *                limited to entities of specified type.
     311                 :            :      *\param intersect Optional intersect list.  If specified,
     312                 :            :      *                search is restricted to entities in this list.
     313                 :            :      */
     314                 :            :     virtual ErrorCode get_tagged_entities( const SequenceManager* seqman, Range& output_entities,
     315                 :            :                                            EntityType type = MBMAXTYPE, const Range* intersect = 0 ) const = 0;
     316                 :            : 
     317                 :            :     /**\brief Count all tagged entities
     318                 :            :      *
     319                 :            :      * Count the entities for which the a tag value has been set,
     320                 :            :      * or a close approximation if the tag storage scheme cannot
     321                 :            :      * accurately determine exactly which entities have explicit values.
     322                 :            :      *
     323                 :            :      *\param seqman   Pointer to entity storage database
     324                 :            :      *\param output_count This is *incremented* for each detected entity.
     325                 :            :      *\param type     Optional entity type.  If specified, search is
     326                 :            :      *                limited to entities of specified type.
     327                 :            :      *\param intersect Optional intersect list.  If specified,
     328                 :            :      *                search is restricted to entities in this list.
     329                 :            :      */
     330                 :            :     virtual ErrorCode num_tagged_entities( const SequenceManager* seqman, size_t& output_count,
     331                 :            :                                            EntityType type = MBMAXTYPE, const Range* intersect = 0 ) const = 0;
     332                 :            : 
     333                 :            :     /**\brief Get all tagged entities with tag value
     334                 :            :      *
     335                 :            :      * Get the list of entities which have the specified tag value.
     336                 :            :      *
     337                 :            :      *\param seqman   Pointer to entity storage database
     338                 :            :      *\param output_entities Results *appended* to this range
     339                 :            :      *\param value    Pointer to tag value
     340                 :            :      *\param value_bytes Size of tag value in bytes.
     341                 :            :      *\param type     Optional entity type.  If specified, search is
     342                 :            :      *                limited to entities of specified type.
     343                 :            :      *\param intersect_entities Optional intersect list.  If specified,
     344                 :            :      *                search is restricted to entities in this list.
     345                 :            :      */
     346                 :            :     virtual ErrorCode find_entities_with_value( const SequenceManager* seqman, Error* error_handler,
     347                 :            :                                                 Range& output_entities, const void* value, int value_bytes = 0,
     348                 :            :                                                 EntityType type                 = MBMAXTYPE,
     349                 :            :                                                 const Range* intersect_entities = 0 ) const = 0;
     350                 :            : 
     351                 :            :     /**\brief Check if entity is tagged */
     352                 :            :     virtual bool is_tagged( const SequenceManager* seqman, EntityHandle entity ) const = 0;
     353                 :            : 
     354                 :            :     /**\brief Get memory use for tag data.
     355                 :            :      *
     356                 :            :      */
     357                 :            :     virtual ErrorCode get_memory_use( const SequenceManager* seqman, unsigned long& total,
     358                 :            :                                       unsigned long& per_entity ) const = 0;
     359                 :            : 
     360                 :            :   protected:
     361                 :         44 :     unsigned long get_memory_use() const
     362                 :            :     {
     363                 :         44 :         return get_default_value_size() + get_name().size();
     364                 :            :     }
     365                 :            : 
     366                 :            :   private:
     367                 :            :     TagInfo( const TagInfo& copy );
     368                 :            : 
     369                 :            :     TagInfo& operator=( const TagInfo& copy );
     370                 :            : 
     371                 :            :     //! stores the default data, if any
     372                 :            :     void* mDefaultValue;
     373                 :            : 
     374                 :            :     //! store the mesh value, if any
     375                 :            :     void* mMeshValue;
     376                 :            : 
     377                 :            :     //! Size of mDefaultValue and mMeshValue, in bytes
     378                 :            :     //! NOTE: These sizes differ from mDataSize in two cases:
     379                 :            :     //!    a) Variable-length tags
     380                 :            :     //!    b) Bit tags (where mDataSize is bits, not bytes.)
     381                 :            :     int mDefaultValueSize, mMeshValueSize;
     382                 :            : 
     383                 :            :     //! stores the size of the data for this tag
     384                 :            :     int mDataSize;
     385                 :            : 
     386                 :            :     //! type of tag data
     387                 :            :     DataType dataType;
     388                 :            : 
     389                 :            :     //! stores the tag name
     390                 :            :     std::string mTagName;
     391                 :            : };
     392                 :            : 
     393                 :            : }  // namespace moab
     394                 :            : 
     395                 :            : #endif  // TAG_INFO_HPP

Generated by: LCOV version 1.11