libdisplaydevice master
C++ library to modify display devices.
json.h File Reference

Declarations for JSON conversion functions. More...

#include <set>
#include "types.h"
Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DD_JSON_DECLARE_CONVERTER(Type)
 Helper MACRO to declare the toJson and fromJson converters for a type.
 

Functions

bool display_device::fromJson (const std::string &string, bool &obj, std::string *error_message=nullptr)
 Deserialize a boolean from JSON.
 
bool display_device::fromJson (const std::string &string, EdidData &obj, std::string *error_message=nullptr)
 Deserialize EDID data from JSON.
 
bool display_device::fromJson (const std::string &string, EnumeratedDevice &obj, std::string *error_message=nullptr)
 Deserialize an enumerated device from JSON.
 
bool display_device::fromJson (const std::string &string, EnumeratedDeviceList &obj, std::string *error_message=nullptr)
 Deserialize an enumerated device list from JSON.
 
bool display_device::fromJson (const std::string &string, SingleDisplayConfiguration &obj, std::string *error_message=nullptr)
 Deserialize a single display configuration from JSON.
 
bool display_device::fromJson (const std::string &string, std::string &obj, std::string *error_message=nullptr)
 Deserialize a string from JSON.
 
bool display_device::fromJson (const std::string &string, StringSet &obj, std::string *error_message=nullptr)
 Deserialize a string set from JSON.
 
std::string display_device::toJson (const bool &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize a boolean to JSON.
 
std::string display_device::toJson (const EdidData &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize EDID data to JSON.
 
std::string display_device::toJson (const EnumeratedDevice &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize an enumerated device to JSON.
 
std::string display_device::toJson (const EnumeratedDeviceList &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize an enumerated device list to JSON.
 
std::string display_device::toJson (const SingleDisplayConfiguration &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize a single display configuration to JSON.
 
std::string display_device::toJson (const std::string &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize a string to JSON.
 
std::string display_device::toJson (const StringSet &obj, const std::optional< unsigned int > &indent=2u, bool *success=nullptr)
 Serialize a string set to JSON.
 

Variables

const std::optional< unsigned int > display_device::JSON_COMPACT {std::nullopt}
 Indentation value for compact JSON output.
 

Detailed Description

Declarations for JSON conversion functions.

Macro Definition Documentation

◆ DD_JSON_DECLARE_CONVERTER

#define DD_JSON_DECLARE_CONVERTER ( Type)
Value:
[[nodiscard]] std::string toJson(const Type &obj, const std::optional<unsigned int> &indent = 2u, bool *success = nullptr); \
[[nodiscard]] bool fromJson(const std::string &string, Type &obj, std::string *error_message = nullptr);

Helper MACRO to declare the toJson and fromJson converters for a type.

*Examples**

EnumeratedDeviceList devices;
DD_LOG(info) << "Got devices:\n" << toJson(devices);
#define DD_LOG(level)
Helper MACRO that disables output string computation if log level is not enabled.
Definition logging.h:153

Function Documentation

◆ fromJson() [1/7]

bool display_device::fromJson ( const std::string & string,
bool & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize a boolean from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [2/7]

bool display_device::fromJson ( const std::string & string,
EdidData & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize EDID data from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [3/7]

bool display_device::fromJson ( const std::string & string,
EnumeratedDevice & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize an enumerated device from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [4/7]

bool display_device::fromJson ( const std::string & string,
EnumeratedDeviceList & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize an enumerated device list from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [5/7]

bool display_device::fromJson ( const std::string & string,
SingleDisplayConfiguration & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize a single display configuration from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [6/7]

bool display_device::fromJson ( const std::string & string,
std::string & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize a string from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ fromJson() [7/7]

bool display_device::fromJson ( const std::string & string,
StringSet & obj,
std::string * error_message = nullptr )
nodiscard

Deserialize a string set from JSON.

Parameters
stringJSON string to parse.
objOutput object updated on success.
error_messageOptional output error message.
Returns
True on success, false otherwise.

◆ toJson() [1/7]

std::string display_device::toJson ( const bool & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize a boolean to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [2/7]

std::string display_device::toJson ( const EdidData & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize EDID data to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [3/7]

std::string display_device::toJson ( const EnumeratedDevice & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize an enumerated device to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [4/7]

std::string display_device::toJson ( const EnumeratedDeviceList & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize an enumerated device list to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [5/7]

std::string display_device::toJson ( const SingleDisplayConfiguration & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize a single display configuration to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [6/7]

std::string display_device::toJson ( const std::string & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize a string to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.

◆ toJson() [7/7]

std::string display_device::toJson ( const StringSet & obj,
const std::optional< unsigned int > & indent = 2u,
bool * success = nullptr )
nodiscard

Serialize a string set to JSON.

Parameters
objObject to serialize.
indentOptional indentation width. Use JSON_COMPACT for compact output.
successOptional output flag set to true on success, false otherwise.
Returns
JSON string on success, error message otherwise.