Add functions to convert between list<string> and Json::Value.
This commit is contained in:
parent
7267981c37
commit
71a754ed1c
|
@ -213,10 +213,7 @@ void Config::parse()
|
|||
profiledata.access_token = _json[profile]["access_token"].asString();
|
||||
profiledata.append = _json[profile]["append"].asString();
|
||||
profiledata.feedurl = _json[profile]["feedurl"].asString();
|
||||
for (const auto &fix : _json[profile]["fixes"])
|
||||
{
|
||||
profiledata.fixes.push_back(fix.asString());
|
||||
}
|
||||
profiledata.fixes = jsonarray_to_stringlist(_json[profile]["fixes"]);
|
||||
profiledata.instance = _json[profile]["instance"].asString();
|
||||
if (!_json[profile]["interval"].isNull())
|
||||
{
|
||||
|
@ -228,10 +225,7 @@ void Config::parse()
|
|||
{
|
||||
profiledata.max_size = _json[profile]["max_size"].asUInt64();
|
||||
}
|
||||
for (const auto &skip : _json[profile]["skip"])
|
||||
{
|
||||
profiledata.skip.push_back(skip.asString());
|
||||
}
|
||||
profiledata.skip = jsonarray_to_stringlist(_json[profile]["skip"]);
|
||||
profiledata.titles_as_cw = _json[profile]["titles_as_cw"].asBool();
|
||||
profiledata.titles_only = _json[profile]["titles_only"].asBool();
|
||||
|
||||
|
@ -243,13 +237,13 @@ void Config::write()
|
|||
_json[profile]["access_token"] = profiledata.access_token;
|
||||
_json[profile]["append"] = profiledata.append;
|
||||
_json[profile]["feedurl"] = profiledata.feedurl;
|
||||
// Leave fixes.
|
||||
_json[profile]["fixes"] = stringlist_to_jsonarray(profiledata.fixes);
|
||||
_json[profile]["instance"] = profiledata.instance;
|
||||
_json[profile]["interval"] = profiledata.interval;
|
||||
_json[profile]["last_guid"] = profiledata.last_guid;
|
||||
_json[profile]["max_size"]
|
||||
= static_cast<Json::Value::UInt64>(profiledata.max_size);
|
||||
// Leave skip.
|
||||
_json[profile]["skip"] = stringlist_to_jsonarray(profiledata.skip);
|
||||
_json[profile]["titles_as_cw"] = profiledata.titles_as_cw;
|
||||
_json[profile]["titles_only"] = profiledata.titles_only;
|
||||
|
||||
|
@ -261,4 +255,27 @@ void Config::write()
|
|||
|
||||
BOOST_LOG_TRIVIAL(debug) << "Wrote config file.";
|
||||
}
|
||||
|
||||
list<string> Config::jsonarray_to_stringlist(const Json::Value &jsonarray) const
|
||||
{
|
||||
list<string> stringlist;
|
||||
for (const auto &element : jsonarray)
|
||||
{
|
||||
stringlist.push_back(element.asString());
|
||||
}
|
||||
return stringlist;
|
||||
}
|
||||
|
||||
Json::Value Config::stringlist_to_jsonarray(const list<string> &stringlist)
|
||||
const
|
||||
{
|
||||
Json::Value jsonarray;
|
||||
for (const auto &element : stringlist)
|
||||
{
|
||||
static Json::ArrayIndex index{0};
|
||||
jsonarray.insert(index, element);
|
||||
++index;
|
||||
}
|
||||
return jsonarray;
|
||||
}
|
||||
} // namespace mastorss
|
||||
|
|
|
@ -21,17 +21,17 @@
|
|||
#include <json/json.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace mastorss
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
using std::uint32_t;
|
||||
using std::list;
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
using std::vector;
|
||||
|
||||
/*!
|
||||
* @brief The configuration for a profile as data structure.
|
||||
|
@ -43,12 +43,12 @@ struct ProfileData
|
|||
string access_token;
|
||||
string append;
|
||||
string feedurl;
|
||||
vector<string> fixes;
|
||||
list<string> fixes;
|
||||
string instance;
|
||||
uint32_t interval{30};
|
||||
string last_guid;
|
||||
size_t max_size{500};
|
||||
vector<string> skip;
|
||||
list<string> skip;
|
||||
bool titles_as_cw{false};
|
||||
bool titles_only{false};
|
||||
|
||||
|
@ -82,6 +82,8 @@ private:
|
|||
[[nodiscard]]
|
||||
string get_access_token(const string &instance) const;
|
||||
void parse();
|
||||
list<string> jsonarray_to_stringlist(const Json::Value &jsonarray) const;
|
||||
Json::Value stringlist_to_jsonarray(const list<string> &stringlist) const;
|
||||
};
|
||||
} // namespace mastorss
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user