-
Notifications
You must be signed in to change notification settings - Fork 0
/
sli_name.cpp
109 lines (88 loc) · 2.41 KB
/
sli_name.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* sli_name.cc
*
* This file is part of NEST
*
* Copyright (C) 2004 by
* The NEST Initiative
*
* See the file AUTHORS for details.
*
* Permission is granted to compile and modify
* this file for non-commercial use.
* See the file LICENSE for details.
*
*/
#include "sli_name.h"
#include <iostream>
#include <iomanip>
std::size_t sli3::Name::capacity()
{
return sli3::Name::handleTableInstance_().size();
}
std::size_t sli3::Name::num_handles()
{
return sli3::Name::handleTableInstance_().size();
}
void sli3::Name::list_handles(std::ostream& out)
{
HandleTable_ &table=sli3::Name::handleTableInstance_();
std::size_t num_handles = table.size();
out << "Handle Table: \n";
out << "Total number of names : "<< num_handles << std::endl;
for ( std::size_t n=0; n< num_handles; ++n)
{
out << std::setw(6) << n << ": "
<< table[n] << std::endl;
}
}
void sli3::Name::print_handle(std::ostream &o) const
{
o << "/"<< handleTableInstance_()[handle_] << '('<<handle_ << ')';
}
// ---------------------------------------------------------------
const std::string& sli3::Name::toString(void) const
{
return handleTableInstance_()[handle_];
}
unsigned int sli3::Name::insert(const std::string &s)
{
sli3::Name::HandleMap_ &map=sli3::Name::handleMapInstance_();
sli3::Name::HandleMap_::const_iterator where=map.find(s);
if( where == map.end() )
{
// The following is more comlex code than a simple
// handleMap_[s] = Handle(s), but it avoids the creation
// of spurious Handle objects. HEP 2007-05-24
HandleTable_ &table=sli3::Name::handleTableInstance_();
unsigned int newhandle= table.size();
map.insert(std::make_pair(s, newhandle));
table.push_back(s);
return newhandle;
}
else
return ((*where).second);
}
void sli3::Name::list(std::ostream &out)
{
sli3::Name::HandleMap_ &map=handleMapInstance_();
out << "\nHandle Map content:" << std::endl;
for ( sli3::Name::HandleMap_::const_iterator where = map.begin();
where != map.end(); ++where )
{
out << (*where).first << " -> "
<< (*where).second
<< std::endl;
}
out << "\nHandle::handleTable_ content" << std::endl;
sli3::Name::list_handles(out);
}
void sli3::Name::info(std::ostream &out)
{
sli3::Name::list_handles(out);
}
std::ostream & sli3::operator<< (std::ostream & o, const sli3::Name &n)
{
o << n.toString().c_str() ;
return o;
}