# HG changeset patch # User Chris Cannam # Date 1562247048 -3600 # Node ID d0ef65d8dd89a4b8449f24fe7edb60ebe2baffbe # Parent 356be36b23917671243ffa1b2aeb8ae9f12bc90c Return id from add(), + comment diff -r 356be36b2391 -r d0ef65d8dd89 base/ById.h --- a/base/ById.h Thu Jul 04 14:30:41 2019 +0100 +++ b/base/ById.h Thu Jul 04 14:30:48 2019 +0100 @@ -29,6 +29,18 @@ //!!! todo: docs +//!!! further possibilities: +// +// - id can only be queried when an object is added to ById (maybe +// add() returns the id, and there is a ById::idOf, but the +// object has no public getId()) +// +// - get() returns a pointer wrapper that cannot be shared/copied +// again by the caller (except by the usual C++ trickery) +// +// also to do: review how often we are calling getAs<...> when we +// could just be using get + struct IdAlloc { // The value NO_ID (-1) is never allocated @@ -144,12 +156,13 @@ class TypedById { public: - static void add(std::shared_ptr item) { + static Id add(std::shared_ptr item) { auto id = item->getId(); if (id.isNone()) { throw std::logic_error("item id should never be None"); } AnyById::add(id.untyped, item); + return id; } static void release(Id id) { diff -r 356be36b2391 -r d0ef65d8dd89 base/XmlExportable.h --- a/base/XmlExportable.h Thu Jul 04 14:30:41 2019 +0100 +++ b/base/XmlExportable.h Thu Jul 04 14:30:48 2019 +0100 @@ -30,6 +30,8 @@ NO_ID = -1 }; + typedef int ExportId; + XmlExportable() : m_exportId(NO_ID) { } virtual ~XmlExportable() { } @@ -38,7 +40,7 @@ * allocated the first time this is called, so objects on which * this is never called do not get allocated one. */ - int getExportId() const; + ExportId getExportId() const; /** * Stream this exportable object out to XML on a text stream.