NCBI C++ ToolKit
Templated interface for a generator of identifiers (IDs) of any type. More...
|typedef IIdGenerator< T >||TThisType|
|Type for the ID, which is a template parameter. |
|Enforce virtual destructor. |
|virtual TId||GenerateId ()=0|
|Generates the "next" id. |
|virtual bool||IsThreadSafe ()|
|Identifies if the implementation happens to be thread-safe. |
Templated interface for a generator of identifiers (IDs) of any type.
Generates the "next" id.
There is no specific constraint on the next id, except that it be effectively, if not actually, unique. Uniqueness is not a hard-core requirement, since wrap-around, limited reuse, and probabilistic uniqueness guarantees are all permitted, depending on the implementation details.
|if||an ID cannot be generated, perhaps because the generator has been excausted.|
Implemented in COrdinalFeatIdGenerator.
Identifies if the implementation happens to be thread-safe.
By default, implementations are not assumed thread-safe.
In dynamic situations, if a user requires a thread-safe ID generator, it is trivial to test for thread-safety, and if necessary, wrap all calls with a mutex (perhaps using a wrapper instance of this interface, that merely checks a mutex and delegates to the original). The wrapping could be made into a function, say, CIRef<IIdGenerator<> > MakeThreadSafe(IIdGenerator<>&). The design considered requiring the implementation to be thread-safe always, but this imposes possibly unnecessary requirements on all implementations. Defining a separate interface or member function to generate an ID with thread-safety was also considered, but some algorithms are thread-safe depending only on their injected dependencies, and calling different interfaces/functions complicates their implementation (e.g. may requires templates).