Loading...
Searching...
No Matches
JsonKVMap.h
Go to the documentation of this file.
//# JsonKVMap.h: Class to hold a collection of JSON key:value pairs
//# Copyright (C) 2016
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef CASA_JSONKVMAP_H
#define CASA_JSONKVMAP_H
#include <casacore/casa/Json/JsonValue.h>
#include <map>
#include <iosfwd>
namespace casacore {
//# Forward Declarations
class ValueHolder;
// <summary>
// Class to hold a collection of JSON key:value pairs.
// </summary>
// <use visibility=export>
// <reviewed reviewer="" date="" tests="tJsonKVMap">
// </reviewed>
//# <prerequisite>
//# </prerequisite>
// <synopsis>
// A JsonKVMap object is the result of a JSON file parsed by JsonParser.
// It is a map of name to a JsonValue object holding an arbitrary value
// (including a JsonKVMap for nested structs).
//
// JsonKVMap has functions to test if a given field is present and to
// get its JsonValue. It also has functions to get a scalar value
// where a default value is used if the key is undefined.
//
// JsonKVMap is derived from std::map, so all its functions are available.
// Iterators make standard iteration possible.
// </synopsis>
// <motivation>
// JSON is a commonly used interchange format.
// </motivation>
//# <todo asof="1996/03/10">
//# <li>
//# </todo>
class JsonKVMap: public std::map<String, JsonValue>
{
public:
// Define the iterator types.
typedef std::map<String,JsonValue>::const_iterator const_iterator;
typedef std::map<String,JsonValue>::iterator iterator;
// Construct an empty map.
JsonKVMap();
// Copy constructor (copy semantics)
JsonKVMap (const JsonKVMap& that);
~JsonKVMap();
// Assignment (copy semantics)
JsonKVMap& operator= (const JsonKVMap& that);
// Is a key defined?
Bool isDefined (const String& name) const
{ return find(name) != end(); }
// Get the value of a key. An exception is thrown if undefined.
const JsonValue& get (const String& name) const;
// \name Get the typed value of a key
// Use the default if not existing.
// <group>
Bool getBool (const String& name, Bool defVal) const;
Int64 getInt (const String& name, Int64 defVal) const;
double getDouble (const String& name, double defVal) const;
DComplex getDComplex (const String& name, const DComplex& defVal) const;
const String& getString (const String& name, const String& defVal) const;
// </group>
// Convert the map to a Record.
Record toRecord() const;
// \name Show the contents of the object
// <group>
void show (ostream&) const;
friend ostream& operator<< (ostream&, const JsonKVMap&);
// </group>
};
} //end namespace
#endif
casacore::JsonKVMap::JsonKVMap
JsonKVMap(const JsonKVMap &that)
Copy constructor (copy semantics).
casacore::JsonKVMap::JsonKVMap
JsonKVMap()
Construct an empty map.
casacore::JsonKVMap::show
void show(ostream &) const
casacore::JsonKVMap::getBool
Bool getBool(const String &name, Bool defVal) const
casacore::JsonKVMap::operator<<
friend ostream & operator<<(ostream &, const JsonKVMap &)
casacore::JsonKVMap::iterator
std::map< String, JsonValue >::iterator iterator
Definition JsonKVMap.h:75
casacore::JsonKVMap::getDComplex
DComplex getDComplex(const String &name, const DComplex &defVal) const
casacore::JsonKVMap::const_iterator
std::map< String, JsonValue >::const_iterator const_iterator
Define the iterator types.
Definition JsonKVMap.h:74
casacore::JsonKVMap::get
const JsonValue & get(const String &name) const
Get the value of a key.
casacore::JsonKVMap::getDouble
double getDouble(const String &name, double defVal) const
casacore::JsonKVMap::isDefined
Bool isDefined(const String &name) const
Is a key defined?
Definition JsonKVMap.h:89
casacore::JsonKVMap::operator=
JsonKVMap & operator=(const JsonKVMap &that)
Assignment (copy semantics).
casacore::JsonKVMap::~JsonKVMap
~JsonKVMap()
casacore::JsonKVMap::getString
const String & getString(const String &name, const String &defVal) const
casacore::JsonKVMap::toRecord
Record toRecord() const
Convert the map to a Record.
casacore::JsonKVMap::getInt
Int64 getInt(const String &name, Int64 defVal) const
casacore::JsonValue
Definition JsonValue.h:90
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::ValueHolder
Definition ValueHolder.h:66
casacore::Record
Record()
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
casacore::name
String name() const
Return the name of the field.
Definition RecordField.h:163
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40