casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
32 #include <map>
33 #include <iosfwd>
34 
35 namespace casacore {
36 
37  //# Forward Declarations
38  class ValueHolder;
39 
40  // <summary>
41  // Class to hold a collection of JSON key:value pairs.
42  // </summary>
43 
44  // <use visibility=export>
45  // <reviewed reviewer="" date="" tests="tJsonKVMap">
46  // </reviewed>
47 
48  //# <prerequisite>
49  //# </prerequisite>
50 
51  // <synopsis>
52  // A JsonKVMap object is the result of a JSON file parsed by JsonParser.
53  // It is a map of name to a JsonValue object holding an arbitrary value
54  // (including a JsonKVMap for nested structs).
55  //
56  // JsonKVMap has functions to test if a given field is present and to
57  // get its JsonValue. It also has functions to get a scalar value
58  // where a default value is used if the key is undefined.
59  //
60  // JsonKVMap is derived from std::map, so all its functions are available.
61  // Iterators make standard iteration possible.
62  // </synopsis>
63 
64  // <motivation>
65  // JSON is a commonly used interchange format.
66  // </motivation>
67 
68  //# <todo asof="1996/03/10">
69  //# <li>
70  //# </todo>
71 
72  class JsonKVMap: public std::map<String, JsonValue>
73  {
74  public:
75  // Define the iterator types.
77  typedef std::map<String,JsonValue>::iterator iterator;
78 
79  // Construct an empty map.
80  JsonKVMap();
81 
82  // Copy constructor (copy semantics)
83  JsonKVMap (const JsonKVMap& that);
84 
85  ~JsonKVMap();
86 
87  // Assignment (copy semantics)
88  JsonKVMap& operator= (const JsonKVMap& that);
89 
90  // Is a key defined?
91  Bool isDefined (const String& name) const
92  { return find(name) != end(); }
93 
94  // Get the value of a key. An exception is thrown if undefined.
95  const JsonValue& get (const String& name) const;
96 
97  // \name Get the typed value of a key
98  // Use the default if not existing.
99  // <group>
100  Bool getBool (const String& name, Bool defVal) const;
101  Int64 getInt (const String& name, Int64 defVal) const;
102  double getDouble (const String& name, double defVal) const;
103  DComplex getDComplex (const String& name, const DComplex& defVal) const;
104  const String& getString (const String& name, const String& defVal) const;
105  // </group>
106 
107  // Convert the map to a Record.
108  Record toRecord() const;
109 
110  // \name Show the contents of the object
111  // <group>
112  void show (ostream&) const;
113  friend ostream& operator<< (ostream&, const JsonKVMap&);
114  // </group>
115  };
116 
117 } //end namespace
118 
119 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
Elements::const_iterator const_iterator
JsonKVMap & operator=(const JsonKVMap &that)
Assignment (copy semantics)
Bool getBool(const String &name, Bool defVal) const
double getDouble(const String &name, double defVal) const
Int64 getInt(const String &name, Int64 defVal) const
DComplex getDComplex(const String &name, const DComplex &defVal) const
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
const_iterator end() const
Record toRecord() const
Convert the map to a Record.
Bool isDefined(const String &name) const
Is a key defined?
Definition: JsonKVMap.h:91
std::map< String, JsonValue >::const_iterator const_iterator
Define the iterator types.
Definition: JsonKVMap.h:76
Class to hold a collection of JSON key:value pairs.
Definition: JsonKVMap.h:72
std::map< String, JsonValue >::iterator iterator
Definition: JsonKVMap.h:77
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Class to hold any JSON value.
Definition: JsonValue.h:91
const String & getString(const String &name, const String &defVal) const
friend ostream & operator<<(ostream &, const JsonKVMap &)
void show(ostream &) const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
JsonKVMap()
Construct an empty map.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42