[MOAB-dev] r1560 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Thu Jan 24 17:38:12 CST 2008
Author: kraftche
Date: 2008-01-24 17:38:12 -0600 (Thu, 24 Jan 2008)
New Revision: 1560
Added:
MOAB/trunk/SparseTagCollection.cpp
MOAB/trunk/SparseTagCollection.hpp
MOAB/trunk/SparseTagSuperCollection.cpp
MOAB/trunk/SparseTagSuperCollection.hpp
Removed:
MOAB/trunk/SparseTagCollections.cpp
MOAB/trunk/SparseTagCollections.hpp
Modified:
MOAB/trunk/Makefile.am
MOAB/trunk/TagServer.cpp
Log:
split two classes defined in SparseTagCollections.?pp into separate files
Modified: MOAB/trunk/Makefile.am
===================================================================
--- MOAB/trunk/Makefile.am 2008-01-24 22:31:26 UTC (rev 1559)
+++ MOAB/trunk/Makefile.am 2008-01-24 23:38:12 UTC (rev 1560)
@@ -161,8 +161,10 @@
SequenceData.cpp \
SequenceManager.cpp \
SequenceManager.hpp \
- SparseTagCollections.cpp \
- SparseTagCollections.hpp \
+ SparseTagSuperCollection.cpp \
+ SparseTagSuperCollection.hpp \
+ SparseTagCollection.cpp \
+ SparseTagCollection.hpp \
StructuredElementSeq.cpp \
StructuredElementSeq.hpp \
TagInfo.cpp \
Copied: MOAB/trunk/SparseTagCollection.cpp (from rev 1555, MOAB/trunk/SparseTagCollections.cpp)
===================================================================
--- MOAB/trunk/SparseTagCollection.cpp (rev 0)
+++ MOAB/trunk/SparseTagCollection.cpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -0,0 +1,159 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ *
+ * Copyright 2004 Sandia Corporation. Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+
+/**********************************************
+ * Filename : SparseTagCollection.cpp
+ *
+ * Purpose : To store any size data with
+ * any entity handle
+ *
+ * Creator : Clinton Stimpson
+ *
+ * Date : 3 April 2002
+ *
+ * ********************************************/
+
+
+#include <memory.h>
+#include <algorithm>
+
+#include "SparseTagCollection.hpp"
+#include "MBRange.hpp"
+#include "TagCompare.hpp"
+
+SparseTagCollection::SparseTagCollection(int data_size)
+{
+ mDataSize = data_size;
+}
+
+SparseTagCollection::~SparseTagCollection()
+{
+ void* tag_data = NULL;
+
+ std::map<MBEntityHandle, void*>::iterator tag_iterator;
+ for(tag_iterator = mData.begin(); tag_iterator != mData.end(); ++tag_iterator)
+ {
+ tag_data = tag_iterator->second;
+ if (mDataSize == MB_VARIABLE_LENGTH)
+ reinterpret_cast<VarLenTag*>(tag_data)->clear();
+ if(tag_data != NULL)
+ mAllocator.destroy(tag_data);
+ }
+ mData.clear();
+}
+
+MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data)
+{
+ MBErrorCode ret_val = MB_TAG_NOT_FOUND;
+
+ std::map<MBEntityHandle, void*>::iterator iterator =
+ mData.lower_bound(entity_handle);
+
+ // data space already exists
+ if (iterator!= mData.end() && iterator->first == entity_handle)
+ {
+ memcpy( iterator->second, data, mDataSize);
+ ret_val = MB_SUCCESS;
+ }
+ // we need to make some data space
+ else
+ {
+ void* new_data = mAllocator.allocate(mDataSize);
+ memcpy(new_data, data, mDataSize);
+ mData.insert(iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data));
+ ret_val = MB_SUCCESS;
+ }
+
+ return ret_val;
+}
+
+MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, void* data)
+{
+ std::map<MBEntityHandle, void*>::iterator iter =
+ mData.find(entity_handle);
+
+ if(iter == mData.end())
+ return MB_TAG_NOT_FOUND;
+
+ memcpy(data, iter->second, mDataSize);
+ return MB_SUCCESS;
+}
+
+
+
+MBErrorCode SparseTagCollection::remove_data( const MBEntityHandle entity_handle )
+{
+ std::map<MBEntityHandle, void*>::iterator iterator =
+ mData.find(entity_handle);
+
+ if(iterator != mData.end())
+ {
+ if (mDataSize == MB_VARIABLE_LENGTH)
+ reinterpret_cast<VarLenTag*>(iterator->second)->clear();
+ mAllocator.destroy(iterator->second);
+ mData.erase(iterator);
+ return MB_SUCCESS;
+ }
+ return MB_ENTITY_NOT_FOUND;
+}
+
+
+//! get number of entities of type
+MBErrorCode SparseTagCollection::get_number_entities(MBEntityType type, int& num_entities)
+{
+ num_entities = 0;
+ std::map<MBEntityHandle, void*>::iterator iter;
+ for(iter = mData.begin(); iter != mData.end(); ++iter)
+ {
+ if(TYPE_FROM_HANDLE(iter->first) == type)
+ num_entities++;
+ }
+ return MB_SUCCESS;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagCollection::get_entities(MBEntityType type, MBRange &entities)
+{
+ std::map<MBEntityHandle, void*>::iterator iter;
+ for(iter = mData.begin(); iter != mData.end(); ++iter)
+ {
+ if(TYPE_FROM_HANDLE(iter->first) == type)
+ entities.insert(iter->first);
+ }
+ return MB_SUCCESS;
+}
+
+
+//! gets all entity handles that match a type, tag and tag value
+MBErrorCode SparseTagCollection::get_entities_with_tag_value(
+ const TagInfo& tag_info,
+ MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size)
+{
+ std::map<MBEntityHandle, void*>::iterator iter, end;
+ int junk;
+ iter = mData.lower_bound( CREATE_HANDLE( type, MB_START_ID, junk ) );
+ end = mData.upper_bound( CREATE_HANDLE( type, MB_END_ID, junk ) );
+ find_tag_values_equal( tag_info, tag_value, value_size, iter, end, entities );
+ return MB_SUCCESS;
+}
+
+
+
+
+
Copied: MOAB/trunk/SparseTagCollection.hpp (from rev 1555, MOAB/trunk/SparseTagCollections.hpp)
===================================================================
--- MOAB/trunk/SparseTagCollection.hpp (rev 0)
+++ MOAB/trunk/SparseTagCollection.hpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -0,0 +1,145 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ *
+ * Copyright 2004 Sandia Corporation. Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+
+/**********************************************
+ * Filename : SparseTagCollection.hpp
+ *
+ * Purpose : To store any size data with
+ * any entity handle
+ *
+ * Creator : Clinton Stimpson
+ *
+ * Date : 3 April 2002
+ *
+ * ********************************************/
+
+
+
+#ifndef SPARSE_TAG_COLLECTION_HPP
+#define SPARSE_TAG_COLLECTION_HPP
+
+#ifndef IS_BUILDING_MB
+#error "SparseTagCollection.hpp isn't supposed to be included into an application"
+#endif
+
+#ifdef WIN32
+#pragma warning(disable : 4786)
+#endif
+
+#include <map>
+#include <vector>
+
+#include "MBTypes.h"
+#include "MBInternals.hpp"
+#include "MBRange.hpp"
+#include "TagInfo.hpp"
+
+//! allocator for tag data
+class SparseTagDataAllocator
+{
+public:
+ //! constructor
+ SparseTagDataAllocator(){}
+ //! destructor
+ ~SparseTagDataAllocator(){}
+ //! allocates memory of size and returns pointer
+ void* allocate(size_t data_size) { return malloc(data_size); }
+ //! frees the memory
+ void destroy(void* p){ free(p); }
+};
+
+
+//! collection of tag data associated with entity ids
+class SparseTagCollection
+{
+public:
+
+ //! constructor takes tag data size
+ SparseTagCollection(int data_size);
+
+ //! destructor
+ ~SparseTagCollection();
+
+ //! set the tag data for an entity id
+ MBErrorCode set_data(const MBEntityHandle entity_handle, const void* data);
+
+ //! get the tag data for an entity id
+ MBErrorCode get_data(const MBEntityHandle entity_handle, void* data);
+
+ //! removes the data
+ MBErrorCode remove_data(const MBEntityHandle entity_handle);
+
+ //! get number of entities of type
+ MBErrorCode get_number_entities(MBEntityType type, int& num_entities);
+
+ //! get number of entities
+ unsigned long get_number_entities()
+ { return mData.size(); }
+
+ //! gets all entity handles that match a type and tag
+ MBErrorCode get_entities(MBEntityType type, MBRange &entities);
+
+ //! gets all entity handles that match a tag
+ MBErrorCode get_entities(MBRange &entities) const;
+
+ //! gets all entity handles that match a type, tag, tag_value
+ MBErrorCode get_entities_with_tag_value( const TagInfo& info,
+ MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size);
+
+ //! if this collection contains this entity, return true, otherwise false
+ bool contains(const MBEntityHandle entity) const;
+
+ int tag_size() const { return mDataSize; }
+
+protected:
+
+ //! hidden constructor
+ SparseTagCollection(){}
+
+ //! size of the data
+ int mDataSize;
+
+ //! allocator for this collection
+ SparseTagDataAllocator mAllocator;
+
+ //! map of entity id and tag data
+ std::map<MBEntityHandle /*entity_handle*/ , void* /*data*/ > mData;
+
+};
+
+inline bool SparseTagCollection::contains(const MBEntityHandle entity) const
+{
+ return (mData.find(entity) == mData.end() ? false : true);
+}
+
+inline MBErrorCode SparseTagCollection::get_entities(MBRange &entities) const
+{
+ for (std::map<MBEntityHandle,void*>::const_iterator mit = mData.begin();
+ mit != mData.end(); mit++)
+ entities.insert((*mit).first);
+
+ return MB_SUCCESS;
+}
+
+
+#endif //SPARSE_TAG_COLLECTION_HPP
+
+
+
+
Deleted: MOAB/trunk/SparseTagCollections.cpp
===================================================================
--- MOAB/trunk/SparseTagCollections.cpp 2008-01-24 22:31:26 UTC (rev 1559)
+++ MOAB/trunk/SparseTagCollections.cpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -1,370 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- *
- * Copyright 2004 Sandia Corporation. Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- */
-
-
-/**********************************************
- * Filename : SparseTagCollections.cpp
- *
- * Purpose : To store any size data with
- * any entity handle
- *
- * Creator : Clinton Stimpson
- *
- * Date : 3 April 2002
- *
- * ********************************************/
-
-
-#include <memory.h>
-#include <algorithm>
-
-#include "SparseTagCollections.hpp"
-#include "MBRange.hpp"
-#include "TagCompare.hpp"
-
-/*
- SparseTagSuperCollection functions -----------------------------
-*/
-
-SparseTagSuperCollection::~SparseTagSuperCollection()
-{
- std::vector<SparseTagCollection*>::iterator tag_iterator;
- for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
- delete *tag_iterator;
- mDataTags.clear();
-}
-
-void SparseTagSuperCollection::reset_data()
-{
- std::vector<SparseTagCollection*>::iterator tag_iterator;
- for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
- {
- if (*tag_iterator) {
- int data_size = (*tag_iterator)->tag_size();
- delete *tag_iterator;
- *tag_iterator = new SparseTagCollection(data_size);
- }
- }
-
-}
-
-MBErrorCode SparseTagSuperCollection::reserve_tag_id(int data_size, MBTagId tag_id)
-{
- if(data_size<=0)
- return MB_FAILURE;
-
- if (tag_id >= mDataTags.size())
- mDataTags.resize( tag_id+1, 0 );
-
- if (mDataTags[tag_id])
- return MB_FAILURE;
-
- mDataTags[tag_id] = new SparseTagCollection(data_size);
- return MB_SUCCESS;
-}
-
-MBErrorCode SparseTagSuperCollection::release_tag_id(MBTagId tag_id)
-{
- if (tag_id >= mDataTags.size() || !mDataTags[tag_id])
- return MB_TAG_NOT_FOUND;
-
- delete mDataTags[tag_id];
- mDataTags[tag_id] = 0;
- return MB_SUCCESS;
-}
-
-int SparseTagSuperCollection::tag_size(const MBTagId tag_id) const
-{
- SparseTagCollection* coll = get_collection(tag_id);
- return coll ? coll->tag_size() : 0;
-}
-
-MBErrorCode SparseTagSuperCollection::set_data(const MBTagId tag_handle,
- const MBEntityHandle entity_handle, const void* data)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->set_data( entity_handle, data ) : MB_TAG_NOT_FOUND;
-}
-
-MBErrorCode SparseTagSuperCollection::get_data(const MBTagId tag_handle,
- const MBEntityHandle entity_handle, void* data)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->get_data( entity_handle, data ) : MB_TAG_NOT_FOUND;
-}
-
-
-MBErrorCode SparseTagSuperCollection::remove_data( const MBTagId tag_handle,
- const MBEntityHandle entity_handle )
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->remove_data( entity_handle ) : MB_TAG_NOT_FOUND;
-}
-
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle, const MBEntityType type,
- MBRange &entities)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->get_entities(type, entities) : MB_TAG_NOT_FOUND;
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities(const MBRange &range,
- const MBTagId tag_handle, const MBEntityType type,
- MBRange &entities)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- if (!coll)
- return MB_TAG_NOT_FOUND;
-
- MBRange dum_range;
- MBErrorCode result = coll->get_entities(type, dum_range);
-
- std::set_intersection(dum_range.begin(), dum_range.end(),
- range.begin(), range.end(),
- mb_range_inserter(entities));
-
- return result;
-}
-
-MBErrorCode SparseTagSuperCollection::get_tags(const MBEntityHandle entity,
- std::vector<MBTag> &all_tags)
-{
- for (MBTagId id = 0; id < mDataTags.size(); ++id)
- if (mDataTags[id] && mDataTags[id]->contains(entity))
- all_tags.push_back( TAG_HANDLE_FROM_ID( id, MB_TAG_SPARSE ) );
-
- return MB_SUCCESS;
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
- const MBTagId tag_handle,
- const TagInfo& tag_info,
- const MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- if (!coll)
- return MB_TAG_NOT_FOUND;
-
- return coll->get_entities_with_tag_value(tag_info, type, entities, tag_value, value_size);
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
- const MBRange &range,
- const MBTagId tag_handle,
- const TagInfo& tag_info,
- const MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- if (!coll)
- return MB_TAG_NOT_FOUND;
-
- MBRange dum_range;
- MBErrorCode result = coll->get_entities_with_tag_value(
- tag_info, type, dum_range, tag_value, value_size);
-
- // do this the hard way to preserve order in the vector
- std::set_intersection(range.begin(), range.end(),
- dum_range.begin(), dum_range.end(),
- mb_range_inserter(entities));
-
- return result;
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_number_entities(const MBTagId tag_handle, const MBEntityType type,
- int& num_entities)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->get_number_entities( type, num_entities ) : MB_TAG_NOT_FOUND;
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagSuperCollection::get_number_entities(const MBRange &range,
- const MBTagId tag_handle, const MBEntityType type,
- int& num_entities)
-{
- MBRange dum_range;
- MBErrorCode result = get_entities(range, tag_handle, type, dum_range);
- num_entities = dum_range.size();
- return result;
-}
-
-
-MBErrorCode SparseTagSuperCollection::get_memory_use( MBTagId tag_id,
- unsigned long& total,
- unsigned long& per_entity )
-{
- SparseTagCollection* coll = get_collection(tag_id);
- if (!coll)
- return MB_TAG_NOT_FOUND;
-
- // 3*sizeof(void*) - std::map RB tree node
- // sizeof(void*)*sizeof(MBEntityHandle) - data in std::map node
- // coll->tag_size() - the actual tag data
- per_entity = 4*sizeof(void*)+sizeof(MBEntityHandle)+coll->tag_size();
-
- // Count number of occupied slots in mDataTags vector
- unsigned num_coll =0;
- for (unsigned i = 0; i < mDataTags.size(); ++i)
- if (mDataTags[i])
- ++num_coll;
-
- // amortized space in mDataTags vector
- total = sizeof(SparseTagCollection*) * mDataTags.capacity() / num_coll;
- // SparseTagCollection object for this tag
- total += sizeof(SparseTagCollection);
- // Per-entity data in SparseTagCollection
- total += per_entity * coll->get_number_entities();
- return MB_SUCCESS;
-}
-
-/*
- SparseTagCollection functions ----------------------------------
-*/
-
-SparseTagCollection::SparseTagCollection(int data_size)
-{
- mDataSize = data_size;
-}
-
-SparseTagCollection::~SparseTagCollection()
-{
- void* tag_data = NULL;
-
- std::map<MBEntityHandle, void*>::iterator tag_iterator;
- for(tag_iterator = mData.begin(); tag_iterator != mData.end(); ++tag_iterator)
- {
- tag_data = tag_iterator->second;
- if (mDataSize == MB_VARIABLE_LENGTH)
- reinterpret_cast<VarLenTag*>(tag_data)->clear();
- if(tag_data != NULL)
- mAllocator.destroy(tag_data);
- }
- mData.clear();
-}
-
-MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data)
-{
- MBErrorCode ret_val = MB_TAG_NOT_FOUND;
-
- std::map<MBEntityHandle, void*>::iterator iterator =
- mData.lower_bound(entity_handle);
-
- // data space already exists
- if (iterator!= mData.end() && iterator->first == entity_handle)
- {
- memcpy( iterator->second, data, mDataSize);
- ret_val = MB_SUCCESS;
- }
- // we need to make some data space
- else
- {
- void* new_data = mAllocator.allocate(mDataSize);
- memcpy(new_data, data, mDataSize);
- mData.insert(iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data));
- ret_val = MB_SUCCESS;
- }
-
- return ret_val;
-}
-
-MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, void* data)
-{
- std::map<MBEntityHandle, void*>::iterator iter =
- mData.find(entity_handle);
-
- if(iter == mData.end())
- return MB_TAG_NOT_FOUND;
-
- memcpy(data, iter->second, mDataSize);
- return MB_SUCCESS;
-}
-
-
-
-MBErrorCode SparseTagCollection::remove_data( const MBEntityHandle entity_handle )
-{
- std::map<MBEntityHandle, void*>::iterator iterator =
- mData.find(entity_handle);
-
- if(iterator != mData.end())
- {
- if (mDataSize == MB_VARIABLE_LENGTH)
- reinterpret_cast<VarLenTag*>(iterator->second)->clear();
- mAllocator.destroy(iterator->second);
- mData.erase(iterator);
- return MB_SUCCESS;
- }
- return MB_ENTITY_NOT_FOUND;
-}
-
-
-//! get number of entities of type
-MBErrorCode SparseTagCollection::get_number_entities(MBEntityType type, int& num_entities)
-{
- num_entities = 0;
- std::map<MBEntityHandle, void*>::iterator iter;
- for(iter = mData.begin(); iter != mData.end(); ++iter)
- {
- if(TYPE_FROM_HANDLE(iter->first) == type)
- num_entities++;
- }
- return MB_SUCCESS;
-}
-
-//! gets all entity handles that match a type and tag
-MBErrorCode SparseTagCollection::get_entities(MBEntityType type, MBRange &entities)
-{
- std::map<MBEntityHandle, void*>::iterator iter;
- for(iter = mData.begin(); iter != mData.end(); ++iter)
- {
- if(TYPE_FROM_HANDLE(iter->first) == type)
- entities.insert(iter->first);
- }
- return MB_SUCCESS;
-}
-
-
-//! gets all entity handles that match a type, tag and tag value
-MBErrorCode SparseTagCollection::get_entities_with_tag_value(
- const TagInfo& tag_info,
- MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size)
-{
- std::map<MBEntityHandle, void*>::iterator iter, end;
- int junk;
- iter = mData.lower_bound( CREATE_HANDLE( type, MB_START_ID, junk ) );
- end = mData.upper_bound( CREATE_HANDLE( type, MB_END_ID, junk ) );
- find_tag_values_equal( tag_info, tag_value, value_size, iter, end, entities );
- return MB_SUCCESS;
-}
-
-
-
-
-
Deleted: MOAB/trunk/SparseTagCollections.hpp
===================================================================
--- MOAB/trunk/SparseTagCollections.hpp 2008-01-24 22:31:26 UTC (rev 1559)
+++ MOAB/trunk/SparseTagCollections.hpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -1,235 +0,0 @@
-/**
- * MOAB, a Mesh-Oriented datABase, is a software component for creating,
- * storing and accessing finite element mesh data.
- *
- * Copyright 2004 Sandia Corporation. Under the terms of Contract
- * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
- * retains certain rights in this software.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- */
-
-
-/**********************************************
- * Filename : SparseTagCollections.hpp
- *
- * Purpose : To store any size data with
- * any entity handle
- *
- * Creator : Clinton Stimpson
- *
- * Date : 3 April 2002
- *
- * ********************************************/
-
-
-
-#ifndef SPARSE_TAG_COLLECTIONS_HPP
-#define SPARSE_TAG_COLLECTIONS_HPP
-
-#ifndef IS_BUILDING_MB
-#error "SparseTagCollections.hpp isn't supposed to be included into an application"
-#endif
-
-#ifdef WIN32
-#pragma warning(disable : 4786)
-#endif
-
-#include <map>
-#include <vector>
-
-#include "MBTypes.h"
-#include "MBInternals.hpp"
-#include "MBRange.hpp"
-#include "TagInfo.hpp"
-
-#define get_collection( A ) ((A) < mDataTags.size() ? mDataTags[(A)] : 0)
-
-//! allocator for tag data
-class SparseTagDataAllocator
-{
-public:
- //! constructor
- SparseTagDataAllocator(){}
- //! destructor
- ~SparseTagDataAllocator(){}
- //! allocates memory of size and returns pointer
- void* allocate(size_t data_size) { return malloc(data_size); }
- //! frees the memory
- void destroy(void* p){ free(p); }
-};
-
-
-//! collection of tag data associated with entity ids
-class SparseTagCollection
-{
-public:
-
- //! constructor takes tag data size
- SparseTagCollection(int data_size);
-
- //! destructor
- ~SparseTagCollection();
-
- //! set the tag data for an entity id
- MBErrorCode set_data(const MBEntityHandle entity_handle, const void* data);
-
- //! get the tag data for an entity id
- MBErrorCode get_data(const MBEntityHandle entity_handle, void* data);
-
- //! removes the data
- MBErrorCode remove_data(const MBEntityHandle entity_handle);
-
- //! get number of entities of type
- MBErrorCode get_number_entities(MBEntityType type, int& num_entities);
-
- //! get number of entities
- unsigned long get_number_entities()
- { return mData.size(); }
-
- //! gets all entity handles that match a type and tag
- MBErrorCode get_entities(MBEntityType type, MBRange &entities);
-
- //! gets all entity handles that match a tag
- MBErrorCode get_entities(MBRange &entities) const;
-
- //! gets all entity handles that match a type, tag, tag_value
- MBErrorCode get_entities_with_tag_value( const TagInfo& info,
- MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size);
-
- //! if this collection contains this entity, return true, otherwise false
- bool contains(const MBEntityHandle entity) const;
-
- int tag_size() const { return mDataSize; }
-
-protected:
-
- //! hidden constructor
- SparseTagCollection(){}
-
- //! size of the data
- int mDataSize;
-
- //! allocator for this collection
- SparseTagDataAllocator mAllocator;
-
- //! map of entity id and tag data
- std::map<MBEntityHandle /*entity_handle*/ , void* /*data*/ > mData;
-
-};
-
-inline bool SparseTagCollection::contains(const MBEntityHandle entity) const
-{
- return (mData.find(entity) == mData.end() ? false : true);
-}
-
-inline MBErrorCode SparseTagCollection::get_entities(MBRange &entities) const
-{
- for (std::map<MBEntityHandle,void*>::const_iterator mit = mData.begin();
- mit != mData.end(); mit++)
- entities.insert((*mit).first);
-
- return MB_SUCCESS;
-}
-
-//! a collection of SparseTagCollections
-class SparseTagSuperCollection
-{
-public:
- //! constructor
- SparseTagSuperCollection(){}
-
- //! destructor
- virtual ~SparseTagSuperCollection();
-
- void reset_data();
-
- //! allocate new tag id
- MBErrorCode reserve_tag_id(int data_size, MBTagId tag_id);
-
- //! releases an MBTagId
- MBErrorCode release_tag_id(MBTagId tag_id);
-
- //! size of data tag
- int tag_size(const MBTagId tag_id) const;
-
- //! set the data of a tag
- MBErrorCode set_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, const void* data);
-
- //! get the data of a tag
- MBErrorCode get_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, void* data);
-
- //! removes data
- MBErrorCode remove_data(const MBTagId tag_handle, const MBEntityHandle entity_handle);
-
- //! gets all entity handles that match a type and tag
- MBErrorCode get_entities(const MBTagId tag_handle, MBRange &entities);
-
- //! gets all entity handles that match a tag
- MBErrorCode get_entities(const MBTagId tag_handle, const MBEntityType type,
- MBRange &entities);
-
- //! gets all entity handles that match a tag
- MBErrorCode get_entities(const MBRange &range,
- const MBTagId tag_handle, const MBEntityType type,
- MBRange &entities);
-
- //! gets all tags on a given entity handle
- MBErrorCode get_tags(const MBEntityHandle entity,
- std::vector<MBTag> &all_tags);
-
- //! gets all entity handles that match a tag
- MBErrorCode get_entities_with_tag_value( const MBTagId tag_handle,
- const TagInfo& tag_info,
- const MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size);
-
- //! gets all entity handles that match a tag
- MBErrorCode get_entities_with_tag_value( const MBRange &range,
- const MBTagId tag_handle,
- const TagInfo& tag_info,
- const MBEntityType type,
- MBRange &entities,
- const void* tag_value,
- int value_size);
-
- //! gets the number of entities that match a tag
- MBErrorCode get_number_entities(const MBTagId tag_handle, const MBEntityType type, int& num_ent);
-
-
- //! gets the number of entities that match a tag
- MBErrorCode get_number_entities(const MBRange &range,
- const MBTagId tag_handle, const MBEntityType type, int& num_ent);
-
- MBErrorCode get_memory_use( MBTagId tag_id,
- unsigned long& total,
- unsigned long& per_entity );
-
-private:
-
- std::vector<SparseTagCollection*> mDataTags;
-};
-
-//! gets all entity handles that match a type and tag
-inline MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle,
- MBRange &entities)
-{
- SparseTagCollection* coll = get_collection(tag_handle);
- return coll ? coll->get_entities(entities) : MB_TAG_NOT_FOUND;
-}
-
-
-#endif //SPARSE_TAG_COLLECTIONS_HPP
-
-
-
-
Copied: MOAB/trunk/SparseTagSuperCollection.cpp (from rev 1559, MOAB/trunk/SparseTagCollections.cpp)
===================================================================
--- MOAB/trunk/SparseTagSuperCollection.cpp (rev 0)
+++ MOAB/trunk/SparseTagSuperCollection.cpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -0,0 +1,253 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ *
+ * Copyright 2004 Sandia Corporation. Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+
+/**********************************************
+ * Filename : SparseTagSuperCollection.cpp
+ *
+ * Purpose : To store any size data with
+ * any entity handle
+ *
+ * Creator : Clinton Stimpson
+ *
+ * Date : 3 April 2002
+ *
+ * ********************************************/
+
+
+#include <memory.h>
+#include <algorithm>
+
+#include "SparseTagSuperCollection.hpp"
+#include "SparseTagCollection.hpp"
+#include "MBRange.hpp"
+
+/*
+ SparseTagSuperCollection functions -----------------------------
+*/
+
+SparseTagSuperCollection::~SparseTagSuperCollection()
+{
+ std::vector<SparseTagCollection*>::iterator tag_iterator;
+ for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
+ delete *tag_iterator;
+ mDataTags.clear();
+}
+
+void SparseTagSuperCollection::reset_data()
+{
+ std::vector<SparseTagCollection*>::iterator tag_iterator;
+ for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
+ {
+ if (*tag_iterator) {
+ int data_size = (*tag_iterator)->tag_size();
+ delete *tag_iterator;
+ *tag_iterator = new SparseTagCollection(data_size);
+ }
+ }
+
+}
+
+MBErrorCode SparseTagSuperCollection::reserve_tag_id(int data_size, MBTagId tag_id)
+{
+ if(data_size<=0)
+ return MB_FAILURE;
+
+ if (tag_id >= mDataTags.size())
+ mDataTags.resize( tag_id+1, 0 );
+
+ if (mDataTags[tag_id])
+ return MB_FAILURE;
+
+ mDataTags[tag_id] = new SparseTagCollection(data_size);
+ return MB_SUCCESS;
+}
+
+MBErrorCode SparseTagSuperCollection::release_tag_id(MBTagId tag_id)
+{
+ if (tag_id >= mDataTags.size() || !mDataTags[tag_id])
+ return MB_TAG_NOT_FOUND;
+
+ delete mDataTags[tag_id];
+ mDataTags[tag_id] = 0;
+ return MB_SUCCESS;
+}
+
+int SparseTagSuperCollection::tag_size(const MBTagId tag_id) const
+{
+ SparseTagCollection* coll = get_collection(tag_id);
+ return coll ? coll->tag_size() : 0;
+}
+
+MBErrorCode SparseTagSuperCollection::set_data(const MBTagId tag_handle,
+ const MBEntityHandle entity_handle, const void* data)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->set_data( entity_handle, data ) : MB_TAG_NOT_FOUND;
+}
+
+MBErrorCode SparseTagSuperCollection::get_data(const MBTagId tag_handle,
+ const MBEntityHandle entity_handle, void* data)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->get_data( entity_handle, data ) : MB_TAG_NOT_FOUND;
+}
+
+
+MBErrorCode SparseTagSuperCollection::remove_data( const MBTagId tag_handle,
+ const MBEntityHandle entity_handle )
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->remove_data( entity_handle ) : MB_TAG_NOT_FOUND;
+}
+
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle,
+ MBRange &entities)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->get_entities(entities) : MB_TAG_NOT_FOUND;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_entities(const MBTagId tag_handle, const MBEntityType type,
+ MBRange &entities)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->get_entities(type, entities) : MB_TAG_NOT_FOUND;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_entities(const MBRange &range,
+ const MBTagId tag_handle, const MBEntityType type,
+ MBRange &entities)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ if (!coll)
+ return MB_TAG_NOT_FOUND;
+
+ MBRange dum_range;
+ MBErrorCode result = coll->get_entities(type, dum_range);
+
+ std::set_intersection(dum_range.begin(), dum_range.end(),
+ range.begin(), range.end(),
+ mb_range_inserter(entities));
+
+ return result;
+}
+
+MBErrorCode SparseTagSuperCollection::get_tags(const MBEntityHandle entity,
+ std::vector<MBTag> &all_tags)
+{
+ for (MBTagId id = 0; id < mDataTags.size(); ++id)
+ if (mDataTags[id] && mDataTags[id]->contains(entity))
+ all_tags.push_back( TAG_HANDLE_FROM_ID( id, MB_TAG_SPARSE ) );
+
+ return MB_SUCCESS;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
+ const MBTagId tag_handle,
+ const TagInfo& tag_info,
+ const MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ if (!coll)
+ return MB_TAG_NOT_FOUND;
+
+ return coll->get_entities_with_tag_value(tag_info, type, entities, tag_value, value_size);
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_entities_with_tag_value(
+ const MBRange &range,
+ const MBTagId tag_handle,
+ const TagInfo& tag_info,
+ const MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ if (!coll)
+ return MB_TAG_NOT_FOUND;
+
+ MBRange dum_range;
+ MBErrorCode result = coll->get_entities_with_tag_value(
+ tag_info, type, dum_range, tag_value, value_size);
+
+ // do this the hard way to preserve order in the vector
+ std::set_intersection(range.begin(), range.end(),
+ dum_range.begin(), dum_range.end(),
+ mb_range_inserter(entities));
+
+ return result;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_number_entities(const MBTagId tag_handle, const MBEntityType type,
+ int& num_entities)
+{
+ SparseTagCollection* coll = get_collection(tag_handle);
+ return coll ? coll->get_number_entities( type, num_entities ) : MB_TAG_NOT_FOUND;
+}
+
+//! gets all entity handles that match a type and tag
+MBErrorCode SparseTagSuperCollection::get_number_entities(const MBRange &range,
+ const MBTagId tag_handle, const MBEntityType type,
+ int& num_entities)
+{
+ MBRange dum_range;
+ MBErrorCode result = get_entities(range, tag_handle, type, dum_range);
+ num_entities = dum_range.size();
+ return result;
+}
+
+
+MBErrorCode SparseTagSuperCollection::get_memory_use( MBTagId tag_id,
+ unsigned long& total,
+ unsigned long& per_entity )
+{
+ SparseTagCollection* coll = get_collection(tag_id);
+ if (!coll)
+ return MB_TAG_NOT_FOUND;
+
+ // 3*sizeof(void*) - std::map RB tree node
+ // sizeof(void*)*sizeof(MBEntityHandle) - data in std::map node
+ // coll->tag_size() - the actual tag data
+ per_entity = 4*sizeof(void*)+sizeof(MBEntityHandle)+coll->tag_size();
+
+ // Count number of occupied slots in mDataTags vector
+ unsigned num_coll =0;
+ for (unsigned i = 0; i < mDataTags.size(); ++i)
+ if (mDataTags[i])
+ ++num_coll;
+
+ // amortized space in mDataTags vector
+ total = sizeof(SparseTagCollection*) * mDataTags.capacity() / num_coll;
+ // SparseTagCollection object for this tag
+ total += sizeof(SparseTagCollection);
+ // Per-entity data in SparseTagCollection
+ total += per_entity * coll->get_number_entities();
+ return MB_SUCCESS;
+}
+
+
+
Copied: MOAB/trunk/SparseTagSuperCollection.hpp (from rev 1559, MOAB/trunk/SparseTagCollections.hpp)
===================================================================
--- MOAB/trunk/SparseTagSuperCollection.hpp (rev 0)
+++ MOAB/trunk/SparseTagSuperCollection.hpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -0,0 +1,139 @@
+/**
+ * MOAB, a Mesh-Oriented datABase, is a software component for creating,
+ * storing and accessing finite element mesh data.
+ *
+ * Copyright 2004 Sandia Corporation. Under the terms of Contract
+ * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
+ * retains certain rights in this software.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+
+/**********************************************
+ * Filename : SparseTagSuperCollection.hpp
+ *
+ * Purpose : To store any size data with
+ * any entity handle
+ *
+ * Creator : Clinton Stimpson
+ *
+ * Date : 3 April 2002
+ *
+ * ********************************************/
+
+
+
+#ifndef SPARSE_TAG_SUPER_COLLECTION_HPP
+#define SPARSE_TAG_SUPER_COLLECTION_HPP
+
+#ifndef IS_BUILDING_MB
+#error "SparseTagSuperCollection.hpp isn't supposed to be included into an application"
+#endif
+
+#ifdef WIN32
+#pragma warning(disable : 4786)
+#endif
+
+#include <map>
+#include <vector>
+
+#include "MBTypes.h"
+#include "MBInternals.hpp"
+#include "MBRange.hpp"
+#include "TagInfo.hpp"
+
+#define get_collection( A ) ((A) < mDataTags.size() ? mDataTags[(A)] : 0)
+
+class SparseTagCollection;
+
+//! a collection of SparseTagCollections
+class SparseTagSuperCollection
+{
+public:
+ //! constructor
+ SparseTagSuperCollection(){}
+
+ //! destructor
+ virtual ~SparseTagSuperCollection();
+
+ void reset_data();
+
+ //! allocate new tag id
+ MBErrorCode reserve_tag_id(int data_size, MBTagId tag_id);
+
+ //! releases an MBTagId
+ MBErrorCode release_tag_id(MBTagId tag_id);
+
+ //! size of data tag
+ int tag_size(const MBTagId tag_id) const;
+
+ //! set the data of a tag
+ MBErrorCode set_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, const void* data);
+
+ //! get the data of a tag
+ MBErrorCode get_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, void* data);
+
+ //! removes data
+ MBErrorCode remove_data(const MBTagId tag_handle, const MBEntityHandle entity_handle);
+
+ //! gets all entity handles that match a type and tag
+ MBErrorCode get_entities(const MBTagId tag_handle, MBRange &entities);
+
+ //! gets all entity handles that match a tag
+ MBErrorCode get_entities(const MBTagId tag_handle, const MBEntityType type,
+ MBRange &entities);
+
+ //! gets all entity handles that match a tag
+ MBErrorCode get_entities(const MBRange &range,
+ const MBTagId tag_handle, const MBEntityType type,
+ MBRange &entities);
+
+ //! gets all tags on a given entity handle
+ MBErrorCode get_tags(const MBEntityHandle entity,
+ std::vector<MBTag> &all_tags);
+
+ //! gets all entity handles that match a tag
+ MBErrorCode get_entities_with_tag_value( const MBTagId tag_handle,
+ const TagInfo& tag_info,
+ const MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size);
+
+ //! gets all entity handles that match a tag
+ MBErrorCode get_entities_with_tag_value( const MBRange &range,
+ const MBTagId tag_handle,
+ const TagInfo& tag_info,
+ const MBEntityType type,
+ MBRange &entities,
+ const void* tag_value,
+ int value_size);
+
+ //! gets the number of entities that match a tag
+ MBErrorCode get_number_entities(const MBTagId tag_handle, const MBEntityType type, int& num_ent);
+
+
+ //! gets the number of entities that match a tag
+ MBErrorCode get_number_entities(const MBRange &range,
+ const MBTagId tag_handle, const MBEntityType type, int& num_ent);
+
+ MBErrorCode get_memory_use( MBTagId tag_id,
+ unsigned long& total,
+ unsigned long& per_entity );
+
+private:
+
+ std::vector<SparseTagCollection*> mDataTags;
+};
+
+
+#endif //SPARSE_TAG_SUPER_COLLECTION_HPP
+
+
+
+
Modified: MOAB/trunk/TagServer.cpp
===================================================================
--- MOAB/trunk/TagServer.cpp 2008-01-24 22:31:26 UTC (rev 1559)
+++ MOAB/trunk/TagServer.cpp 2008-01-24 23:38:12 UTC (rev 1560)
@@ -40,7 +40,7 @@
#include <assert.h>
#include "TagServer.hpp"
#include "MBRange.hpp"
-#include "SparseTagCollections.hpp"
+#include "SparseTagSuperCollection.hpp"
#include "MBBits.hpp"
#include "MBInterface.hpp"
#include "SequenceManager.hpp"
More information about the moab-dev
mailing list