Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ComplexJSON Struct Reference

Custom struct to handle both strings and nested JSON objects. More...

Collaboration diagram for duckdb::ComplexJSON:

Public Member Functions

 ComplexJSON (const string &str)
 Constructor for string values.
 
 ComplexJSON ()
 Basic empty constructor.
 
void AddObjectEntry (const string &key, unique_ptr< ComplexJSON > object)
 Adds entry to the underlying map, also sets the type to OBJECT.
 
void AddArrayElement (unique_ptr< ComplexJSON > object)
 Adds element to the underlying list, also sets the type to ARRAY.
 
ComplexJSONGetObject (const string &key)
 Gets a ComplexJSON object from the map.
 
ComplexJSONGetArrayElement (const idx_t &index)
 Gets a ComplexJSON element from the list.
 
string GetValue (const string &key) const
 Gets a string version of the underlying ComplexJSON object from the map.
 
string GetValue (const idx_t &index) const
 Gets a string version of the underlying ComplexJSON array from the list.
 
unordered_map< string, string > Flatten () const
 Flattens this json to a top level key -> nested json.
 

Static Public Member Functions

static string GetValueRecursive (const ComplexJSON &child)
 Recursive function for GetValue.
 

Private Attributes

string str_value
 Basic string value, in case this is the last value of a nested json.
 
unordered_map< string, unique_ptr< ComplexJSON > > obj_value
 If this is a json object a map of key/value.
 
vector< unique_ptr< ComplexJSON > > arr_value
 If this is a json array a list of values.
 
ComplexJSONType type
 If this json is an object (i.e., map or not)
 

Detailed Description

Custom struct to handle both strings and nested JSON objects.

Constructor & Destructor Documentation

◆ ComplexJSON() [1/2]

duckdb::ComplexJSON::ComplexJSON ( const string &  str)
explicit

Constructor for string values.

49989 : str_value(str), type(ComplexJSONType::VALUE) {
49990}
ComplexJSONType type
If this json is an object (i.e., map or not)
Definition duckdb.hpp:3728
string str_value
Basic string value, in case this is the last value of a nested json.
Definition duckdb.hpp:3722

◆ ComplexJSON() [2/2]

duckdb::ComplexJSON::ComplexJSON ( )

Basic empty constructor.

49992 : type(ComplexJSONType::VALUE) {
49993}

Member Function Documentation

◆ AddObjectEntry()

void duckdb::ComplexJSON::AddObjectEntry ( const string &  key,
unique_ptr< ComplexJSON object 
)

Adds entry to the underlying map, also sets the type to OBJECT.

49995 {
49996 type = ComplexJSONType::OBJECT;
49997 obj_value[key] = std::move(object);
49998}
unordered_map< string, unique_ptr< ComplexJSON > > obj_value
If this is a json object a map of key/value.
Definition duckdb.hpp:3724

◆ AddArrayElement()

void duckdb::ComplexJSON::AddArrayElement ( unique_ptr< ComplexJSON object)

Adds element to the underlying list, also sets the type to ARRAY.

50000 {
50001 type = ComplexJSONType::ARRAY;
50002 arr_value.push_back(std::move(object));
50003}
vector< unique_ptr< ComplexJSON > > arr_value
If this is a json array a list of values.
Definition duckdb.hpp:3726

◆ GetObject()

ComplexJSON & duckdb::ComplexJSON::GetObject ( const string &  key)

Gets a ComplexJSON object from the map.

50005 {
50006 if (type == ComplexJSONType::OBJECT) {
50007 if (obj_value.find(key) == obj_value.end()) {
50008 throw InvalidInputException("Complex JSON Key not found");
50009 }
50010 return *obj_value[key];
50011 }
50012 throw InvalidInputException("ComplexJson is not an object");
50013}

◆ GetArrayElement()

ComplexJSON & duckdb::ComplexJSON::GetArrayElement ( const idx_t index)

Gets a ComplexJSON element from the list.

50015 {
50016 if (type == ComplexJSONType::ARRAY) {
50017 if (index >= arr_value.size()) {
50018 throw InvalidInputException("Complex JSON array element out of bounds");
50019 }
50020 return *arr_value[index];
50021 }
50022 throw InvalidInputException("ComplexJson is not an array");
50023}
index

◆ Flatten()

unordered_map< string, string > duckdb::ComplexJSON::Flatten ( ) const

Flattens this json to a top level key -> nested json.

50025 {
50026 unordered_map<string, string> result;
50027 for (auto &obj : obj_value) {
50028 result[obj.first] = obj.second->GetValueRecursive(*obj.second);
50029 }
50030 return result;
50031}

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