RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
rstudio::launcher_plugins::json::Object Class Reference

Class which represents a specific type of JSON Value: a JSON object. More...

#include <Json.hpp>

Inheritance diagram for rstudio::launcher_plugins::json::Object:
rstudio::launcher_plugins::json::Value

Classes

class  Iterator
 Class which allows iterating over the members of a JSON object. More...
 
class  Member
 Class which represents a single member of a JSON object. More...
 

Public Types

typedef std::reverse_iterator< IteratorReverseIterator
 Reverse iterator for a JSON object.
 

Public Member Functions

 Object ()
 Constructs an empty JSON object.
 
 Object (const StringPairList &in_strPairs)
 Constructs a JSON object from a list of string pairs. More...
 
 Object (const Object &in_other)
 Copy constructor. More...
 
 Object (Object &&in_other) noexcept
 Move constructor. More...
 
Objectoperator= (const Object &in_other)
 Assignment operator. More...
 
Objectoperator= (Object &&in_other) noexcept
 Move operator. More...
 
Value operator[] (const char *in_name)
 Accessor operator. Gets the value a member of this JSON object by name. If no such object exists, an empty JSON value will be returned. More...
 
Value operator[] (const std::string &in_name)
 Accessor operator. Gets the value a member of this JSON object by name. If no such object exists, an empty JSON value will be returned. More...
 
Iterator find (const char *in_name) const
 Finds a JSON member by name. More...
 
Iterator find (const std::string &in_name) const
 Finds a JSON member by name. More...
 
Iterator begin () const
 Gets an iterator pointing to the first member of this object. More...
 
Iterator end () const
 Gets an iterator after the last member of this object. More...
 
ReverseIterator rbegin () const
 Gets an iterator pointing to the last member of this object, which iterates in the reverse direction. More...
 
ReverseIterator rend () const
 Gets an iterator before the first member of this object, which can be compared with an other ReverseIterator to determine when reverse iteration has ended. More...
 
void clear ()
 Clears the JSON object.
 
bool erase (const char *in_name)
 Erases a member by name. More...
 
bool erase (const std::string &in_name)
 Erases a member by name. More...
 
Iterator erase (const Iterator &in_itr)
 Erases the member specified by the provided iterator. More...
 
size_t getSize () const
 Gets the number of members in the JSON object. More...
 
bool hasMember (const char *in_name) const
 Checks whether this object has a member with the specified name. More...
 
bool hasMember (const std::string &in_name) const
 Checks whether this object has a member with the specified name. More...
 
void insert (const std::string &in_name, const Value &in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, bool in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, double in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, float in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, int in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, int64_t in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, const char *in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, const std::string &in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, unsigned int in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, uint64_t in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, const Array &in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const std::string &in_name, const Object &in_value)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
void insert (const Member &in_member)
 Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden. More...
 
bool isEmpty () const
 Checks whether the JSON object is empty. More...
 
Error parse (const char *in_jsonStr) override
 Parses the JSON string into this object. More...
 
Error parse (const std::string &in_jsonStr) override
 Parses the JSON string into this object. More...
 
bool toStringMap (StringListMap &out_map) const
 Converts this JSON object to a map with string keys and a list of string values. More...
 
StringPairList toStringPairList () const
 Converts this JSON object to a list of string pairs. More...
 
- Public Member Functions inherited from rstudio::launcher_plugins::json::Value
 Value ()
 Constructor.
 
 Value (ValueImplPtr in_valueImpl)
 Constructor. Creates a JSON value from a Value::Impl object. More...
 
 Value (const Value &in_other)
 Copy constructor. More...
 
 Value (Value &&in_other) noexcept
 Move constructor. More...
 
 Value (bool in_value)
 Conversion constructor. More...
 
 Value (double in_value)
 Conversion constructor. More...
 
 Value (float in_value)
 Conversion constructor. More...
 
 Value (int in_value)
 Conversion constructor. More...
 
 Value (int64_t in_value)
 Conversion constructor. More...
 
 Value (const char *in_value)
 Conversion constructor. More...
 
 Value (const std::string &in_value)
 Conversion constructor. More...
 
 Value (unsigned int in_value)
 Conversion constructor. More...
 
 Value (uint64_t in_value)
 Conversion constructor. More...
 
virtual ~Value ()=default
 Virtual destructor.
 
Valueoperator= (const Value &in_other)
 Assignment operator from Value. More...
 
Valueoperator= (Value &&in_other) noexcept
 Move operator. More...
 
Valueoperator= (bool in_value)
 Assignment operator. More...
 
Valueoperator= (double in_value)
 Assignment operator. More...
 
Valueoperator= (float in_value)
 Assignment operator. More...
 
Valueoperator= (int in_value)
 Assignment operator. More...
 
Valueoperator= (int64_t in_value)
 Assignment operator. More...
 
Valueoperator= (const char *in_value)
 Assignment operator. More...
 
Valueoperator= (const std::string &in_value)
 Assignment operator. More...
 
Valueoperator= (unsigned int in_value)
 Assignment operator. More...
 
Valueoperator= (uint64_t in_value)
 Assignment operator. More...
 
bool operator== (const Value &in_other) const
 Equality operator. More...
 
bool operator!= (const Value &in_other) const
 Inequality operator. More...
 
Value clone () const
 Makes a copy of this JSON value. More...
 
Error coerce (const std::string &in_schema, std::vector< std::string > &out_propViolations)
 Attempts to coerce a JSON object to conform to the given schema by discarding non-conforming properties. More...
 
Array getArray () const
 Gets the value as a JSON array. If the call to getType() does not return Type::ARRAY, this method is invalid. More...
 
bool getBool () const
 Gets the value as a bool. If the call to getType() does not return Type::BOOL, this method is invalid. More...
 
double getDouble () const
 Gets the value as a double. If the call to getType() does not return Type::DOUBLE, this method is invalid. More...
 
float getFloat () const
 Gets the value as a float. If the call to getType() does not return Type::FLOAT, this method is invalid. More...
 
int getInt () const
 Gets the value as an int. If the call to getType() does not return Type::INT, this method is invalid. More...
 
int64_t getInt64 () const
 Gets the value as an int64. If the call to getType() does not return Type::INT64, this method is invalid. More...
 
Object getObject () const
 Gets the value as a JSON object. IF the call to getType() does not return Type::OBJECT, this method is invalid. More...
 
std::string getString () const
 Gets the value as a string. If the call to getType() does not return Type::STRING, this method is invalid. More...
 
Type getType () const
 Gets the type of this value. More...
 
unsigned int getUInt () const
 Gets the value as an unsigned int. If the call to getType() does not return Type::UINT, this method is invalid. More...
 
uint64_t getUInt64 () const
 Gets the value as an uint64. If the call to getType() does not return Type::UINT64, this method is invalid. More...
 
template<typename T >
getValue () const
 Gets this JSON value as the specified type. More...
 
bool isArray () const
 Checks whether the value is a JSON array or not. More...
 
bool isBool () const
 Checks whether the value is a boolean value or not. More...
 
bool isDouble () const
 Checks whether the value is a double value or not. More...
 
bool isFloat () const
 Checks whether the value is a float value or not. More...
 
bool isInt () const
 Checks whether the value is an int 32 value or not. More...
 
bool isInt64 () const
 Checks whether the value is an int 64 value or not. More...
 
bool isObject () const
 Checks whether the value is a JSON object or not. More...
 
bool isString () const
 Checks whether the value is a string value or not. More...
 
bool isNull () const
 Checks whether the value is null or not. More...
 
bool isUInt () const
 Checks whether the value is an unsigned int 32 value or not. More...
 
bool isUInt64 () const
 Checks whether the value is an unsigned int 64 value or not. More...
 
Error parseAndValidate (const std::string &in_jsonStr, const std::string &in_schema)
 Parses the JSON string and validates it against the schema. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, const json::Value &in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, bool in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, double in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, float in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, int in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, int64_t in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, const char *in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, const std::string &in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, unsigned int in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, uint64_t in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, const Array &in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error setValueAtPointerPath (const std::string &in_pointerPath, const Object &in_value)
 Sets a value within the current value based on the specified JSON Pointer path. More...
 
Error validate (const std::string &in_schema) const
 Validates this JSON value against a schema. More...
 
std::string write () const
 Writes this value to a string. More...
 
void write (std::ostream &io_ostream) const
 Writes this value to the specified output stream. More...
 
std::string writeFormatted () const
 Writes and formats this value to a string. More...
 
void writeFormatted (std::ostream &io_ostream) const
 Writes and formats this value to the specified output stream. More...
 

Static Public Member Functions

static Member createMember (const std::string &in_name, const Value &in_value)
 Creates a JSON object from the given name and JSON value. More...
 
static Error getSchemaDefaults (const std::string &in_schema, Object &out_schemaDefaults)
 Creates a JSON object which represents the schema defaults of the provided JSON schema string. More...
 
static Object mergeObjects (const Object &in_base, const Object &in_overlay)
 Merges two JSON objects together. Conflicts between the base and the overlay will be resolved by taking the value in the overlay. More...
 

Friends

class Value
 
class Iterator
 

Additional Inherited Members

- Protected Types inherited from rstudio::launcher_plugins::json::Value
typedef std::shared_ptr< Impl > ValueImplPtr
 Convenience typedef for the type of the private implementation of json::Value.
 
- Protected Member Functions inherited from rstudio::launcher_plugins::json::Value
 PRIVATE_IMPL_SHARED (m_impl)
 Private implementation of Value.
 

Detailed Description

Class which represents a specific type of JSON Value: a JSON object.

Constructor & Destructor Documentation

◆ Object() [1/3]

rstudio::launcher_plugins::json::Object::Object ( const StringPairList &  in_strPairs)
explicit

Constructs a JSON object from a list of string pairs.

Parameters
in_strPairsThe list of string pairs from which to construct this object.

◆ Object() [2/3]

rstudio::launcher_plugins::json::Object::Object ( const Object in_other)

Copy constructor.

Parameters
in_otherThe JSON object to copy from.

◆ Object() [3/3]

rstudio::launcher_plugins::json::Object::Object ( Object &&  in_other)
noexcept

Move constructor.

Parameters
in_otherThe JSON object to move to this Object.

Member Function Documentation

◆ begin()

Iterator rstudio::launcher_plugins::json::Object::begin ( ) const

Gets an iterator pointing to the first member of this object.

Returns
An iterator pointing to the first member of this object.

◆ createMember()

static Member rstudio::launcher_plugins::json::Object::createMember ( const std::string &  in_name,
const Value in_value 
)
static

Creates a JSON object from the given name and JSON value.

Parameters
in_nameThe name of the JSON object.
in_valueThe value of the JSON object.
Returns
The newly created member.

◆ end()

Iterator rstudio::launcher_plugins::json::Object::end ( ) const

Gets an iterator after the last member of this object.

Returns
An iterator after the last member of this object.

◆ erase() [1/3]

bool rstudio::launcher_plugins::json::Object::erase ( const char *  in_name)

Erases a member by name.

Parameters
in_nameThe name of the member to erase.
Returns
True if a member was erased; false otherwise.

◆ erase() [2/3]

Iterator rstudio::launcher_plugins::json::Object::erase ( const Iterator in_itr)

Erases the member specified by the provided iterator.

Parameters
in_itrThe iterator pointing to the member to erase.
Returns
An iterator pointing to the member immediately after the erased member.

◆ erase() [3/3]

bool rstudio::launcher_plugins::json::Object::erase ( const std::string &  in_name)

Erases a member by name.

Parameters
in_nameThe name of the member to erase.
Returns
True if a member was erased; false otherwise.

◆ find() [1/2]

Iterator rstudio::launcher_plugins::json::Object::find ( const char *  in_name) const

Finds a JSON member by name.

Parameters
in_nameThe name of the member to find.
Returns
If such a member exists, an iterator pointing to that member; the end iterator otherwise.

◆ find() [2/2]

Iterator rstudio::launcher_plugins::json::Object::find ( const std::string &  in_name) const

Finds a JSON member by name.

Parameters
in_nameThe name of the member to find.
Returns
If such a member exists, an iterator pointing to that member; the end iterator otherwise.

◆ getSchemaDefaults()

static Error rstudio::launcher_plugins::json::Object::getSchemaDefaults ( const std::string &  in_schema,
Object out_schemaDefaults 
)
static

Creates a JSON object which represents the schema defaults of the provided JSON schema string.

Parameters
in_schemaThe JSON schema string to parse into a JSON object.
out_schemaDefaultsThe parsed schema defaults. This object is not valid if an error is returned.
Returns
Success if in_schema could be parsed; Error otherwise.

◆ getSize()

size_t rstudio::launcher_plugins::json::Object::getSize ( ) const

Gets the number of members in the JSON object.

Returns
The number of members in the JSON object.

◆ hasMember() [1/2]

bool rstudio::launcher_plugins::json::Object::hasMember ( const char *  in_name) const

Checks whether this object has a member with the specified name.

Parameters
in_nameThe name of the member for which to check.
Returns
True if a member with the specified name exists; false otherwise.

◆ hasMember() [2/2]

bool rstudio::launcher_plugins::json::Object::hasMember ( const std::string &  in_name) const

Checks whether this object has a member with the specified name.

Parameters
in_nameThe name of the member for which to check.
Returns
True if a member with the specified name exists; false otherwise.

◆ insert() [1/13]

void rstudio::launcher_plugins::json::Object::insert ( const Member in_member)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_memberThe member to insert.

◆ insert() [2/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
bool  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [3/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
const Array in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [4/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
const char *  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [5/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
const Object in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [6/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
const std::string &  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [7/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
const Value in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [8/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
double  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [9/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
float  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [10/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
int  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [11/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
int64_t  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [12/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
uint64_t  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ insert() [13/13]

void rstudio::launcher_plugins::json::Object::insert ( const std::string &  in_name,
unsigned int  in_value 
)

Inserts the specified member into this JSON object. If an object with the same name already exists, it will be overridden.

Parameters
in_nameThe name of the JSON value to insert.
in_valueThe value to insert.

◆ isEmpty()

bool rstudio::launcher_plugins::json::Object::isEmpty ( ) const

Checks whether the JSON object is empty.

Returns
True if the JSON object has no members; false otherwise.

◆ mergeObjects()

static Object rstudio::launcher_plugins::json::Object::mergeObjects ( const Object in_base,
const Object in_overlay 
)
static

Merges two JSON objects together. Conflicts between the base and the overlay will be resolved by taking the value in the overlay.

Parameters
in_baseThe base object to merge.
in_overlayThe overlay object to merge with the base.
Returns
The merged object.

◆ operator=() [1/2]

Object& rstudio::launcher_plugins::json::Object::operator= ( const Object in_other)

Assignment operator.

Parameters
in_otherThe JSON object to copy from.
Returns
A reference to this JSON object.

◆ operator=() [2/2]

Object& rstudio::launcher_plugins::json::Object::operator= ( Object &&  in_other)
noexcept

Move operator.

Parameters
in_otherThe JSON object to move from.
Returns
A reference to this JSON object.

◆ operator[]() [1/2]

Value rstudio::launcher_plugins::json::Object::operator[] ( const char *  in_name)

Accessor operator. Gets the value a member of this JSON object by name. If no such object exists, an empty JSON value will be returned.

Parameters
in_nameThe name of the member to access.
Returns
The value of the member with the specified name, if it exists; empty JSON value otherwise.

◆ operator[]() [2/2]

Value rstudio::launcher_plugins::json::Object::operator[] ( const std::string &  in_name)

Accessor operator. Gets the value a member of this JSON object by name. If no such object exists, an empty JSON value will be returned.

Parameters
in_nameThe name of the member to access.
Returns
The value of the member with the specified name, if it exists; empty JSON value otherwise.

◆ parse() [1/2]

Error rstudio::launcher_plugins::json::Object::parse ( const char *  in_jsonStr)
overridevirtual

Parses the JSON string into this object.

Parameters
in_jsonStrThe JSON string to parse.
Returns
Success on successful parse when the resulting JSON value is a JSON Object; error otherwise (e.g. ParseError).

Reimplemented from rstudio::launcher_plugins::json::Value.

◆ parse() [2/2]

Error rstudio::launcher_plugins::json::Object::parse ( const std::string &  in_jsonStr)
overridevirtual

Parses the JSON string into this object.

Parameters
in_jsonStrThe JSON string to parse.
Returns
Success on successful parse when the resulting JSON value is a JSON Object; error otherwise (e.g. ParseError).

Reimplemented from rstudio::launcher_plugins::json::Value.

◆ rbegin()

ReverseIterator rstudio::launcher_plugins::json::Object::rbegin ( ) const

Gets an iterator pointing to the last member of this object, which iterates in the reverse direction.

Returns
A reverse iterator pointing to the last member of this object.

◆ rend()

ReverseIterator rstudio::launcher_plugins::json::Object::rend ( ) const

Gets an iterator before the first member of this object, which can be compared with an other ReverseIterator to determine when reverse iteration has ended.

Returns
An iterator before the first member of this object.

◆ toStringMap()

bool rstudio::launcher_plugins::json::Object::toStringMap ( StringListMap &  out_map) const

Converts this JSON object to a map with string keys and a list of string values.

Parameters
out_mapThe converted map, on success.
Returns
True if conversion succeeded; false otherwise.

◆ toStringPairList()

StringPairList rstudio::launcher_plugins::json::Object::toStringPairList ( ) const

Converts this JSON object to a list of string pairs.

NOTE: This method will skip any members whose values are not string type.

Returns
The string pairs represented in this object.

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