Skip to content

Commit

Permalink
Merge pull request #1443 from LLNL/feature/nselliott/core-collections
Browse files Browse the repository at this point in the history
Move ItemCollection and derived classes to core
  • Loading branch information
nselliott authored Oct 30, 2024
2 parents 7d4e77a + cfbf6a6 commit e5b5707
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 142 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
### Added

### Changed
- ItemCollection and its child classes MapCollection, ListCollection, and IndexedCollection were moved from Sidre
to core. The namespace prefix for these classes is now axom:: insteand of axom::sidre. The internal usage of
these types within Sidre Datastore and Group is unchanged.

### Deprecated

Expand Down
4 changes: 4 additions & 0 deletions src/axom/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ set(core_headers
ArrayIteratorBase.hpp
ArrayView.hpp
MDMapping.hpp
IndexedCollection.hpp
ItemCollection.hpp
IteratorBase.hpp
ListCollection.hpp
Macros.hpp
Map.hpp
MapCollection.hpp
FlatMap.hpp
NumericLimits.hpp
Path.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@
#define SIDRE_INDEXED_COLLECTION_HPP_

// Standard C++ headers
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

// Other axom headers
#include "axom/config.hpp"
#include "axom/core/Types.hpp"
#include "axom/core/ItemCollection.hpp"
#include "axom/core/Macros.hpp"

// Sidre project headers
#include "SidreTypes.hpp"
#include "ItemCollection.hpp"
#include "axom/core/Types.hpp"

namespace axom
{
namespace sidre
{
/*!
*************************************************************************
*
Expand Down Expand Up @@ -99,18 +95,18 @@ class IndexedCollection : public ItemCollection<T>
/*!
* \brief Insert \a item at index \a idx if that index is not already occupied
*
* \return Index at which \a item was inserted, if successful; sidre::InvalidIndex otherwise
* \return Index at which \a item was inserted, if successful; axom::InvalidIndex otherwise
*/
IndexType insertItem(T* item, IndexType idx)
{
if(hasItem(idx))
{
return sidre::InvalidIndex;
return axom::InvalidIndex;
}

if(idx < 0)
{
return sidre::InvalidIndex;
return axom::InvalidIndex;
}

// grow capacity to support insertion at index
Expand Down Expand Up @@ -172,7 +168,7 @@ class IndexedCollection : public ItemCollection<T>
*/
IndexType getValidEmptyIndex()
{
IndexType newIndex = sidre::InvalidIndex;
IndexType newIndex = axom::InvalidIndex;
bool found_empty_index = false;

// try to find an empty index from the stack
Expand All @@ -195,9 +191,15 @@ class IndexedCollection : public ItemCollection<T>
newIndex = m_items.size();
}

SLIC_ASSERT_MSG(
isInClosedRange(newIndex) && !hasItem(newIndex),
"Index " << newIndex << " in IndexedCollection is not a valid empty index");
#ifdef AXOM_DEBUG
if(!isInClosedRange(newIndex) || hasItem(newIndex))
{
std::cerr << "Index " << newIndex
<< " in IndexedCollection is not a valid empty index"
<< std::endl;
}
assert(isInClosedRange(newIndex) && !hasItem(newIndex));
#endif

return newIndex;
}
Expand Down Expand Up @@ -283,7 +285,6 @@ T* IndexedCollection<T>::removeItem(IndexType idx)
return nullptr;
}

} // end namespace sidre
} // end namespace axom

#endif // SIDRE_INDEXED_COLLECTION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* This is a templated abstract base class defining an interface for
* classes holding a collection of items of a fixed
* type that can be accessed by string name or sidre::IndexType.
* type that can be accessed by string name or axom::IndexType.
*
* The primary intent is to decouple the implementation of the
* collections from the Group class which owns collections of
Expand All @@ -39,54 +39,30 @@
* size_t getNumItems() const;
*
* - // Return first valid item index for iteration.
* // sidre::InvalidIndex returned if no items in collection
* // axom::InvalidIndex returned if no items in collection
*
* IndexType getFirstValidIndex() const;
*
* - // Return next valid item index for iteration.
* // sidre::InvalidIndex returned if there are no more items
* // axom::InvalidIndex returned if there are no more items
* // to be iterated over.
*
* IndexType getNextValidIndex(IndexType idx) const;
*
* - // Return true if item with given name in collection; else false.
*
* bool hasItem(const std::string& name) const;
*
* - // Return true if item with given index in collection; else false.
*
* bool hasItem(IndexType idx) const;
*
* - // Return pointer to item with given name (nullptr if none).
*
* T* getItem(const std::string& name);
* T const* getItem(const std::string& name) const ;
*
* - // Return pointer to item with given index (nullptr if none).
*
* T* getItem(IndexType idx);
* T const* getItem(IndexType idx) const;
*
* - // Return name of object with given index
* // (sidre::InvalidName if none).
*
* std::string getItemName(IndexType idx) const;
*
* - // Return index of object with given name
* // (sidre::InvalidIndex if none).
*
* IndexType getItemIndex(const std::string& name) const;
*
* - // Insert item with given name; return index if insertion
* // succeeded, and InvalidIndex otherwise.
*
* IndexType insertItem(T* item, const std::string& name);
*
* - // Remove item with given name if it exists and return a
* // pointer to it. If it doesn't exist, return nullptr.
*
* T* removeItem(const std::string& name);
*
* - // Remove item with given index if it exists and return a
* // pointer to it. If it doesn't exist, return nullptr.
*
Expand All @@ -96,30 +72,23 @@
*
* void removeAllItems();
*
* - // Clear all items and destroy them.
*
* void deleteAllItems();
*
* \endverbatim
*
******************************************************************************
*/

#ifndef SIDRE_ITEMCOLLECTIONS_HPP_
#define SIDRE_ITEMCOLLECTIONS_HPP_
#ifndef AXOM_ITEMCOLLECTIONS_HPP_
#define AXOM_ITEMCOLLECTIONS_HPP_

#include <string>

// Other axom headers
#include "axom/config.hpp"
#include "axom/core/Types.hpp"
#include "axom/core/IteratorBase.hpp"

// Sidre project headers
#include "SidreTypes.hpp"

namespace axom
{
namespace sidre
{
/*!
*************************************************************************
*
Expand Down Expand Up @@ -221,9 +190,9 @@ class ItemCollection<T>::iterator : public IteratorBase<iterator, IndexType>
public:
iterator(CollectionType* coll, bool is_first) : m_collection(coll)
{
SLIC_ASSERT(coll != nullptr);
assert(coll != nullptr);

BaseType::m_pos = is_first ? coll->getFirstValidIndex() : sidre::InvalidIndex;
BaseType::m_pos = is_first ? coll->getFirstValidIndex() : axom::InvalidIndex;
}

IndexType index() const { return BaseType::m_pos; }
Expand Down Expand Up @@ -275,9 +244,9 @@ class ItemCollection<T>::const_iterator
public:
const_iterator(const CollectionType* coll, bool is_first) : m_collection(coll)
{
SLIC_ASSERT(coll != nullptr);
assert(coll != nullptr);

BaseType::m_pos = is_first ? coll->getFirstValidIndex() : sidre::InvalidIndex;
BaseType::m_pos = is_first ? coll->getFirstValidIndex() : axom::InvalidIndex;
}

IndexType index() const { return BaseType::m_pos; }
Expand Down Expand Up @@ -364,7 +333,6 @@ class ItemCollection<T>::const_iterator_adaptor
const CollectionType* m_collection {nullptr};
};

} /* end namespace sidre */
} /* end namespace axom */

#endif /* SIDRE_ITEMCOLLECTIONS_HPP_ */
#endif /* AXOM_ITEMCOLLECTIONS_HPP_ */
3 changes: 3 additions & 0 deletions src/axom/core/IteratorBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#ifndef AXOM_ITERBASE_HPP_
#define AXOM_ITERBASE_HPP_

#include "axom/config.hpp"
#include "axom/core/Macros.hpp"

namespace axom
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
* size_t getNumItems() const;
*
* - // Return first item index for iteration.
* // sidre::InvalidIndex returned if no items in collection
* // axom::InvalidIndex returned if no items in collection
*
* IndexType getFirstValidIndex() const;
*
* - // Return next valid item index for iteration.
* // sidre::InvalidIndex returned if there are no further items
* // axom::InvalidIndex returned if there are no further items
*
* IndexType getNextValidIndex(IndexType idx) const;
* *
Expand Down Expand Up @@ -75,10 +75,11 @@
******************************************************************************
*/

#ifndef SIDRE_LISTCOLLECTIONS_HPP_
#define SIDRE_LISTCOLLECTIONS_HPP_
#ifndef AXOM_LISTCOLLECTIONS_HPP_
#define AXOM_LISTCOLLECTIONS_HPP_

// Standard C++ headers
#include <iostream>
#include <map>
#include <list>
#include <stack>
Expand All @@ -90,13 +91,10 @@
#include "axom/core/Types.hpp"

// Sidre project headers
#include "SidreTypes.hpp"
#include "ItemCollection.hpp"
#include "axom/core/ItemCollection.hpp"

namespace axom
{
namespace sidre
{
////////////////////////////////////////////////////////////////////////
//
// ListCollection keeps an index constant for each item
Expand Down Expand Up @@ -224,10 +222,16 @@ IndexType ListCollection<T>::getNextValidIndex(IndexType idx) const
template <typename T>
IndexType ListCollection<T>::insertItem(T* item, const std::string& name)
{
SLIC_WARNING_IF(!name.empty(),
"Item " << name << " added to Group "
<< "which holds items in list format. "
<< "The name of this item will be ignored.");
#ifdef AXOM_DEBUG
if(!name.empty())
{
std::cerr << "Item " << name << " added to Group "
<< "which holds items in list format. "
<< "The name of this item will be ignored." << std::endl;
}
#else
AXOM_UNUSED_VAR(name);
#endif

bool use_recycled_index = false;
IndexType idx = m_items.size();
Expand Down Expand Up @@ -273,7 +277,6 @@ T* ListCollection<T>::removeItem(IndexType idx)
return ret_val;
}

} /* end namespace sidre */
} /* end namespace axom */

#endif /* SIDRE_LIST_COLLECTIONS_HPP_ */
#endif /* AXOM_LIST_COLLECTIONS_HPP_ */
Loading

0 comments on commit e5b5707

Please sign in to comment.