0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
NameMatrix.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// OpenTrep
8
#include <
opentrep/NameMatrix.hpp
>
9
#include <
opentrep/service/Logger.hpp
>
10
11
namespace
OPENTREP
{
12
13
// //////////////////////////////////////////////////////////////////////
14
NameMatrix::NameMatrix
() {
15
}
16
17
// //////////////////////////////////////////////////////////////////////
18
NameMatrix::NameMatrix
(
const
NameMatrix
& iNameMatrix)
19
: _nameMatrix (iNameMatrix._nameMatrix) {
20
}
21
22
// //////////////////////////////////////////////////////////////////////
23
NameMatrix::~NameMatrix
() {
24
}
25
26
// //////////////////////////////////////////////////////////////////////
27
std::string
NameMatrix::describeKey
()
const
{
28
std::ostringstream oStr;
29
return
oStr.str();
30
}
31
32
// //////////////////////////////////////////////////////////////////////
33
std::string
NameMatrix::describe
()
const
{
34
std::ostringstream oStr;
35
oStr <<
describeKey
();
36
37
unsigned
short
idx = 0;
38
for
(NameMatrix_T::const_iterator itNameList = _nameMatrix.begin();
39
itNameList != _nameMatrix.end(); ++itNameList, ++idx) {
40
if
(idx != 0) {
41
oStr <<
","
;
42
}
43
const
Names
& lNameList = itNameList->second;
44
oStr << lNameList.
describe
();
45
}
46
47
return
oStr.str();
48
}
49
50
// //////////////////////////////////////////////////////////////////////
51
void
NameMatrix::toStream
(std::ostream& ioOut)
const
{
52
ioOut <<
describe
();
53
}
54
55
// //////////////////////////////////////////////////////////////////////
56
void
NameMatrix::fromStream
(std::istream& ioIn) {
57
}
58
59
// //////////////////////////////////////////////////////////////////////
60
std::string
NameMatrix::toString
()
const
{
61
std::ostringstream oStr;
62
oStr <<
describe
();
63
return
oStr.str();
64
}
65
66
// //////////////////////////////////////////////////////////////////////
67
bool
NameMatrix::getNameList
(
const
LanguageCode_T
& iLanguageCode,
68
NameList_T
& ioNameList)
const
{
69
bool
oFoundNameList =
false
;
70
71
NameMatrix_T::const_iterator itNameList = _nameMatrix.find (iLanguageCode);
72
if
(itNameList != _nameMatrix.end()) {
73
const
Names
& lNameList = itNameList->second;
74
ioNameList = lNameList.
getNameList
();
75
oFoundNameList =
true
;
76
}
77
78
return
oFoundNameList;
79
}
80
81
// //////////////////////////////////////////////////////////////////////
82
void
NameMatrix::addName
(
const
LanguageCode_T
& iLanguageCode,
83
const
std::string& iName) {
84
85
// Check whether a name in that language has already been recorded
86
NameMatrix_T::iterator itNameList = _nameMatrix.find (iLanguageCode);
87
if
(itNameList != _nameMatrix.end()) {
88
// Just add the name for that language
89
Names
& lNameList = itNameList->second;
90
91
lNameList.
addName
(iName);
92
93
}
else
{
94
// Create a new name list for the given language
95
Names
lNameList (iLanguageCode);
96
lNameList.
addName
(iName);
97
98
// Insert the name list with the dedicated list
99
const
bool
insertSucceeded =
100
_nameMatrix.insert (NameMatrix_T::value_type (iLanguageCode,
101
lNameList)).second;
102
if
(insertSucceeded ==
false
) {
103
OPENTREP_LOG_ERROR
(
"The "
<< iName <<
" name can not be inserted in "
104
<<
"the dedicated list for the "
105
<< iLanguageCode <<
" language"
);
106
}
107
assert (insertSucceeded ==
true
);
108
}
109
}
110
111
// //////////////////////////////////////////////////////////////////////
112
void
NameMatrix::reset
() {
113
_nameMatrix.clear();
114
}
115
116
}
Logger.hpp
OPENTREP_LOG_ERROR
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition
Logger.hpp:24
NameMatrix.hpp
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::NameList_T
std::list< std::string > NameList_T
Definition
Names.hpp:20
OPENTREP::LanguageCode_T
Definition
OPENTREP_Types.hpp:300
OPENTREP::NameMatrix::toStream
void toStream(std::ostream &) const
Definition
NameMatrix.cpp:51
OPENTREP::NameMatrix::fromStream
void fromStream(std::istream &)
Definition
NameMatrix.cpp:56
OPENTREP::NameMatrix::NameMatrix
NameMatrix()
Definition
NameMatrix.cpp:14
OPENTREP::NameMatrix::describeKey
std::string describeKey() const
Definition
NameMatrix.cpp:27
OPENTREP::NameMatrix::describe
std::string describe() const
Definition
NameMatrix.cpp:33
OPENTREP::NameMatrix::toString
std::string toString() const
Definition
NameMatrix.cpp:60
OPENTREP::NameMatrix::reset
void reset()
Definition
NameMatrix.cpp:112
OPENTREP::NameMatrix::getNameList
bool getNameList(const LanguageCode_T &, NameList_T &) const
Definition
NameMatrix.cpp:67
OPENTREP::NameMatrix::~NameMatrix
~NameMatrix()
Definition
NameMatrix.cpp:23
OPENTREP::NameMatrix::addName
void addName(const LanguageCode_T &, const std::string &iName)
Definition
NameMatrix.cpp:82
OPENTREP::Names
Definition
Names.hpp:26
OPENTREP::Names::addName
void addName(const std::string &iName)
Definition
Names.cpp:89
OPENTREP::Names::getNameList
const NameList_T & getNameList() const
Definition
Names.hpp:60
OPENTREP::Names::describe
std::string describe() const
Definition
Names.cpp:51
Generated on
for OpenTREP by
1.17.0