Stan  2.10.0
probability, sampling & optimization
Public Member Functions | List of all members
stan::json::json_data Class Reference

A json_data is a var_context object that represents a set of named values which are typed to either double or int and can be either scalar value or a non-empty array of values of any dimensionality. More...

#include <json_data.hpp>

Inheritance diagram for stan::json::json_data:
stan::io::var_context

Public Member Functions

 json_data (std::istream &in)
 Construct a json_data object from the specified input stream. More...
 
bool contains_r (const std::string &name) const
 Return true if this json_data contains the specified variable name. More...
 
bool contains_i (const std::string &name) const
 Return true if this json_data contains an integer valued array with the specified name. More...
 
std::vector< double > vals_r (const std::string &name) const
 Return the double values for the variable with the specified name or null. More...
 
std::vector< size_t > dims_r (const std::string &name) const
 Return the dimensions for the variable with the specified name. More...
 
std::vector< int > vals_i (const std::string &name) const
 Return the integer values for the variable with the specified name. More...
 
std::vector< size_t > dims_i (const std::string &name) const
 Return the dimensions for the integer variable with the specified name. More...
 
virtual void names_r (std::vector< std::string > &names) const
 Return a list of the names of the floating point variables in the json_data. More...
 
virtual void names_i (std::vector< std::string > &names) const
 Return a list of the names of the integer variables in the json_data. More...
 
bool remove (const std::string &name)
 Remove variable from the object. More...
 
- Public Member Functions inherited from stan::io::var_context
virtual ~var_context ()
 
void add_vec (std::stringstream &msg, const std::vector< size_t > &dims) const
 
void validate_dims (const std::string &stage, const std::string &name, const std::string &base_type, const std::vector< size_t > &dims_declared) const
 

Additional Inherited Members

- Static Public Member Functions inherited from stan::io::var_context
static std::vector< size_t > to_vec ()
 
static std::vector< size_t > to_vec (size_t n1)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7, size_t n8)
 

Detailed Description

A json_data is a var_context object that represents a set of named values which are typed to either double or int and can be either scalar value or a non-empty array of values of any dimensionality.

Arrays must be retangular and the values of an array are all of the same type, either double or int.

The dimensions and values of variables are accessed by variable name. The values of a variable are stored as a vector of values and a vector of array dimensions, where a scalar value consists of a single value and an emtpy vector for the dimensionality. Multidimensional arrays are stored in column-major order, meaning the first index changes the most quickly. If all the values of an array are int values, the array will be stored as a vector of ints, else the array will be stored as a vector of type double.

json_data objects are created by using the json_parser and a json_data_handler to read a single JSON text from an input stream.

Definition at line 44 of file json_data.hpp.

Constructor & Destructor Documentation

stan::json::json_data::json_data ( std::istream &  in)
inlineexplicit

Construct a json_data object from the specified input stream.

Warning: This method does not close the input stream.

Parameters
inInput stream from which to read.
Exceptions
json_exceptionif data is not well-formed stan data declaration

Definition at line 75 of file json_data.hpp.

Member Function Documentation

bool stan::json::json_data::contains_i ( const std::string &  name) const
inlinevirtual

Return true if this json_data contains an integer valued array with the specified name.

Parameters
nameVariable name to test.
Returns
true if the variable name has an integer array value.

Implements stan::io::var_context.

Definition at line 100 of file json_data.hpp.

bool stan::json::json_data::contains_r ( const std::string &  name) const
inlinevirtual

Return true if this json_data contains the specified variable name.

This method returns true even if the values are all integers.

Parameters
nameVariable name to test.
Returns
true if the variable exists.

Implements stan::io::var_context.

Definition at line 88 of file json_data.hpp.

std::vector<size_t> stan::json::json_data::dims_i ( const std::string &  name) const
inlinevirtual

Return the dimensions for the integer variable with the specified name.

Parameters
nameName of variable.
Returns
Dimensions of variable.

Implements stan::io::var_context.

Definition at line 162 of file json_data.hpp.

std::vector<size_t> stan::json::json_data::dims_r ( const std::string &  name) const
inlinevirtual

Return the dimensions for the variable with the specified name.

Parameters
nameName of variable.
Returns
Dimensions of variable.

Implements stan::io::var_context.

Definition at line 132 of file json_data.hpp.

virtual void stan::json::json_data::names_i ( std::vector< std::string > &  names) const
inlinevirtual

Return a list of the names of the integer variables in the json_data.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 188 of file json_data.hpp.

virtual void stan::json::json_data::names_r ( std::vector< std::string > &  names) const
inlinevirtual

Return a list of the names of the floating point variables in the json_data.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 175 of file json_data.hpp.

bool stan::json::json_data::remove ( const std::string &  name)
inline

Remove variable from the object.

Parameters
nameName of the variable to remove.
Returns
If variable is removed returns true, else returns false.

Definition at line 202 of file json_data.hpp.

std::vector<int> stan::json::json_data::vals_i ( const std::string &  name) const
inlinevirtual

Return the integer values for the variable with the specified name.

Parameters
nameName of variable.
Returns
Values.

Implements stan::io::var_context.

Definition at line 148 of file json_data.hpp.

std::vector<double> stan::json::json_data::vals_r ( const std::string &  name) const
inlinevirtual

Return the double values for the variable with the specified name or null.

Parameters
nameName of variable.
Returns
Values of variable.

Implements stan::io::var_context.

Definition at line 111 of file json_data.hpp.


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

     [ Stan Home Page ] © 2011–2016, Stan Development Team.