OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
Names.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/Names.hpp>
9
10namespace OPENTREP {
11
12 // //////////////////////////////////////////////////////////////////////
13 Names::Names() : _languageCode ("en_US") {
14 assert (false);
15 }
16
17 // //////////////////////////////////////////////////////////////////////
18 Names::Names (const LanguageCode_T& iLanguageCode)
19 : _languageCode (iLanguageCode) {
20 }
21
22 // //////////////////////////////////////////////////////////////////////
23 Names::Names (const Names& iName)
24 : _languageCode (iName._languageCode),
25 _nameList (iName._nameList) {
26 }
27
28 // //////////////////////////////////////////////////////////////////////
30 }
31
32 // //////////////////////////////////////////////////////////////////////
33 std::string Names::getFirstName() const {
34 if (_nameList.empty() == true) {
35 return "";
36 }
37 NameList_T::const_iterator itName = _nameList.begin();
38 assert (itName != _nameList.end());
39 const std::string& lName = *itName;
40 return lName;
41 }
42
43 // //////////////////////////////////////////////////////////////////////
44 std::string Names::describeKey() const {
45 std::ostringstream oStr;
46 //oStr << "[" << Language::getLongLabel (_languageCode) << "]: ";
47 return oStr.str();
48 }
49
50 // //////////////////////////////////////////////////////////////////////
51 std::string Names::describe() const {
52 std::ostringstream oStr;
53 oStr << describeKey();
54
55 // The language code is the same for all the items of the list. But it
56 // is repeated for every item, so that it can be parsed easily.
57 // const std::string& lLangCode = Language::getShortLabel (_languageCode);
58
59 unsigned short idx = 0;
60 for (NameList_T::const_iterator itName = _nameList.begin();
61 itName != _nameList.end(); ++itName, ++idx) {
62 if (idx != 0) {
63 oStr << ",";
64 }
65 const std::string& lName = *itName;
66 oStr << _languageCode << "," << lName;
67 }
68
69 return oStr.str();
70 }
71
72 // //////////////////////////////////////////////////////////////////////
73 void Names::toStream (std::ostream& ioOut) const {
74 ioOut << describe();
75 }
76
77 // //////////////////////////////////////////////////////////////////////
78 void Names::fromStream (std::istream& ioIn) {
79 }
80
81 // //////////////////////////////////////////////////////////////////////
82 std::string Names::toString() const {
83 std::ostringstream oStr;
84 oStr << describe();
85 return oStr.str();
86 }
87
88 // //////////////////////////////////////////////////////////////////////
89 void Names::addName (const std::string& iName) {
90 _nameList.push_back (iName);
91 }
92
93 // //////////////////////////////////////////////////////////////////////
95 _nameList.clear();
96 }
97
98}
std::string describeKey() const
Definition Names.cpp:44
std::string toString() const
Definition Names.cpp:82
void toStream(std::ostream &ioOut) const
Definition Names.cpp:73
void addName(const std::string &iName)
Definition Names.cpp:89
void resetList()
Definition Names.cpp:94
Names(const LanguageCode_T &)
Definition Names.cpp:18
void fromStream(std::istream &ioIn)
Definition Names.cpp:78
std::string describe() const
Definition Names.cpp:51
std::string getFirstName() const
Definition Names.cpp:33