The C++ framework for developing highly scalable, high performance servers on Windows platforms.

CNamedIndex Class Reference
[Opaque user data]

Collaboration diagram for CNamedIndex:

List of all members.


Detailed Description

A class that provides a collection of named indices. That is it allows you to Add() or Find() a name to a collection and return an index that identifies that name within the collection. Once you have added as many names as you wish you can convert the collection of names into a read-only collection by calling Lock() on the collection. The class is designed to be used to allow unrelated blocks of code to request a unique index for use in accessing opaque user data from an instance of IIndexedOpaqueUserData. The blocks of code needing an index typically request one by name (usually based on the name of the class doing the requesting). Once all names have been requested, Lock() is called and the size of the user data block required is calculated by calling GetMaxIndexValue() to return the number of indices requested.


Public Types

typedef unsigned short Index

Public Member Functions

 CNamedIndex ()
 Construct an empty collection.
 CNamedIndex (Index maxIndices)
 CNamedIndex (const CNamedIndex &rhs)
CNamedIndexoperator= (const CNamedIndex &rhs)
Index Add (const _tstring &name)
 Allocates a new index called name and returns the value. Throws an exception if the name already exists or if the collection has already had Lock() called on it.
Index Find (const _tstring &name) const
 Finds an index called name and returns the value. Throws an exception if the name does not exist.
Index FindOrAdd (const _tstring &name)
 First attempts to Find() an index by name and if the name doesn't already exist then creates a new index called name and returns the value. Throws an exception if the collection has already had Lock() called on it.
Index GetMaxIndexValue () const
 Returns the number of indices allocated.
Index Lock ()
 Locks the collection against further additions and returns the number of indices allocated.
bool Locked () const
 Returns true if the collection is locked.


Member Typedef Documentation

typedef unsigned short Index


Constructor & Destructor Documentation

CNamedIndex (  ) 

Construct an empty collection.

CNamedIndex ( Index  maxIndices  )  [explicit]

CNamedIndex ( const CNamedIndex rhs  ) 


Member Function Documentation

CNamedIndex& operator= ( const CNamedIndex rhs  ) 

CNamedIndex::Index Add ( const _tstring name  ) 

Allocates a new index called name and returns the value. Throws an exception if the name already exists or if the collection has already had Lock() called on it.

CNamedIndex::Index Find ( const _tstring name  )  const

Finds an index called name and returns the value. Throws an exception if the name does not exist.

CNamedIndex::Index FindOrAdd ( const _tstring name  ) 

First attempts to Find() an index by name and if the name doesn't already exist then creates a new index called name and returns the value. Throws an exception if the collection has already had Lock() called on it.

CNamedIndex::Index GetMaxIndexValue (  )  const

Returns the number of indices allocated.

CNamedIndex::Index Lock (  ) 

Locks the collection against further additions and returns the number of indices allocated.

bool Locked (  )  const

Returns true if the collection is locked.


Generated on Sun Sep 12 19:08:43 2021 for The Server Framework - v7.4 by doxygen 1.5.3