Made Easy::Attachment writable (#1)
the build was successful Details

This commit is contained in:
tastytea 2018-06-14 01:53:28 +02:00
parent 929e815c73
commit 8f30451ec1
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 93 additions and 2 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.16.1
VERSION 0.17.0
LANGUAGES CXX
)

View File

@ -49,6 +49,12 @@ const string Attachment::description() const
return get_string("description");
}
Attachment Attachment::description(const string &description)
{
set("description", Json::Value(description));
return *this;
}
const std::chrono::duration<double> Attachment::duration() const
{
const double sec = get_double("meta.original.duration");
@ -56,6 +62,18 @@ const std::chrono::duration<double> Attachment::duration() const
return std::chrono::duration<double>(sec);
}
const string Attachment::file()
{
return get_string("file");
}
Attachment Attachment::file(const string &file)
{
set("file", Json::Value(file));
return *this;
}
const std::array<double, 2> Attachment::focus() const
{
const Json::Value x = get("meta.focus.x");
@ -72,6 +90,13 @@ const std::array<double, 2> Attachment::focus() const
return {};
}
Attachment Attachment::focus(const std::array<double, 2> &focus)
{
set("meta.focus.x", Json::Value(focus[0]));
set("meta.focus.y", Json::Value(focus[1]));
return *this;
}
const double Attachment::framerate() const
{
string strframes = get_string("meta.original.frame_rate");

View File

@ -68,16 +68,40 @@ namespace Mastodon
* @brief Returns the bitrate of a video
*/
const uint_fast64_t bitrate() const;
/*!
* @brief Returns the image description
*/
const string description() const;
/*!
* @brief Sets the image description
*
* @since 0.17.0
*/
Attachment description(const string &description);
/*!
* @brief Returns the duration of a video in seconds
*/
const std::chrono::duration<double> duration() const;
/*!
* @brief Gets file to upload
*
* @since 0.17.0
*/
const string file();
/*!
* @brief Sets file to upload
*
* @since 0.17.0
*
* @param file Filename
*/
Attachment file(const string &file);
/*!
* @brief Returns the focus point (x, y)
*
@ -85,6 +109,15 @@ namespace Mastodon
*/
const std::array<double, 2> focus() const;
/*!
* @brief Sets the focus point (x, y)
*
* Values are between -1.0 and 1.0.
*
* @since 0.17.0
*/
Attachment focus(const std::array<double, 2> &focus);
/*!
* @brief Returns the framerate of a video in frames per second
*/

View File

@ -225,7 +225,40 @@ const std::vector<string> Easy::Entity::get_vector(const string &key) const
const void Easy::Entity::set(const string &key, const Json::Value &value)
{
_tree[key] = value;
if (key.find('.') == std::string::npos)
{
_tree[key] = value;
return;
}
else
{
std::size_t pos = 0;
string current_key = key;
Json::Value *node = &_tree;
while ((pos = current_key.find('.')) != std::string::npos)
{
try
{
node = &(*node)[current_key.substr(0, pos)];
if (node->isNull())
{
*node = Json::Value(Json::objectValue);
}
current_key = current_key.substr(pos + 1);
}
catch (const Json::LogicError &e)
{
ttdebug << e.what() << '\n';
goto error;
}
}
(*node)[current_key] = value;
return;
}
error:
ttdebug << "Could not set data: " << key << '\n';
}
const std::uint_fast64_t Easy::Entity::stouint64(const string &str) const