comparison base/ById.h @ 1840:7faa08747f5e

Comments
author Chris Cannam
date Tue, 14 Apr 2020 08:19:23 +0100
parents 0678bf772f82
children
comparison
equal deleted inserted replaced
1839:915d316a5609 1840:7faa08747f5e
65 * it, then the ById store will return a null shared_ptr from its 65 * it, then the ById store will return a null shared_ptr from its
66 * get() function for that id; but if it returns a non-null 66 * get() function for that id; but if it returns a non-null
67 * shared_ptr, then the object being pointed to can't be deleted while 67 * shared_ptr, then the object being pointed to can't be deleted while
68 * that shared_ptr is in scope. 68 * that shared_ptr is in scope.
69 * 69 *
70 * The result is like using weak_ptr references to a shared_ptr whose
71 * ownership is within a "layer" (at "application level") rather than
72 * managed by a specific object. A human-readable id representation is
73 * also quite useful for debugging.
74 *
70 * Example: 75 * Example:
71 * 76 *
72 * class Thing : public WithTypedId<Thing> { Thing(int x) { } }; 77 * class Thing : public WithTypedId<Thing> { Thing(int x) { } };
73 * typedef TypedById<Thing, Thing::Id> ThingById; 78 * typedef TypedById<Thing, Thing::Id> ThingById;
74 * 79 *
180 template <typename Item, typename Id> 185 template <typename Item, typename Id>
181 friend class TypedById; 186 friend class TypedById;
182 187
183 /** 188 /**
184 * Return an id for this object. The id is a unique value for this 189 * Return an id for this object. The id is a unique value for this
185 * object among all objects that implement WithTypedId within this 190 * object among all objects that implement WithId within this
186 * single run of the application. 191 * single run of the application.
187 */ 192 */
188 Id getId() const { 193 Id getId() const {
189 Id id; 194 Id id;
190 id.untyped = getUntypedId(); 195 id.untyped = getUntypedId();