NEST  2.6.0,not_revisioned_source_dir@0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Name Class Reference

Represent strings by ints to facilitate fast comparison. More...

#include <name.h>

Inheritance diagram for Name:
AggregateDatum< Name,&SLIInterpreter::Literaltype > AggregateDatum< Name,&SLIInterpreter::Nametype > AggregateDatum< Name,&SLIInterpreter::Symboltype > LiteralDatum NameDatum SymbolDatum

Public Types

typedef unsigned int handle_t
 

Public Member Functions

 Name ()
 Create Name without value. More...
 
 Name (const char s[])
 
 Name (const std::string &s)
 
 Name (const Name &n)
 
const std::string & toString (void) const
 Return string represented by Name. More...
 
handle_t toIndex (void) const
 Return table index for Name object. More...
 
bool operator== (const Name &n) const
 
bool operator!= (const Name &n) const
 
bool operator< (const Name &n) const
 Non-alphabetic ordering of names. More...
 
void print_handle (std::ostream &) const
 

Static Public Member Functions

static bool lookup (const std::string &s)
 
static size_t capacity ()
 
static size_t num_handles ()
 
static void list_handles (std::ostream &)
 
static void list (std::ostream &)
 
static void info (std::ostream &)
 

Private Types

typedef std::map< std::string,
handle_t
HandleMap_
 Datatype for map from strings to handles. More...
 
typedef std::deque< std::string > HandleTable_
 

Private Member Functions

handle_t insert (const std::string &)
 

Static Private Member Functions

static HandleMap_handleMapInstance_ ()
 Function returning a reference to the single map instance. More...
 
static HandleTable_handleTableInstance_ ()
 

Private Attributes

handle_t handle_
 Handle for the name represented by the Name object. More...
 

Detailed Description

Represent strings by ints to facilitate fast comparison.

Each Name object represents a string by a unique integer number. Comparing Name objects instead of comparing strings directly, reduces the complexity of string comparison to that of int comparison.

Each Name object contains a Handle to the string it represents. Strings are mapped to Handles via an associative array. Handles are stored in a table, and each Handle contains its own index into this table as unique ID, as well as the string represented. Fast comparison of Name objects is achieved by comparing the indices stored in the handles. Reference counting permits deletion of unused Handles.

Note
Any string read by the interpreter should be converted to a Name at once.
class Name maintains two static lookup tables and is thus not thread-safe.

Member Typedef Documentation

typedef unsigned int Name::handle_t
typedef std::map<std::string, handle_t> Name::HandleMap_
private

Datatype for map from strings to handles.

typedef std::deque<std::string> Name::HandleTable_
private

Constructor & Destructor Documentation

Name::Name ( )
inline

Create Name without value.

Name::Name ( const char  s[])
inline
Name::Name ( const std::string &  s)
inline
Name::Name ( const Name n)
inline

Member Function Documentation

std::size_t Name::capacity ( )
static
Name::HandleMap_ & Name::handleMapInstance_ ( )
inlinestaticprivate

Function returning a reference to the single map instance.

Implementation akin to Meyers Singleton, see Alexandrescu, ch 6.4.

References handleTableInstance_().

Referenced by insert(), list(), and lookup().

Name::HandleTable_ & Name::handleTableInstance_ ( )
inlinestaticprivate
void Name::info ( std::ostream &  out)
static

References list_handles().

unsigned int Name::insert ( const std::string &  s)
private
void Name::list ( std::ostream &  out)
static
void Name::list_handles ( std::ostream &  out)
static

References handleTableInstance_(), nest::names::n, and num_handles().

Referenced by info(), and list().

static bool Name::lookup ( const std::string &  s)
inlinestatic

References handleMapInstance_().

Referenced by SLIType::settypename().

std::size_t Name::num_handles ( )
static
bool Name::operator!= ( const Name n) const
inline

References handle_.

bool Name::operator< ( const Name n) const
inline

Non-alphabetic ordering of names.

Entering Name's into dictionaries requires ordering. Ordering based on string comparison would be very slow. We thus compare based on table indices.

References handle_.

bool Name::operator== ( const Name n) const
inline

References handle_.

void Name::print_handle ( std::ostream &  o) const

References handle_, and handleTableInstance_().

handle_t Name::toIndex ( void  ) const
inline
const std::string & Name::toString ( void  ) const

Return string represented by Name.

References handle_, and handleTableInstance_().

Referenced by __pyx_f_12pynestkernel_sli_datum_to_object(), nest::GenericFactory< BaseT >::create(), SLIInterpreter::createcommand(), nest::Network::divergent_connect(), MathLinkPutStringFunction::execute(), XIfstreamFunction::execute(), IfstreamFunction::execute(), OfstreamFunction::execute(), OfsopenFunction::execute(), IsstreamFunction::execute(), StrSStreamFunction::execute(), StrFunction::execute(), PrettyprintFunction::execute(), CloseistreamFunction::execute(), CloseostreamFunction::execute(), FlushFunction::execute(), EndlFunction::execute(), EndsFunction::execute(), EatwhiteFunction::execute(), SetwFunction::execute(), SetprecisionFunction::execute(), IOSFixedFunction::execute(), IOSScientificFunction::execute(), IOSDefaultFunction::execute(), IOSShowpointFunction::execute(), IOSNoshowpointFunction::execute(), IOSShowbaseFunction::execute(), IOSNoshowbaseFunction::execute(), IOSDecFunction::execute(), nest::NestModule::SetDefaults_l_DFunction::execute(), IOSHexFunction::execute(), nest::NestModule::GetDefaults_lFunction::execute(), IOSOctFunction::execute(), IOSLeftFunction::execute(), IOSRightFunction::execute(), IOSInternalFunction::execute(), GetcFunction::execute(), GetsFunction::execute(), GetlineFunction::execute(), IGoodFunction::execute(), IClearFunction::execute(), OClearFunction::execute(), IFailFunction::execute(), OGoodFunction::execute(), IEofFunction::execute(), OEofFunction::execute(), In_AvailFunction::execute(), ReadDoubleFunction::execute(), ReadIntFunction::execute(), ReadWordFunction::execute(), nest::Network::execute_sli_protected(), nest::Time::ms::fromtoken(), getValue< bool >(), getValue< double >(), getValue< float >(), getValue< long >(), getValue< std::string >(), getValue< std::vector< double > >(), getValue< std::vector< long > >(), Dictionary::lookup2(), DictionaryStack::lookup2(), nest::UnknownModelName::message(), operator<<(), Dictionary::operator[](), setValue< bool >(), setValue< double >(), setValue< float >(), setValue< long >(), setValue< std::string >(), setValue< std::valarray< double > >(), setValue< std::valarray< long > >(), setValue< std::vector< double > >(), setValue< std::vector< long > >(), TokenArray::toValarray(), TokenArray::toVector(), and DictionaryStack::undef().

Member Data Documentation

handle_t Name::handle_
private

Handle for the name represented by the Name object.

Referenced by operator!=(), operator<(), operator==(), print_handle(), toIndex(), and toString().


The documentation for this class was generated from the following files: