libDwmRDAP-0.1.4
DwmCountryCode.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $Name:$
3 // @(#) $Id: DwmCountryCode.hh 8911 2017-03-27 08:33:29Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2017
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMCOUNTRYCODE_HH_
43 #define _DWMCOUNTRYCODE_HH_
44 
45 #include <string>
46 #include <tuple>
47 
48 #include <json/json.h>
49 
50 #include "DwmReadable.hh"
51 #include "DwmWritable.hh"
52 
53 namespace Dwm {
54 
55  //--------------------------------------------------------------------------
58  //--------------------------------------------------------------------------
60  : public Dwm::Readable, public Dwm::Writable
61  {
62  public:
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  CountryCode() = default;
67 
68  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  CountryCode(const Json::Value & jv);
72 
73  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  Json::Value Json() const;
77 
78  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
81  const std::string & Alpha2() const;
82 
83  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  const std::string & Alpha2(const std::string & alpha2);
88 
89  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  const std::string & Alpha3() const;
93 
94  //------------------------------------------------------------------------
97  //------------------------------------------------------------------------
98  const std::string & Alpha3(const std::string & alpha3);
99 
100  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  const std::string & Name() const;
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  const std::string & Name(const std::string & name);
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  std::istream & Read(std::istream & is);
114 
115  //------------------------------------------------------------------------
118  //------------------------------------------------------------------------
119  ssize_t Read(int fd);
120 
121  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  size_t Read(FILE *f);
126 
127  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  std::ostream & Write(std::ostream & os) const;
131 
132  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  ssize_t Write(int fd) const;
137 
138  //------------------------------------------------------------------------
141  //------------------------------------------------------------------------
142  size_t Write(FILE *f) const;
143 
144  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  uint32_t StreamedLength() const;
149 
150  //------------------------------------------------------------------------
152  //------------------------------------------------------------------------
153  bool operator == (const CountryCode & cc) const
154  {
155  return (_data == cc._data);
156  }
157 
158  private:
159  std::tuple<std::string,std::string,std::string> _data;
160  };
161 
162 } // namespace Dwm
163 
164 #endif // _DWMCOUNTRYCODE_HH_
uint32_t StreamedLength() const
Returns the number of bytes that should be written if one of the Write() members is called...
Encapsulates country code information.
Definition: DwmCountryCode.hh:59
CountryCode()=default
Default constructor.
const std::string & Name() const
Returns the full country name.
bool operator==(const CountryCode &cc) const
operator ==
Definition: DwmCountryCode.hh:153
const std::string & Alpha3() const
Returns the 3-letter country code.
Definition: DwmCountryCode.hh:53
std::istream & Read(std::istream &is)
Reads the country code from an istream. Returns the istream.
const std::string & Alpha2() const
Returns the 2-letter country code.
std::ostream & Write(std::ostream &os) const
Writes the country code to an ostream. Returns the ostream.
Json::Value Json() const
Return the country code as a Json::Value.