casacore
JsonKVMap.h
Go to the documentation of this file.
1 //# JsonKVMap.h: Class to hold a collection of JSON key:value pairs
2 //# Copyright (C) 2016
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: JsonKVMap.h 14057 2009-09-18 12:26:29Z diepen $
27 
28 #ifndef CASA_JSONKVMAP_H
29 #define CASA_JSONKVMAP_H
30 
31 #include <casacore/casa/Json/JsonValue.h>
32 #include <map>
33 #include <iosfwd>
34 
35 namespace casacore {
36 
37  // <summary>
38  // Class to hold a collection of JSON key:value pairs.
39  // </summary>
40 
41  // <use visibility=export>
42  // <reviewed reviewer="" date="" tests="tJsonKVMap">
43  // </reviewed>
44 
45  //# <prerequisite>
46  //# </prerequisite>
47 
48  // <synopsis>
49  // A JsonKVMap object is the result of a JSON file parsed by JsonParser.
50  // It is a map of name to a JsonValue object holding an arbitrary value
51  // (including a JsonKVMap for nested structs).
52  //
53  // JsonKVMap has functions to test if a given field is present and to
54  // get its JsonValue. It also has functions to get a scalar value
55  // where a default value is used if the key is undefined.
56  //
57  // JsonKVMap is derived from std::map, so all its functions are available.
58  // Iterators to make standard iteration possible.
59  // </synopsis>
60 
61  // <motivation>
62  // JSON is a commonly used interchange format.
63  // </motivation>
64 
65  //# <todo asof="1996/03/10">
66  //# <li>
67  //# </todo>
68 
69  class JsonKVMap: public std::map<String, JsonValue>
70  {
71  public:
72  typedef std::map<String,JsonValue>::const_iterator const_iterator;
73  typedef std::map<String,JsonValue>::iterator iterator;
74 
75  JsonKVMap();
76 
77  // Copy constructor (copy semantics)
78  JsonKVMap (const JsonKVMap& that);
79 
80  ~JsonKVMap();
81 
82  // Assignment (copy semantics)
83  JsonKVMap& operator= (const JsonKVMap& that);
84 
85  // Is a key defined?
86  Bool isDefined (const String& name) const
87  { return find(name) != end(); }
88 
89  // Get the value of a key. An exception is thrown if undefined.
90  const JsonValue& get (const String& name) const;
91 
92  // \name Get the typed value of a key
93  // Use the default if not existing.
94  // <group>
95  Bool getBool (const String& name, Bool defVal) const;
96  Int64 getInt (const String& name, Int64 defVal) const;
97  double getDouble (const String& name, double defVal) const;
98  DComplex getDComplex (const String& name, const DComplex& defVal) const;
99  const String& getString (const String& name, const String& defVal) const;
100  // </group>
101 
102  // \name Show the contents of the object
103  // <group>
104  void show (ostream&) const;
105  friend ostream& operator<< (ostream&, const JsonKVMap&);
106  // </group>
107  };
108 
109 } //end namespace
110 
111 #endif
DComplex getDComplex(const String &name, const DComplex &defVal) const
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
JsonKVMap & operator=(const JsonKVMap &that)
Assignment (copy semantics)
Bool getBool(const String &name, Bool defVal) const
const String & getString(const String &name, const String &defVal) const
std::map< String, JsonValue >::const_iterator const_iterator
Definition: JsonKVMap.h:72
Class to hold a collection of JSON key:value pairs.
Definition: JsonKVMap.h:69
Int64 getInt(const String &name, Int64 defVal) const
std::map< String, JsonValue >::iterator iterator
Definition: JsonKVMap.h:73
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Class to hold any JSON value.
Definition: JsonValue.h:89
void show(ostream &) const
friend ostream & operator<<(ostream &, const JsonKVMap &)
double getDouble(const String &name, double defVal) const
Bool isDefined(const String &name) const
Is a key defined?
Definition: JsonKVMap.h:86
String: the storage and methods of handling collections of characters.
Definition: String.h:223
this file contains all the compiler specific defines
Definition: mainpage.dox:28