RavEngine
Loading...
Searching...
No Matches
CmCollection.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef CM_COLLECTION_H
30#define CM_COLLECTION_H
31
32#include "common/PxCollection.h"
33#include "foundation/PxHashMap.h"
34#include "foundation/PxUserAllocated.h"
35#include "foundation/PxAllocator.h"
36
37namespace physx
38{
39namespace Cm
40{
41 template <class Key,
42 class Value,
43 class HashFn = PxHash<Key>,
44 class Allocator = PxAllocator >
45 class CollectionHashMap : public PxCoalescedHashMap< Key, Value, HashFn, Allocator>
46 {
49
50 public:
51 CollectionHashMap(PxU32 initialTableSize = 64, float loadFactor = 0.75f):
52 PxCoalescedHashMap< Key, Value, HashFn, Allocator>(initialTableSize,loadFactor) {}
53
54 void insertUnique(const Key& k, const Value& v)
55 {
56 PX_PLACEMENT_NEW(MapBase::mBase.insertUnique(k), EntryData)(k,v);
57 }
58 };
59
61 {
62 public:
65
66 virtual void add(PxBase& object, PxSerialObjectId ref);
67 virtual void remove(PxBase& object);
68 virtual bool contains(PxBase& object) const;
69 virtual void addId(PxBase& object, PxSerialObjectId id);
70 virtual void removeId(PxSerialObjectId id);
71 virtual PxBase* find(PxSerialObjectId ref) const;
72 virtual void add(PxCollection& collection);
73 virtual void remove(PxCollection& collection);
74 virtual PxU32 getNbObjects() const;
75 virtual PxBase& getObject(PxU32 index) const;
76 virtual PxU32 getObjects(PxBase** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const;
77
78 virtual PxU32 getNbIds() const;
79 virtual PxSerialObjectId getId(const PxBase& object) const;
80 virtual PxU32 getIds(PxSerialObjectId* userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const;
81
82 void release() { PX_DELETE_THIS; }
83
84 // Only for internal use. Bypasses virtual calls, specialized behaviour.
85 PX_INLINE void internalAdd(PxBase* s, PxSerialObjectId id = PX_SERIAL_OBJECT_ID_INVALID) { mObjects.insertUnique(s, id); }
86 PX_INLINE PxU32 internalGetNbObjects() const { return mObjects.size(); }
87 PX_INLINE PxBase* internalGetObject(PxU32 i) const { PX_ASSERT(i<mObjects.size()); return mObjects.getEntries()[i].first; }
88 PX_INLINE const ObjectToIdMap::Entry* internalGetObjects() const { return mObjects.getEntries(); }
89
90 IdToObjectMap mIds;
91 ObjectToIdMap mObjects;
92 };
93}
94}
95
96#endif
Definition CmCollection.h:46
Definition CmCollection.h:61
virtual PxU32 getNbObjects() const
Gets number of PxBase objects in this collection.
Definition CmCollection.cpp:155
virtual void addId(PxBase &object, PxSerialObjectId id)
Adds an id to a member PxBase object.
Definition CmCollection.cpp:77
virtual PxSerialObjectId getId(const PxBase &object) const
Gets the PxSerialObjectId name of a PxBase object within the collection.
Definition CmCollection.cpp:183
virtual void remove(PxBase &object)
Removes a PxBase member object from the collection.
Definition CmCollection.cpp:60
virtual bool contains(PxBase &object) const
Returns whether the collection contains a certain PxBase object.
Definition CmCollection.cpp:72
virtual PxU32 getIds(PxSerialObjectId *userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const
Copies member PxSerialObjectId values to a user specified buffer.
Definition CmCollection.cpp:189
virtual void removeId(PxSerialObjectId id)
Removes id from a contained PxBase object.
Definition CmCollection.cpp:91
virtual PxBase * find(PxSerialObjectId ref) const
Looks for a PxBase object given a PxSerialObjectId value.
Definition CmCollection.cpp:103
virtual PxU32 getObjects(PxBase **userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const
Copies member PxBase pointers to a user specified buffer.
Definition CmCollection.cpp:166
virtual PxU32 getNbIds() const
Gets number of PxSerialObjectId names in this collection.
Definition CmCollection.cpp:178
virtual void add(PxBase &object, PxSerialObjectId ref)
Adds a PxBase object to the collection.
Definition CmCollection.cpp:34
void release()
Deletes a collection object.
Definition CmCollection.h:82
virtual PxBase & getObject(PxU32 index) const
Gets the PxBase object of this collection given its index.
Definition CmCollection.cpp:160
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Definition PxHashMap.h:101
Collection class for serialization.
Definition PxCollection.h:104
Definition PxHashInternals.h:695
Definition PxBasicTemplates.h:67
Definition PxUserAllocated.h:43
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU64 PxSerialObjectId
ID type for PxBase objects in a PxCollection.
Definition PxSerialFramework.h:61