mastodon-cpp
0.110.0
|
Base class for all entities. More...
#include <entity.hpp>
Public Member Functions | |
Entity (const string &json) | |
Constructs an Entity object from a JSON string. More... | |
Entity (const Json::Value &object) | |
Constructs an Entity object from a JSON object. More... | |
Entity () | |
Constructs an empty Entity object. More... | |
virtual | ~Entity () |
Destroys the object. More... | |
operator const Json::Value () const | |
void | from_string (const string &json) |
Replaces the Entity with a new one from a JSON string. More... | |
const string | to_string () const |
Returns the JSON of the Entity as formatted string. More... | |
void | from_object (const Json::Value &object) |
Replaces the Entity with a new one from a JSON object. More... | |
const Json::Value | to_object () const |
Returns the JSON object of the Entity. More... | |
virtual bool | valid () const =0 |
Returns true if the Entity holds valid data. More... | |
const string | error () const |
Returns error string sent by the server. More... | |
bool | was_set () const |
Returns true if the last requested value was set, false if it was unset. More... | |
Protected Member Functions | |
const Json::Value | get (const string &key) const |
Returns the value of key as Json::Value. More... | |
const string | get_string (const string &key) const |
Returns the value of key as std::string. More... | |
uint64_t | get_uint64 (const string &key) const |
Returns the value of key as std::uint64_t. More... | |
double | get_double (const string &key) const |
Returns the value of key as double. More... | |
bool | get_bool (const string &key) const |
Returns the value of key as bool. More... | |
const Easy::time_type | get_time (const string &key) const |
Returns the value of key as Easy::time. More... | |
const std::vector< string > | get_vector (const string &key) const |
Returns the value of key as vector. More... | |
void | set (const string &key, const Json::Value &value) |
Sets the value of key. More... | |
std::uint64_t | stouint64 (const string &str) const |
Returns value of str as uint64_t. | |
bool | check_valid (const std::vector< string > &attributes) const |
Checks if an Entity is valid. More... | |
Base class for all entities.
|
explicit |
Constructs an Entity object from a JSON string.
json | JSON string |
|
explicit |
Easy::Entity::Entity | ( | ) |
Constructs an empty Entity object.
|
protected |
Checks if an Entity is valid.
attributes | The attributes to check |
const string Easy::Entity::error | ( | ) | const |
Returns error string sent by the server.
void Easy::Entity::from_object | ( | const Json::Value & | object | ) |
void Easy::Entity::from_string | ( | const string & | json | ) |
Replaces the Entity with a new one from a JSON string.
json | JSON string |
|
protected |
Returns the value of key as Json::Value.
Returns an empty object if the value does not exist or is null.
|
protected |
Returns the value of key as bool.
Returns false if the value does not exist or is null.
|
protected |
Returns the value of key as double.
Returns 0.0 if the value does not exist or is null.
|
protected |
Returns the value of key as std::string.
returns "" if the value does not exist or is null.
|
protected |
Returns the value of key as Easy::time.
Returns clocks epoch if the value does not exist or is null.
|
protected |
Returns the value of key as std::uint64_t.
Returns 0 if the value does not exist or is null.
|
protected |
Returns the value of key as vector.
Returns an empty vector if the value does not exist or is null.
Easy::Entity::operator const Json::Value | ( | ) | const |
Returns the JSON object of the Entity
|
protected |
Sets the value of key.
const Json::Value Easy::Entity::to_object | ( | ) | const |
const string Easy::Entity::to_string | ( | ) | const |
|
pure virtual |
Returns true if the Entity holds valid data.
Implemented in Mastodon::Easy::Account::Source, Mastodon::Easy::Attachment, Mastodon::Easy::Tag, Mastodon::Easy::Attachment::Meta, Mastodon::Easy::Status, Mastodon::Easy::Tag::History, Mastodon::Easy::Account, Mastodon::Easy::Instance, Mastodon::Easy::Notification, Mastodon::Easy::PushSubscription, Mastodon::Easy::Results, Mastodon::Easy::Conversation, Mastodon::Easy::List, Mastodon::Easy::Mention, Mastodon::Easy::Poll, Mastodon::Easy::Card, Mastodon::Easy::Context, Mastodon::Easy::Relationship, Mastodon::Easy::Application, Mastodon::Easy::Emoji, Mastodon::Easy::Filter, and Mastodon::Easy::Token.
bool Easy::Entity::was_set | ( | ) | const |
Returns true if the last requested value was set, false if it was unset.
Members of Easy::Entity-derived classes return a default value depending on its type when the requested value is not found in the JSON. "" for strings, false for bools and so on. Most of the time this is no problem, but sometimes you need to know for sure.
Example: