NGen
Loading...
Searching...
No Matches
geojson::JSONProperty Class Reference

@TODO: Convert JSONProperty into a variant of the supported types
More...

#include <JSONProperty.hpp>

+ Collaboration diagram for geojson::JSONProperty:

Classes

struct  AsVectorVisitor
 Visitor to filter boost variants by type T into a vector of type T. More...
 

Public Member Functions

 JSONProperty (std::string value_key, const boost::property_tree::ptree &property_tree)
 
 JSONProperty (std::string value_key, short value)
 Create a JSONProperty that stores a natural number.
 
 JSONProperty (std::string value_key, int value)
 Create a JSONProperty that stores a natural number.
 
 JSONProperty (std::string value_key, long value)
 Create a JSONProperty that stores a natural number.
 
 JSONProperty (std::string value_key, float value)
 Create a JSONProperty that stores a floating point number.
 
 JSONProperty (std::string value_key, double value)
 Create a JSONProperty that stores a floating point number.
 
 JSONProperty (std::string value_key, const char *value)
 Create a JSONProperty that stores text.
 
 JSONProperty (std::string value_key, std::string value)
 Create a JSONProperty that stores text.
 
 JSONProperty (std::string value_key, std::vector< JSONProperty > properties)
 
 JSONProperty (const JSONProperty &original)
 
 JSONProperty (const std::string &value_key, const JSONProperty &original)
 Copy construct a JSONProperty, but use a new key value for the property.
 
virtual ~JSONProperty ()
 A basic destructor.
 
 JSONProperty (std::string value_key, bool value)
 Create a JSONProperty that stores a true or false value.
 
 JSONProperty (std::string value_key, PropertyMap &value)
 Create a JSONProperty that stores a nested map of properties.
 
PropertyType get_type () const
 Get the type of the property (Natural, Real, String, etc)
 
long as_natural_number () const
 Attempt to get the natural numeric value stored within the property.
 
double as_real_number () const
 
bool as_boolean () const
 
template<typename T >
void as_vector (std::vector< T > &vector) const
 Populates a std::vector<T> with PropertyVariant values.
 
std::vector< JSONPropertyas_list () const
 
std::vector< long > as_natural_vector () const
 
std::vector< double > as_real_vector () const
 
std::vector< std::string > as_string_vector () const
 
std::vector< bool > as_boolean_vector () const
 
std::string as_string () const
 
JSONProperty at (std::string key) const
 
std::vector< std::string > keys () const
 
std::map< std::string, JSONPropertyget_values () const
 
std::string get_key () const
 
bool has_key (std::string key) const
 
bool operator== (const JSONProperty &other) const
 
bool operator!= (const JSONProperty &other)
 

Static Public Member Functions

static void print_property (const geojson::JSONProperty &p, int tab=0, bool newline=true)
 Pretty print the property to standard out stream.
 

Private Attributes

std::string key
 
PropertyType type
 
PropertyMap values
 
std::vector< JSONPropertyvalue_list
 
PropertyVariant data
 

Detailed Description

@TODO: Convert JSONProperty into a variant of the supported types

Object used to store basic geojson property data

Constructor & Destructor Documentation

◆ JSONProperty() [1/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
const boost::property_tree::ptree & property_tree )
inline

Referenced by as_list().

◆ JSONProperty() [2/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
short value )
inline

Create a JSONProperty that stores a natural number.

Parameters
value_keyThe name of the key that stores this value
valueThe natural number that will be stored

References geojson::Natural.

◆ JSONProperty() [3/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
int value )
inline

Create a JSONProperty that stores a natural number.

Parameters
value_keyThe name of the key that stores this value
valueThe natural number that will be stored

References geojson::Natural.

◆ JSONProperty() [4/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
long value )
inline

Create a JSONProperty that stores a natural number.

Parameters
value_keyThe name of the key that stores this value
valueThe natural number that will be stored

References geojson::Natural.

◆ JSONProperty() [5/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
float value )
inline

Create a JSONProperty that stores a floating point number.

Parameters
value_keyThe name of the key that stores this value
valueThe floating point number that will be stored

References geojson::Real.

◆ JSONProperty() [6/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
double value )
inline

Create a JSONProperty that stores a floating point number.

Parameters
value_keyThe name of the key that stores this value
valueThe floating point number that will be stored

References geojson::Real.

◆ JSONProperty() [7/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
const char * value )
inline

Create a JSONProperty that stores text.

Parameters
value_keyThe name of the key that stores this value
valueThe text that will be stored

References geojson::String.

◆ JSONProperty() [8/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
std::string value )
inline

Create a JSONProperty that stores text.

Parameters
value_keyThe name of the key that stores this value
valueThe text that will be stored

◆ JSONProperty() [9/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
std::vector< JSONProperty > properties )
inline

◆ JSONProperty() [10/13]

geojson::JSONProperty::JSONProperty ( const JSONProperty & original)
inline

References data, key, type, value_list, and values.

◆ JSONProperty() [11/13]

geojson::JSONProperty::JSONProperty ( const std::string & value_key,
const JSONProperty & original )
inline

Copy construct a JSONProperty, but use a new key value for the property.

Parameters
value_key
original

◆ ~JSONProperty()

virtual geojson::JSONProperty::~JSONProperty ( )
inlinevirtual

A basic destructor.

◆ JSONProperty() [12/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
bool value )
inline

Create a JSONProperty that stores a true or false value.

Parameters
value_keyThe name of the key that stores this value
valueThe true or false value that will be stored

References geojson::Boolean.

◆ JSONProperty() [13/13]

geojson::JSONProperty::JSONProperty ( std::string value_key,
PropertyMap & value )
inline

Create a JSONProperty that stores a nested map of properties.

Parameters
value_keyThe name of the key that stores this value
valueA map of nested properties that will be stored

Member Function Documentation

◆ as_boolean()

bool JSONProperty::as_boolean ( ) const

◆ as_boolean_vector()

std::vector< bool > JSONProperty::as_boolean_vector ( ) const

References as_vector(), and values.

◆ as_list()

◆ as_natural_number()

long JSONProperty::as_natural_number ( ) const

Attempt to get the natural numeric value stored within the property.

An exception will be thrown if this property doesn't store a natural number

Returns
The natural number that is stored within the property

References data, geojson::get_propertytype_name(), get_type(), key, geojson::Natural, and type.

Referenced by print_property().

◆ as_natural_vector()

std::vector< long > JSONProperty::as_natural_vector ( ) const

References as_vector(), and values.

◆ as_real_number()

◆ as_real_vector()

std::vector< double > JSONProperty::as_real_vector ( ) const

References as_vector(), and values.

◆ as_string()

◆ as_string_vector()

std::vector< std::string > JSONProperty::as_string_vector ( ) const

References as_vector(), and values.

◆ as_vector()

template<typename T >
void geojson::JSONProperty::as_vector ( std::vector< T > & vector) const
inline

Populates a std::vector<T> with PropertyVariant values.

Scalar properties will yeild a vector of size 1.

List properties will yield a vector of compatible types. E.g. a List with [1, 2.1, 3] can upcast the Natural number 1 and 3 iff a container is provided with sufficient datatype (double)

std::vector<double> double_vec; as_vector(double_vec);

Will give a vector of doubles = {1.0, 2.1, 3.0}.

However, if a vector of long is used, only the Natural numbers will be extracted

std::vector<long> long_vec; as_vector(long_vec);

Will give a vector of longs = {1, 3}.

Other than this caveat, as_vector effetively filters the property list for types representable by T.

Template Parameters
T
Parameters
vector

Referenced by as_boolean_vector(), as_natural_vector(), as_real_vector(), and as_string_vector().

◆ at()

◆ get_key()

std::string JSONProperty::get_key ( ) const

References key.

◆ get_type()

PropertyType JSONProperty::get_type ( ) const

Get the type of the property (Natural, Real, String, etc)

Returns
The type of the property

References type.

Referenced by as_boolean(), as_list(), as_natural_number(), as_real_number(), as_string(), at(), get_values(), keys(), Partitions_Parser::parse_partition_file(), and print_property().

◆ get_values()

PropertyMap JSONProperty::get_values ( ) const

◆ has_key()

bool JSONProperty::has_key ( std::string key) const

References key, and keys().

◆ keys()

std::vector< std::string > JSONProperty::keys ( ) const

◆ operator!=()

bool geojson::JSONProperty::operator!= ( const JSONProperty & other)
inline

◆ operator==()

bool geojson::JSONProperty::operator== ( const JSONProperty & other) const
inline

References at(), data, keys(), type, and values.

◆ print_property()

static void geojson::JSONProperty::print_property ( const geojson::JSONProperty & p,
int tab = 0,
bool newline = true )
inlinestatic

Pretty print the property to standard out stream.

Recurses through the property to tab/print nested objects/lists.

Parameters
pProperty to print
tab(optional) Additional starting tab to indent (default 0)
newline(optional) Add a new line to the end of the print (default true)

References as_boolean(), as_list(), as_natural_number(), as_real_number(), as_string(), geojson::Boolean, get_type(), get_values(), geojson::List, geojson::Natural, geojson::Object, geojson::Real, and geojson::String.

Referenced by realization::config::Formulation::Formulation().

Member Data Documentation

◆ data

PropertyVariant geojson::JSONProperty::data
private

◆ key

std::string geojson::JSONProperty::key
private

◆ type

◆ value_list

std::vector<JSONProperty> geojson::JSONProperty::value_list
private

Referenced by JSONProperty(), as_list(), and as_string().

◆ values


The documentation for this class was generated from the following files: