OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NameMatrix.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // OpenTrep
10 
11 namespace OPENTREP {
12 
13  // //////////////////////////////////////////////////////////////////////
15  }
16 
17  // //////////////////////////////////////////////////////////////////////
18  NameMatrix::NameMatrix (const NameMatrix& iNameMatrix)
19  : _nameMatrix (iNameMatrix._nameMatrix) {
20  }
21 
22  // //////////////////////////////////////////////////////////////////////
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  // //////////////////////////////////////////////////////////////////////
113  _nameMatrix.clear();
114  }
115 
116 }
bool getNameList(const LanguageCode_T &, NameList_T &) const
Definition: NameMatrix.cpp:67
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:23
void addName(const LanguageCode_T &, const std::string &iName)
Definition: NameMatrix.cpp:82
void toStream(std::ostream &) const
Definition: NameMatrix.cpp:51
void fromStream(std::istream &)
Definition: NameMatrix.cpp:56
std::string describeKey() const
Definition: NameMatrix.cpp:27
std::list< std::string > NameList_T
Definition: Names.hpp:20
void addName(const std::string &iName)
Definition: Names.cpp:89
std::string toString() const
Definition: NameMatrix.cpp:60
const NameList_T & getNameList() const
Definition: Names.hpp:60
std::string describe() const
Definition: Names.cpp:51
std::string describe() const
Definition: NameMatrix.cpp:33