8#ifndef INCLUDED_BDLCC_OBJECTCATALOG
9#define INCLUDED_BDLCC_OBJECTCATALOG
300#include <bdlscm_version.h>
328#include <bsl_utility.h>
329#include <bsl_vector.h>
331#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
341class ObjectCatalog_AutoCleanup;
343class ObjectCatalogIter;
362 bool d_deallocateFlag;
389 bool deallocateFlag);
421 k_INDEX_MASK = 0x007fffff,
422 k_BUSY_INDICATOR = 0x00800000,
423 k_GENERATION_INC = 0x01000000,
424 k_GENERATION_MASK = 0xff000000
443 Node *d_nextFreeNode_p;
462 static TYPE *getNodeValue(Node *node);
471 void freeNode(Node *node);
476 template <
class VECTOR>
477 void removeAllImp(VECTOR *buffer);
483 Node *findNode(
int handle)
const;
505 int add(TYPE
const&
object);
518 int remove(
int handle, TYPE *valueBuffer = 0);
526#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
527 void removeAll(std::pmr::vector<TYPE> *buffer);
533 int replace(
int handle,
const TYPE& newObject);
554 int find(
int handle, TYPE *valueBuffer)
const;
565 "use 'ObjectCatalogIter::value()' instead")
572 const TYPE& value(
int handle) const;
600 bsl::ptrdiff_t d_index;
609 template <
class BDE_OTHER_TYPE>
612 template <
class BDE_OTHER_TYPE>
647 operator const void *()
const;
661 const TYPE& value()
const;
676: d_catalog_p(catalog)
678, d_deallocateFlag(false)
685 if (d_catalog_p && d_node_p) {
686 if (d_deallocateFlag) {
689 d_catalog_p->d_nodePool.deallocate(d_node_p);
693 d_catalog_p->freeNode(d_node_p);
705 d_deallocateFlag = deallocateFlag;
733 return node->d_payload.d_value.address();
739void ObjectCatalog<TYPE>::freeNode(
typename ObjectCatalog<TYPE>::Node *node)
743 node->d_handle += k_GENERATION_INC;
744 node->d_handle &= ~k_BUSY_INDICATOR;
746 node->d_payload.d_next_p = d_nextFreeNode_p;
747 d_nextFreeNode_p = node;
752template <
class VECTOR>
753void ObjectCatalog<TYPE>::removeAllImp(VECTOR *buffer)
755 static const bool isVector =
757#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
767 for (VIt it = d_nodes.
begin(); it != d_nodes.
end(); ++it) {
768 if ((*it)->d_handle & k_BUSY_INDICATOR) {
769 TYPE *value = getNodeValue(*it);
785 d_nextFreeNode_p = 0;
792typename ObjectCatalog<TYPE>::Node *
793ObjectCatalog<TYPE>::findNode(
int handle)
const
795 int index = handle & k_INDEX_MASK;
799 index >= (
int)d_nodes.
size() ||
800 !(handle & k_BUSY_INDICATOR)) {
804 Node *node = d_nodes[index];
806 return node->d_handle == handle ? node : 0;
814, d_nodePool(sizeof(Node), allocator)
836 if (d_nextFreeNode_p) {
837 node = d_nextFreeNode_p;
838 d_nextFreeNode_p = node->d_payload.d_next_p;
848 node =
static_cast<Node *
>(d_nodePool.
allocate());
853 node->d_handle =
static_cast<int>(d_nodes.
size()) - 1;
859 node->d_handle |= k_BUSY_INDICATOR;
860 handle = node->d_handle;
865 getNodeValue(node),
object, d_nodes.
get_allocator().mechanism());
879 TYPE& local = object;
886 if (d_nextFreeNode_p) {
887 node = d_nextFreeNode_p;
888 d_nextFreeNode_p = node->d_payload.d_next_p;
898 node =
static_cast<Node *
>(d_nodePool.
allocate());
903 node->d_handle =
static_cast<int>(d_nodes.
size()) - 1;
909 node->d_handle |= k_BUSY_INDICATOR;
910 handle = node->d_handle;
915 getNodeValue(node), local, d_nodes.
get_allocator().mechanism());
932 Node *node = findNode(handle);
938 TYPE *value = getNodeValue(node);
962 removeAllImp(buffer);
969 removeAllImp(buffer);
972#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
977 removeAllImp(buffer);
986 Node *node = findNode(handle);
992 TYPE *value = getNodeValue(node);
1004template <
class TYPE>
1007 TYPE& local = newObject;
1011 Node *node = findNode(handle);
1017 TYPE *value = getNodeValue(node);
1030template <
class TYPE>
1037template <
class TYPE>
1043 return 0 == findNode(handle) ? -1 : 0;
1046template <
class TYPE>
1052 Node *node = findNode(handle);
1058 *valueBuffer = *getNodeValue(node);
1063template <
class TYPE>
1066 for (
Iter it(*
this); it; ++it) {
1067 if (it.value() ==
object) {
1075template <
class TYPE>
1082template <
class TYPE>
1088 Node *node = findNode(handle);
1092 return *getNodeValue(node);
1095template <
class TYPE>
1103 unsigned numBusy = 0, numFree = 0;
1104 for (
unsigned ii = 0; ii < d_nodes.
size(); ++ii) {
1105 const int handle = d_nodes[ii]->d_handle;
1107 handle & k_BUSY_INDICATOR ? ++numBusy
1110 BSLS_ASSERT( numBusy ==
static_cast<unsigned>(d_length));
1113 for (
const Node *p = d_nextFreeNode_p; p; p = p->d_payload.d_next_p) {
1125template <
class TYPE>
1128: d_catalog_p(&catalog)
1131 d_catalog_p->d_lock.lockRead();
1135template <
class TYPE>
1139: d_catalog_p(&catalog)
1142 typedef typename Catalog::Node Node;
1144 d_catalog_p->d_lock.lockRead();
1146 Node *node = d_catalog_p->findNode(
handle);
1147 d_index = node ? node->d_handle & Catalog::k_INDEX_MASK
1151template <
class TYPE>
1155 d_catalog_p->d_lock.unlock();
1159template <
class TYPE>
1163 while ((
unsigned)d_index < d_catalog_p->d_nodes.
size() &&
1164 !(d_catalog_p->d_nodes[d_index]->d_handle &
1170template <
class TYPE>
1174 BSLS_ASSERT(
static_cast<unsigned>(d_index) < d_catalog_p->d_nodes.size());
1176 return d_catalog_p->d_nodes[d_index]->d_handle;
1179template <
class TYPE>
1183 BSLS_ASSERT(
static_cast<unsigned>(d_index) < d_catalog_p->d_nodes.size());
1191template <
class TYPE>
1195 return static_cast<unsigned>(d_index) < d_catalog_p->d_nodes.size()
1202template <
class TYPE>
1208 typename Catalog::Node *node = d_catalog_p->d_nodes[d_index];
Definition bdlcc_objectcatalog.h:597
~ObjectCatalogIter()
Destroy this iterator and unlock the catalog associated with it.
Definition bdlcc_objectcatalog.h:1153
const TYPE & value() const
Definition bdlcc_objectcatalog.h:1181
void operator++()
Definition bdlcc_objectcatalog.h:1160
int handle() const
Definition bdlcc_objectcatalog.h:1172
bsl::pair< int, TYPE > operator()() const
Definition bdlcc_objectcatalog.h:1204
Definition bdlcc_objectcatalog.h:357
void manageNode(typename ObjectCatalog< TYPE >::Node *node, bool deallocateFlag)
Definition bdlcc_objectcatalog.h:700
void releaseNode()
Definition bdlcc_objectcatalog.h:709
~ObjectCatalog_AutoCleanup()
Definition bdlcc_objectcatalog.h:683
void release()
Definition bdlcc_objectcatalog.h:715
Definition bdlcc_objectcatalog.h:412
int add(TYPE const &object)
Definition bdlcc_objectcatalog.h:829
int replace(int handle, const TYPE &newObject)
Definition bdlcc_objectcatalog.h:982
int find(int handle) const
Definition bdlcc_objectcatalog.h:1039
void removeAll()
Definition bdlcc_objectcatalog.h:953
ObjectCatalog(bslma::Allocator *allocator=0)
Definition bdlcc_objectcatalog.h:812
int remove(int handle, TYPE *valueBuffer=0)
Definition bdlcc_objectcatalog.h:928
int replace(int handle, bslmf::MovableRef< TYPE > newObject)
Definition bdlcc_objectcatalog.h:1005
void removeAll(std::vector< TYPE > *buffer)
Definition bdlcc_objectcatalog.h:967
BSLS_DEPRECATE_FEATURE("bde", "ObjectCataloog::value(handle)", "use 'ObjectCatalogIter::value()' instead") const TYPE &value(int handle) const
bslma::Allocator * allocator() const
Return the allocator used by this object.
Definition bdlcc_objectcatalog.h:1032
int add(bslmf::MovableRef< TYPE > object)
Definition bdlcc_objectcatalog.h:877
BSLMF_NESTED_TRAIT_DECLARATION(ObjectCatalog, bslma::UsesBslmaAllocator)
void removeAll(bsl::vector< TYPE > *buffer)
Definition bdlcc_objectcatalog.h:960
int length() const
Definition bdlcc_objectcatalog.h:1077
~ObjectCatalog()
Destroy this object catalog.
Definition bdlcc_objectcatalog.h:822
bool isMember(const TYPE &object) const
Definition bdlcc_objectcatalog.h:1064
void verifyState() const
Definition bdlcc_objectcatalog.h:1096
int find(int handle, TYPE *valueBuffer) const
Definition bdlcc_objectcatalog.h:1048
Definition bdlma_pool.h:335
bslma::Allocator * allocator() const
Definition bdlma_pool.h:621
void * allocate()
Definition bdlma_pool.h:562
void release()
Relinquish all memory currently allocated via this pool object.
Definition bdlma_pool.h:603
Definition bslstl_pair.h:1210
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this vector.
Definition bslstl_vector.h:2664
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2511
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2519
Definition bslstl_vector.h:1025
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:4019
void push_back(const VALUE_TYPE &value)
Definition bslstl_vector.h:3760
VALUE_TYPE * iterator
Definition bslstl_vector.h:1057
void swap(vector &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:1712
Definition bslma_allocator.h:457
Definition bslmf_movableref.h:751
Definition bslmt_rwmutex.h:147
Definition bslmt_readlockguard.h:287
Definition bslmt_writelockguard.h:221
Definition bsls_atomic.h:743
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:609
#define BSLS_REVIEW_OPT(X)
Definition bsls_review.h:977
Definition bdlcc_boundedqueue.h:270
BSLS_KEYWORD_CONSTEXPR std::ptrdiff_t ssize(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1394
Definition bslmf_issame.h:146
static void moveConstruct(TARGET_TYPE *address, TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1642
static void copyConstruct(TARGET_TYPE *address, const TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1599
Definition bslma_usesbslmaallocator.h:343
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060
Definition bdlcc_objectcatalog.h:429
Node * d_next_p
Definition bdlcc_objectcatalog.h:433
bsls::ObjectBuffer< TYPE > d_value
Definition bdlcc_objectcatalog.h:431
Definition bsls_objectbuffer.h:276