casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef CASA_JSONKVMAP_H
27#define CASA_JSONKVMAP_H
28
29#include <casacore/casa/Json/JsonValue.h>
30#include <map>
31#include <iosfwd>
32
33namespace casacore {
34
35 //# Forward Declarations
36 class ValueHolder;
37
38 // <summary>
39 // Class to hold a collection of JSON key:value pairs.
40 // </summary>
41
42 // <use visibility=export>
43 // <reviewed reviewer="" date="" tests="tJsonKVMap">
44 // </reviewed>
45
46 //# <prerequisite>
47 //# </prerequisite>
48
49 // <synopsis>
50 // A JsonKVMap object is the result of a JSON file parsed by JsonParser.
51 // It is a map of name to a JsonValue object holding an arbitrary value
52 // (including a JsonKVMap for nested structs).
53 //
54 // JsonKVMap has functions to test if a given field is present and to
55 // get its JsonValue. It also has functions to get a scalar value
56 // where a default value is used if the key is undefined.
57 //
58 // JsonKVMap is derived from std::map, so all its functions are available.
59 // Iterators make standard iteration possible.
60 // </synopsis>
61
62 // <motivation>
63 // JSON is a commonly used interchange format.
64 // </motivation>
65
66 //# <todo asof="1996/03/10">
67 //# <li>
68 //# </todo>
69
70 class JsonKVMap: public std::map<String, JsonValue>
71 {
72 public:
73 // Define the iterator types.
74 typedef std::map<String,JsonValue>::const_iterator const_iterator;
75 typedef std::map<String,JsonValue>::iterator iterator;
76
77 // Construct an empty map.
79
80 // Copy constructor (copy semantics)
81 JsonKVMap (const JsonKVMap& that);
82
84
85 // Assignment (copy semantics)
87
88 // Is a key defined?
89 Bool isDefined (const String& name) const
90 { return find(name) != end(); }
91
92 // Get the value of a key. An exception is thrown if undefined.
93 const JsonValue& get (const String& name) const;
94
95 // \name Get the typed value of a key
96 // Use the default if not existing.
97 // <group>
98 Bool getBool (const String& name, Bool defVal) const;
99 Int64 getInt (const String& name, Int64 defVal) const;
100 double getDouble (const String& name, double defVal) const;
101 DComplex getDComplex (const String& name, const DComplex& defVal) const;
102 const String& getString (const String& name, const String& defVal) const;
103 // </group>
104
105 // Convert the map to a Record.
107
108 // \name Show the contents of the object
109 // <group>
110 void show (ostream&) const;
111 friend ostream& operator<< (ostream&, const JsonKVMap&);
112 // </group>
113 };
114
115} //end namespace
116
117#endif
JsonKVMap(const JsonKVMap &that)
Copy constructor (copy semantics)
JsonKVMap()
Construct an empty map.
void show(ostream &) const
Bool getBool(const String &name, Bool defVal) const
friend ostream & operator<<(ostream &, const JsonKVMap &)
std::map< String, JsonValue >::iterator iterator
Definition JsonKVMap.h:75
DComplex getDComplex(const String &name, const DComplex &defVal) const
std::map< String, JsonValue >::const_iterator const_iterator
Define the iterator types.
Definition JsonKVMap.h:74
const JsonValue & get(const String &name) const
Get the value of a key.
double getDouble(const String &name, double defVal) const
Bool isDefined(const String &name) const
Is a key defined?
Definition JsonKVMap.h:89
JsonKVMap & operator=(const JsonKVMap &that)
Assignment (copy semantics)
const String & getString(const String &name, const String &defVal) const
Record toRecord() const
Convert the map to a Record.
Int64 getInt(const String &name, Int64 defVal) const
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
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40