NCBI C++ ToolKit
Public Types | Public Member Functions
IIdGenerator< T > Class Template Reference

Search Toolkit Book for IIdGenerator

Templated interface for a generator of identifiers (IDs) of any type. More...

#include <objtools/readers/reader_idgen.hpp>

+ Inheritance diagram for IIdGenerator< T >:
+ Collaboration diagram for IIdGenerator< T >:

List of all members.

Public Types

typedef IIdGenerator< T > TThisType
typedef T TId
 Type for the ID, which is a template parameter.

Public Member Functions

virtual ~IIdGenerator ()
 Enforce virtual destructor.
virtual TId GenerateId ()=0
 Generates the "next" id.
virtual bool IsThreadSafe ()
 Identifies if the implementation happens to be thread-safe.

Detailed Description

template<class T>
class IIdGenerator< T >

Templated interface for a generator of identifiers (IDs) of any type.

Definition at line 54 of file reader_idgen.hpp.

Member Typedef Documentation

template<class T>
typedef T IIdGenerator< T >::TId

Type for the ID, which is a template parameter.

Definition at line 61 of file reader_idgen.hpp.

template<class T>
typedef IIdGenerator<T> IIdGenerator< T >::TThisType

Constructor & Destructor Documentation

template<class T>
virtual IIdGenerator< T >::~IIdGenerator ( ) [inline, virtual]

Enforce virtual destructor.

Definition at line 64 of file reader_idgen.hpp.

Member Function Documentation

template<class T>
virtual TId IIdGenerator< T >::GenerateId ( ) [pure virtual]

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.

ifan ID cannot be generated, perhaps because the generator has been excausted.
TId should be a CRef in the case of CObject instance, an AutoPtr for other non copy-constructible objects, and otherwise, should have value semantics.

Implemented in COrdinalFeatIdGenerator.

template<class T>
virtual bool IIdGenerator< T >::IsThreadSafe ( ) [inline, virtual]

Identifies if the implementation happens to be thread-safe.

By default, implementations are not assumed thread-safe.

true if the implementation is known to be thread-safe, false otherwise (may be thread-safe, but not assured).
This function admits a client that will respond dynamically to the issue of thread-safety. Callers might use this to optimize away mutual exclusion in MT situations, but if they require thread-safety, it is advisable to require an ITheadSafeIdGenerator.

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).

Reimplemented in IThreadSafeIdGenerator< T >, and IThreadSafeIdGenerator< CRef< CFeat_id > >.

Definition at line 113 of file reader_idgen.hpp.

The documentation for this class was generated from the following file:
Modified on Sun Mar 01 14:32:39 2015 by rev. 426318