DUDS
Distributed Update of Data from Something
LanguageTaggedString.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef LANGUAGETAGGEDSTRING_HPP
11 #define LANGUAGETAGGEDSTRING_HPP
12 
13 #include <string>
14 #include <map>
15 #include <boost/serialization/nvp.hpp>
16 
17 namespace duds { namespace general {
18 
32  std::string tag;
36  std::string string;
41  bool operator < (const LanguageTaggedString &lts) const {
42  int res = tag.compare(lts.tag);
43  if (!res) {
44  return string.compare(lts.string) < 0;
45  }
46  return res < 0;
47  }
48 private:
50  // needs boost/date_time/posix_time/time_serialize.hpp
51  template <class A>
52  void serialize(A &a, const unsigned int) {
53  a & BOOST_SERIALIZATION_NVP(tag);
54  a & BOOST_SERIALIZATION_NVP(string);
55  }
56 };
57 
58 /*
59  * A container that holds LanguageTaggedString objects, and limits a language
60  * tag to a single string. The names of items of this type should not be
61  * plural or otherwise suggest multiple strings because there is only one
62  * string per language and normally only one language will be used at time.
63  * @todo Change this type to something that allows a best match search for a
64  * requested language tag.
65  */
66 //typedef std::set<LanguageTaggedString> LanguageTaggedStringSet;
67 
68 // or maybe a Boost multi-index to get the key from LanguageTaggedString
69 typedef std::map<std::string, std::string> LanguageTaggedStringMap;
70 
71 /*
72  * A container that holds LanguageTaggedString objects, and can hold several
73  * such objects for the same language tag. For a given language tag, each
74  * associated sting must be unique.
75  * @todo Explain why or remove.
76  */
77 //typedef std::multiset<LanguageTaggedString> LanguageTaggedStringMultiSet;
78 
79 } }
80 
81 #endif // #ifndef LANGUAGETAGGEDSTRING_HPP
82 
std::string string
A string encoded in UTF-8.
Holds a string and its associated language.
bool operator<(const LanguageTaggedString &lts) const
Compares two for sorting.
std::string tag
The IETF language tag, RFC 5646, maybe.
friend class boost::serialization::access
std::map< std::string, std::string > LanguageTaggedStringMap
void serialize(A &a, const unsigned int)