RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Classes | Typedefs | Enumerations | Functions
Json.hpp File Reference
#include <map>
#include <ostream>
#include <set>
#include <sstream>
#include <utility>
#include <vector>
#include <Optional.hpp>
#include <Error.hpp>
#include <logging/Logger.hpp>
#include <PImpl.hpp>

Go to the source code of this file.

Classes

class  rstudio::launcher_plugins::json::Value
 Class which represents a json value. More...
 
class  rstudio::launcher_plugins::json::Object
 Class which represents a specific type of JSON Value: a JSON object. More...
 
class  rstudio::launcher_plugins::json::Object::Member
 Class which represents a single member of a JSON object. More...
 
class  rstudio::launcher_plugins::json::Object::Iterator
 Class which allows iterating over the members of a JSON object. More...
 
class  rstudio::launcher_plugins::json::Array
 Class which represents a JSON array. More...
 
class  rstudio::launcher_plugins::json::Array::Iterator
 Class which allows iterating over the elements of a JSON array. More...
 
struct  rstudio::launcher_plugins::json::detail::is_json_type< T >
 Struct which is either a child class of std::true_type or std::false_type depending on whether T is a JSON type (e.g. Value, Object, Array) or not (e.g. int, bool, string, float, etc.). More...
 

Typedefs

typedef std::vector< std::pair< std::string, std::string > > rstudio::launcher_plugins::json::StringPairList
 
typedef std::map< std::string, std::vector< std::string > > rstudio::launcher_plugins::json::StringListMap
 

Enumerations

enum  rstudio::launcher_plugins::json::Type {
  ARRAY, BOOL, INTEGER, OBJECT,
  STRING, REAL, NULL_TYPE, UNKNOWN
}
 Enum which represents the type of a json value. More...
 
enum  rstudio::launcher_plugins::json::JsonReadError { SUCCESS = 0, MISSING_MEMBER = 1, INVALID_TYPE = 2 }
 Errors which may occur while reading values from JSON objects.
 

Functions

template<typename T >
bool rstudio::launcher_plugins::json::isType (const Value &in_value)
 Checks whether the specified JSON value is of the type specified in the template parameter. More...
 
std::string rstudio::launcher_plugins::json::typeAsString (Type in_type)
 
std::ostream & rstudio::launcher_plugins::json::operator<< (std::ostream &io_ostream, Type in_type)
 
template<typename T >
Type rstudio::launcher_plugins::json::detail::asJsonType (const T &in_object, std::true_type)
 Internal utility function. Gets the type of the object as a JSON type, if the object is a JSON type (e.g. Value, Object, Array). More...
 
template<typename T >
Type rstudio::launcher_plugins::json::detail::asJsonType (const T &in_object, std::false_type)
 Internal utility function. Gets the type of the object as a JSON type, if the object is not a JSON type (e.g. int, bool, string, float, etc.). More...
 
template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue (const T &in_value)
 Internal utility function. Converts a C/C++ value to a JSON value. More...
 
template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue (const Optional< T > &in_value)
 Internal utility function. Converts a C/C++ optional value to a JSON value. More...
 
template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue (const std::vector< T > &in_vector)
 Internal utility function. Converts a vector value to a JSON array value. More...
 
template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue (const std::set< T > &in_set)
 Internal utility function. Converts a set value to a JSON array value. More...
 
template<typename T >
Type rstudio::launcher_plugins::json::asJsonType (const T &in_object)
 Gets the JSON type of the object. More...
 
std::string rstudio::launcher_plugins::json::typeAsString (const Value &in_value)
 Gets the type of the JSON value as a string. More...
 
template<typename T >
Value rstudio::launcher_plugins::json::toJsonValue (const T &in_value)
 Converts a C/C++ value to a JSON value. More...
 
template<typename T >
Array rstudio::launcher_plugins::json::toJsonArray (const std::vector< T > &in_vector)
 Converts a vector value to a JSON array value. More...
 
template<typename T >
Array rstudio::launcher_plugins::json::toJsonArray (const std::set< T > &in_set)
 Converts a set value to a JSON array value. More...
 
Error rstudio::launcher_plugins::json::jsonReadError (JsonReadError in_errorCode, const std::string &in_message, const ErrorLocation &in_errorLocation)
 Creates a JSON read error. More...
 
bool rstudio::launcher_plugins::json::isMissingMemberError (const Error &in_error)
 Checks whether the supplied error is a "missing member" error. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, T &out_value)
 Reads a member from an object. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< T > &out_value)
 Reads a member from an object. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, std::vector< T > &out_values)
 Reads an array member from an object. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, std::set< T > &out_values)
 Reads an array member from an object. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< std::vector< T > > &out_values)
 Reads an optional array member from an object. More...
 
template<typename T >
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< std::set< T > > &out_values)
 Reads an optional array member from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, T &out_value, Args &... io_args)
 Reads multiple members from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< T > &out_value, Args &... io_args)
 Reads multiple members from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, std::vector< T > &out_values, Args &... io_args)
 Reads multiple members from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, std::set< T > &out_values, Args &... io_args)
 Reads multiple members from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< std::vector< T > > &out_value, Args &... io_args)
 Reads multiple members from an object. More...
 
template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject (const Object &in_object, const std::string &in_name, Optional< std::set< T > > &out_value, Args &... io_args)
 Reads multiple members from an object. More...
 

Detailed Description

JSON classes and utility functions.

Enumeration Type Documentation

◆ Type

Enum which represents the type of a json value.

Represents the type of error to send to the RStudio Launcher.

Enum which represents the type of a Response.

Enum which represents the type of a Request.

The type of resource limit.

Enum which represents the Type of a JobConfig value.

The last enum value, INVALID, must always be the last value and is used to validate the received request.

Types are defined as described in the RStudio Launcher API Documentation. See https://docs.rstudio.com/job-launcher/latest/creating-plugins.html#plugin-messages for more details.

Types are defined as described in the RStudio Launcher API Documentation. See https://docs.rstudio.com/job-launcher/latest/creating-plugins.html#plugin-messages for more details.

Function Documentation

◆ asJsonType() [1/3]

template<typename T >
Type rstudio::launcher_plugins::json::asJsonType ( const T &  in_object)

Gets the JSON type of the object.

Template Parameters
TThe C/C++ type of the object.
Parameters
in_objectThe object for which to retrieve the type.
Returns
The JSON type of the specified object.

◆ asJsonType() [2/3]

template<typename T >
Type rstudio::launcher_plugins::json::detail::asJsonType ( const T &  in_object,
std::false_type   
)

Internal utility function. Gets the type of the object as a JSON type, if the object is not a JSON type (e.g. int, bool, string, float, etc.).

Template Parameters
TThe type of in_object.
Parameters
in_objectThe object to get the type of.
Returns
The JSON type of in_object.

◆ asJsonType() [3/3]

template<typename T >
Type rstudio::launcher_plugins::json::detail::asJsonType ( const T &  in_object,
std::true_type   
)

Internal utility function. Gets the type of the object as a JSON type, if the object is a JSON type (e.g. Value, Object, Array).

Template Parameters
TThe type of in_object.
Parameters
in_objectThe object to get the type of.
Returns
The JSON type of in_object.

◆ isMissingMemberError()

bool rstudio::launcher_plugins::json::isMissingMemberError ( const Error in_error)

Checks whether the supplied error is a "missing member" error.

Parameters
in_errorThe error to check.
Returns
True if the error is a missing member error; False otherwise.

◆ isType()

template<typename T >
bool rstudio::launcher_plugins::json::isType ( const Value in_value)

Checks whether the specified JSON value is of the type specified in the template parameter.

Template Parameters
TThe type to check the JSON value against.
Parameters
in_valueThe value of which to check the type.
Returns
True if in_value is of type T; false otherwise.

◆ jsonReadError()

Error rstudio::launcher_plugins::json::jsonReadError ( JsonReadError  in_errorCode,
const std::string &  in_message,
const ErrorLocation in_errorLocation 
)

Creates a JSON read error.

Parameters
in_errorCodeThe code of the error to create.
in_messageThe message of the error.
in_errorLocationThe location at which the error occurred.
Returns
The newly created JSON read error.

◆ readObject() [1/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< std::set< T > > &  out_value,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the values of the array member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valuesThe set of unique values of the array member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if the all the elements of the array member have valid types, and if all other members exist and have valid types; Error otherwise.

◆ readObject() [2/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< std::set< T > > &  out_values 
)

Reads an optional array member from an object.

Template Parameters
TThe type of values of the array member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valuesThe set of unique values of the array member, if no error occurs.
Returns
Success if the values of the member are of type T; Error otherwise.

◆ readObject() [3/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< std::vector< T > > &  out_value,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the values of the array member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valuesThe values of the array member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if the all the elements of the array member have valid types, and if all other members exist and have valid types; Error otherwise.

◆ readObject() [4/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< std::vector< T > > &  out_values 
)

Reads an optional array member from an object.

Template Parameters
TThe type of values of the array member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valuesThe values of the array member, if no error occurs.
Returns
Success if the values of the member are of type T; Error otherwise.

◆ readObject() [5/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< T > &  out_value 
)

Reads a member from an object.

Template Parameters
TThe type of the member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valueThe value of the member, if no error occurs.
Returns
Success if the member could be found and is of type T; Error otherwise.

◆ readObject() [6/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
Optional< T > &  out_value,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the first member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valueThe value of the first member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if all the members exist and have valid types; Error otherwise.

◆ readObject() [7/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
std::set< T > &  out_values 
)

Reads an array member from an object.

Template Parameters
TThe type of values of the array member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valuesThe set of unique values of the array member, if no error occurs.
Returns
Success if the member could be found and its values are of type T; Error otherwise.

◆ readObject() [8/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
std::set< T > &  out_values,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the values of the array member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valuesThe set of unique values of the array member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if the array member exists and all its elements have valid types, and if all other members exist and have valid types; Error otherwise.

◆ readObject() [9/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
std::vector< T > &  out_values 
)

Reads an array member from an object.

Template Parameters
TThe type of values of the array member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valuesThe values of the array member, if no error occurs.
Returns
Success if the member could be found and its values are of type T; Error otherwise.

◆ readObject() [10/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
std::vector< T > &  out_values,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the values of the array member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valuesThe values of the array member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if the array member exists and all its elements have valid types, and if all other members exist and have valid types; Error otherwise.

◆ readObject() [11/12]

template<typename T >
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
T &  out_value 
)

Reads a member from an object.

Template Parameters
TThe type of the member.
Parameters
in_objectThe object from which the member should be read.
in_nameThe name of the member to read.
out_valueThe value of the member, if no error occurs.
Returns
Success if the member could be found and is of type T; Error otherwise.

◆ readObject() [12/12]

template<typename T , typename... Args>
Error rstudio::launcher_plugins::json::readObject ( const Object in_object,
const std::string &  in_name,
T &  out_value,
Args &...  io_args 
)

Reads multiple members from an object.

Template Parameters
TThe type of the first member to read.
ArgsThe template parameter pack for the remaining members.
Parameters
in_objectThe object from which to read the members.
in_nameThe name of the first member to be read.
out_valueThe value of the first member to be read, if no error occurs.
io_argsThe parameter pack of the remaining members to be read.
Returns
Success if all the members exist and have valid types; Error otherwise.

◆ toJsonArray() [1/2]

template<typename T >
Array rstudio::launcher_plugins::json::toJsonArray ( const std::set< T > &  in_set)

Converts a set value to a JSON array value.

Template Parameters
TThe C/C++ type of the set elements.
Parameters
in_setThe set value to convert to a JSON array value.
Returns
The converted JSON array value.

◆ toJsonArray() [2/2]

template<typename T >
Array rstudio::launcher_plugins::json::toJsonArray ( const std::vector< T > &  in_vector)

Converts a vector value to a JSON array value.

Template Parameters
TThe C/C++ type of the vector elements.
Parameters
in_vectorThe vector value to convert to a JSON array value.
Returns
The converted JSON array value.

◆ toJsonValue() [1/5]

template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue ( const Optional< T > &  in_value)
inline

Internal utility function. Converts a C/C++ optional value to a JSON value.

Template Parameters
TThe C/C++ type of the value to convert.
Parameters
in_valueThe optional value to convert to a JSON value.
Returns
The converted JSON value.

◆ toJsonValue() [2/5]

template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue ( const std::set< T > &  in_set)
inline

Internal utility function. Converts a set value to a JSON array value.

Template Parameters
TThe C/C++ type of the set elements.
Parameters
in_setThe set value to convert to a JSON array value.
Returns
The converted JSON array value.

◆ toJsonValue() [3/5]

template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue ( const std::vector< T > &  in_vector)
inline

Internal utility function. Converts a vector value to a JSON array value.

Template Parameters
TThe C/C++ type of the vector elements.
Parameters
in_vectorThe vector value to convert to a JSON array value.
Returns
The converted JSON array value.

◆ toJsonValue() [4/5]

template<typename T >
Value rstudio::launcher_plugins::json::detail::toJsonValue ( const T &  in_value)
inline

Internal utility function. Converts a C/C++ value to a JSON value.

Template Parameters
TThe C/C++ type of the value to convert.
Parameters
in_valueThe value to convert to a JSON value.
Returns
The converted JSON value.

◆ toJsonValue() [5/5]

template<typename T >
Value rstudio::launcher_plugins::json::toJsonValue ( const T &  in_value)
inline

Converts a C/C++ value to a JSON value.

Template Parameters
TThe C/C++ type of the value to convert.
Parameters
in_valueThe value to convert to a JSON value.
Returns
The converted JSON value.

◆ typeAsString()

std::string rstudio::launcher_plugins::json::typeAsString ( const Value in_value)
inline

Gets the type of the JSON value as a string.

Parameters
in_valueThe JSON value for which retrieve the type as a string.
Returns
The type of the JSON value, as a string.