mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:40:05 +00:00
Support loadable radar sites
This commit is contained in:
parent
56cda08b0d
commit
9c2f86b00a
8 changed files with 510 additions and 3 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <fstream>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -27,6 +29,9 @@ static void PrettyPrintJson(std::ostream& os,
|
|||
boost::json::value const& jv,
|
||||
std::string* indent = nullptr);
|
||||
|
||||
static boost::json::value ReadJsonFile(QFile& file);
|
||||
static boost::json::value ReadJsonStream(std::istream& is);
|
||||
|
||||
bool FromJsonInt64(const boost::json::object& json,
|
||||
const std::string& key,
|
||||
int64_t& value,
|
||||
|
|
@ -117,13 +122,56 @@ bool FromJsonString(const boost::json::object& json,
|
|||
|
||||
boost::json::value ReadJsonFile(const std::string& path)
|
||||
{
|
||||
std::ifstream ifs {path};
|
||||
std::string line;
|
||||
boost::json::value json;
|
||||
|
||||
if (path.starts_with(":"))
|
||||
{
|
||||
QFile file(path.c_str());
|
||||
json = ReadJsonFile(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ifstream ifs {path};
|
||||
json = ReadJsonStream(ifs);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
static boost::json::value ReadJsonFile(QFile& file)
|
||||
{
|
||||
boost::json::value json;
|
||||
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QTextStream jsonStream(&file);
|
||||
jsonStream.setEncoding(QStringConverter::Utf8);
|
||||
|
||||
std::string jsonSource = jsonStream.readAll().toStdString();
|
||||
std::istringstream is {jsonSource};
|
||||
|
||||
json = ReadJsonStream(is);
|
||||
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Could not open file for reading: \""
|
||||
<< file.fileName().toStdString() << "\"";
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
static boost::json::value ReadJsonStream(std::istream& is)
|
||||
{
|
||||
std::string line;
|
||||
|
||||
boost::json::stream_parser p;
|
||||
boost::json::error_code ec;
|
||||
|
||||
while (std::getline(ifs, line))
|
||||
while (std::getline(is, line))
|
||||
{
|
||||
p.write(line, ec);
|
||||
if (ec)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue