NEST  2.6.0,not_revisioned_source_dir@0
name.h
Go to the documentation of this file.
1 /*
2  * name.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef NAME_H
24 #define NAME_H
25 
26 #include <cassert>
27 #include <map>
28 #include <string>
29 #include <deque>
30 #include <iostream>
31 
53 class Name
54 {
55 
56  public:
57  typedef unsigned int handle_t;
61  Name() : handle_(0) {}
62 
63  Name(const char s[]) : handle_(insert(std::string(s))) {}
64  Name(const std::string &s) : handle_(insert(s)) {}
65  Name(const Name &n) : handle_(n.handle_) {}
66 
70  const std::string& toString(void) const;
71 
75  handle_t toIndex(void) const
76  {
77  return handle_;
78  }
79 
80  bool operator== (const Name &n) const
81  {
82  return handle_ == n.handle_;
83  }
84 
85  bool operator!= (const Name &n) const
86  {
87  return !(handle_ == n.handle_);
88  }
89 
96  bool operator< (const Name &n) const
97  {
98  return handle_ < n.handle_;
99  }
100 
101  static bool lookup(const std::string &s)
102  {
104  return (table.find(s) != table.end());
105  }
106 
107  static
108  size_t capacity();
109  static
110  size_t num_handles();
111 
112  void print_handle(std::ostream&) const;
113 
114  static void list_handles(std::ostream &);
115  static void list(std::ostream &);
116  static void info(std::ostream &);
117 
118  private:
119  handle_t insert(const std::string&);
120 
124  typedef std::map<std::string, handle_t> HandleMap_;
125  typedef std::deque<std::string> HandleTable_;
126 
131  static HandleMap_& handleMapInstance_();
133 
138 };
139 
140 std::ostream& operator<<(std::ostream&, const Name&);
141 
142 
143 inline
145 {
146  // Meyers singleton, created first time function is invoked.
147 
148  static HandleTable_ handleTable(1,"0");
149 
150  return handleTable;
151 }
152 
153 inline
155 {
156  // Meyers singleton, created first time function is invoked.
157  static HandleMap_ handleMap;
158 
160 
161  return handleMap;
162 }
163 
164 
165 
166 #endif
static HandleTable_ & handleTableInstance_()
Definition: name.h:144
handle_t handle_
Handle for the name represented by the Name object.
Definition: name.h:137
std::deque< std::string > HandleTable_
Definition: name.h:125
bool operator!=(const Name &n) const
Definition: name.h:85
static void list(std::ostream &)
Definition: name.cc:88
static size_t capacity()
Definition: name.cc:29
static size_t num_handles()
Definition: name.cc:34
Name(const std::string &s)
Definition: name.h:64
bool operator==(const Name &n) const
Definition: name.h:80
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
static bool lookup(const std::string &s)
Definition: name.h:101
std::map< std::string, handle_t > HandleMap_
Datatype for map from strings to handles.
Definition: name.h:124
static void info(std::ostream &)
Definition: name.cc:104
const Name std("std")
Miscellaneous parameters.
Definition: nest_names.h:265
Name()
Create Name without value.
Definition: name.h:61
const std::string & toString(void) const
Return string represented by Name.
Definition: name.cc:63
bool operator<(const Name &n) const
Non-alphabetic ordering of names.
Definition: name.h:96
static void list_handles(std::ostream &)
Definition: name.cc:40
Name(const char s[])
Definition: name.h:63
std::ostream & operator<<(std::ostream &, const Name &)
Definition: name.cc:110
handle_t toIndex(void) const
Return table index for Name object.
Definition: name.h:75
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
handle_t insert(const std::string &)
Definition: name.cc:68
void print_handle(std::ostream &) const
Definition: name.cc:55
unsigned int handle_t
Definition: name.h:57
Name(const Name &n)
Definition: name.h:65
static HandleMap_ & handleMapInstance_()
Function returning a reference to the single map instance.
Definition: name.h:154