libDwmRDAP-0.1.4
DwmCountryCodes.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $Name:$
3 // @(#) $Id: DwmCountryCodes.hh 8910 2017-03-27 08:14:35Z 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 _DWMCOUNTRYCODES_HH_
43 #define _DWMCOUNTRYCODES_HH_
44 
45 #include <fstream>
46 #include <map>
47 #include <vector>
48 
49 #include "DwmReadable.hh"
50 #include "DwmWritable.hh"
51 
52 #include "DwmCountryCode.hh"
53 
54 namespace Dwm {
55 
56  //--------------------------------------------------------------------------
58  //--------------------------------------------------------------------------
60  : public Dwm::Readable, public Dwm::Writable
61  {
62  public:
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  CountryCodes() = default;
67 
68  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  CountryCode FindByCode(const std::string & code) const;
73 
74  std::vector<CountryCode> FindByNameRegExp(const std::string & rgxp) const;
75 
76  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  bool ReadJson(const std::string & fileName);
81 
82  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  bool WriteJson(const std::string & fileName) const;
87 
88  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  std::istream & Read(std::istream & is);
92 
93  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  ssize_t Read(int fd);
98 
99  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  size_t Read(FILE *f);
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  std::ostream & Write(std::ostream & os) const;
109 
110  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  ssize_t Write(int fd) const;
115 
116  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  size_t Write(FILE *f) const;
121 
122  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  uint32_t StreamedLength() const;
127 
128  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  bool operator == (const CountryCodes & countryCodes) const
132  {
133  return (_a2toCountryCode == countryCodes._a2toCountryCode);
134  }
135 
136  private:
137  std::map<std::string,CountryCode> _a2toCountryCode;
138  std::map<std::string,CountryCode> _a3toCountryCode;
139  };
140 
141 } // namespace Dwm
142 
143 #endif // _DWMCOUNTRYCODES_HH_
Encapsulates country code information.
Definition: DwmCountryCode.hh:59
Definition: DwmCountryCode.hh:53
uint32_t StreamedLength() const
Returns the number of bytes that should be written if one of the Write() members is called...
CountryCode FindByCode(const std::string &code) const
Finds a country code by 2 or 3 letter code.
bool ReadJson(const std::string &fileName)
Reads the country codes from a JSON file.
Dwm::CountryCode class definition.
Encapsulates a set of country codes.
Definition: DwmCountryCodes.hh:59
bool WriteJson(const std::string &fileName) const
Writes the country code to a file in JSON format.
bool operator==(const CountryCodes &countryCodes) const
operator ==
Definition: DwmCountryCodes.hh:131
CountryCodes()=default
Default constructor.
std::istream & Read(std::istream &is)
Reads the country codes from an istream. Returns the istream.
std::ostream & Write(std::ostream &os) const
Writes the country codes to an ostream. Returns the ostream.