WSL/SLF GitLab Repository

Commit eea956b2 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

still moving forward with the DBO plugin, picojson has been edited to fix the...

still moving forward with the DBO plugin, picojson has been edited to fix the warnings (few changes), fixing a misplaced space in SetCompilerOptions
parent c96ca526
......@@ -42,7 +42,7 @@ namespace mio {
* - DBO_URL: The URL of the RESTful web service e.g.http://developwis.wsl.ch:8730/osper-api
* - DBO_USER: The username to access the service (optional)
* - DBO_PASS: The password to authenticate the USER (optional)
* - STATION#: station code for the given station, e. g. la_fouly_1034 (case sensitive!)
* - STATION#: station code for the given station, prefixed by the network it belongs ot (for example: IMIS::SLF2)
* - DBO_TIMEOUT: timeout (in seconds) for the connection to the server (default: 60s)
* - DBO_DEBUG: print the full requests/answers from the server when something does not work as expected
*
......@@ -54,6 +54,39 @@ namespace mio {
* STATION1 = wind_tunnel_meteo
* @endcode
*
* @section dbo_dependencies Picojson
* This plugin relies on <A HREF="https://github.com/kazuho/picojson/">picojson</A> for reading and parsing
* <A HREF="https://en.wikipedia.org/wiki/JSON">JSON</A> data. Picojson is released under a
* <A HREF="https://opensource.org/licenses/BSD-2-Clause">2-Clause BSD License</A>. Please find here below
* the full license agreement for picojson:
*
* @code
* Copyright 2009-2010 Cybozu Labs, Inc.
* Copyright 2011-2014 Kazuho Oku
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @endcode
*/
//we keep it as a simple function in order to avoid exposing picojson stuff in the header
......@@ -138,8 +171,9 @@ void goToJSONPath(const std::string& path, picojson::value& v, std::vector<picoj
goToJSONPath(remaining_path, array[jj], results);
} else
goToJSONPath(remaining_path, it->second, results);
} else
} else {
results.push_back( it->second );
}
}
}
}
......@@ -267,11 +301,15 @@ void DBO::fillStationMeta()
vecMeta.clear();
for(size_t ii=0; ii<vecStationName.size(); ii++) {
const std::string station_id( vecStationName[ii] );
const std::string request( metadata_endpoint + IOUtils::strToLower( station_id ) );
std::string station_id( vecStationName[ii] );
if (station_id.find(':')==std::string::npos) station_id = "IMIS::" + station_id;
const std::string request( metadata_endpoint + "name=" + IOUtils::strToLower( station_id ) );
stringstream ss;
if (curl_read(request, ss)) {
if (ss.str().empty())
throw UnknownValueException("Station not found: '"+station_id+"'", AT);
picojson::value v;
const std::string err( picojson::parse(v, ss.str()) );
if (!err.empty()) throw IOException("Error while parsing JSON: "+err, AT);
......@@ -286,9 +324,9 @@ void DBO::fillStationMeta()
vecMeta.push_back( sd );
//select proper time series
/*const std::vector<std::string> ts_codes( getStrings("$.properties.timeseries.measurand.code", v) );
const std::vector<std::string> ts_codes( getStrings("$.properties.timeseries.code", v) );
for(size_t jj=0; jj<ts_codes.size(); jj++)
std::cout << "Found " << ts_codes[jj] << "\n";*/
std::cout << "Found " << ts_codes[jj] << "\n";
} else {
if (dbo_debug)
......
......@@ -42,13 +42,6 @@
#include <vector>
#include <utility>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wconversion"
#endif
// for isnan/isinf
#if __cplusplus>=201103L
# include <cmath>
......@@ -175,12 +168,12 @@ namespace picojson {
template <typename T> void set(T &&);
#endif
bool evaluate_as_boolean() const;
const value& get(size_t idx) const;
const value& get(const size_t idx) const;
const value& get(const std::string& key) const;
value& get(size_t idx);
value& get(const size_t idx);
value& get(const std::string& key);
bool contains(size_t idx) const;
bool contains(const size_t idx) const;
bool contains(const std::string& key) const;
std::string to_str() const;
template <typename Iter> void serialize(Iter os, bool prettify = false) const;
......@@ -196,9 +189,9 @@ namespace picojson {
typedef value::array array;
typedef value::object object;
inline value::value() : type_(null_type) {}
inline value::value() : type_(null_type), u_() {}
inline value::value(int type, bool) : type_(type) {
inline value::value(int type, bool) : type_(type), u_() {
switch (type) {
#define INIT(p, v) case p##type: u_.p = v; break
INIT(boolean_, false);
......@@ -214,17 +207,17 @@ namespace picojson {
}
}
inline value::value(bool b) : type_(boolean_type) {
inline value::value(bool b) : type_(boolean_type), u_() {
u_.boolean_ = b;
}
#ifdef PICOJSON_USE_INT64
inline value::value(int64_t i) : type_(int64_type) {
inline value::value(int64_t i) : type_(int64_type), u_() {
u_.int64_ = i;
}
#endif
inline value::value(double n) : type_(number_type) {
inline value::value(double n) : type_(number_type), u_() {
if (
#ifdef _MSC_VER
! _finite(n)
......@@ -239,37 +232,37 @@ namespace picojson {
u_.number_ = n;
}
inline value::value(const std::string& s) : type_(string_type) {
inline value::value(const std::string& s) : type_(string_type), u_() {
u_.string_ = new std::string(s);
}
inline value::value(const array& a) : type_(array_type) {
inline value::value(const array& a) : type_(array_type), u_() {
u_.array_ = new array(a);
}
inline value::value(const object& o) : type_(object_type) {
inline value::value(const object& o) : type_(object_type), u_() {
u_.object_ = new object(o);
}
#if PICOJSON_USE_RVALUE_REFERENCE
inline value::value(std::string&& s) : type_(string_type) {
inline value::value(std::string&& s) : type_(string_type), u_() {
u_.string_ = new std::string(std::move(s));
}
inline value::value(array&& a) : type_(array_type) {
inline value::value(array&& a) : type_(array_type), u_() {
u_.array_ = new array(std::move(a));
}
inline value::value(object&& o) : type_(object_type) {
inline value::value(object&& o) : type_(object_type), u_() {
u_.object_ = new object(std::move(o));
}
#endif
inline value::value(const char* s) : type_(string_type) {
inline value::value(const char* s) : type_(string_type), u_() {
u_.string_ = new std::string(s);
}
inline value::value(const char* s, size_t len) : type_(string_type) {
inline value::value(const char* s, size_t len) : type_(string_type), u_() {
u_.string_ = new std::string(s, len);
}
......@@ -288,7 +281,7 @@ namespace picojson {
clear();
}
inline value::value(const value& x) : type_(x.type_) {
inline value::value(const value& x) : type_(x.type_), u_() {
switch (type_) {
#define INIT(p, v) case p##type: u_.p = v; break
INIT(string_, new std::string(*x.u_.string_));
......@@ -310,7 +303,7 @@ namespace picojson {
}
#if PICOJSON_USE_RVALUE_REFERENCE
inline value::value(value&& x)throw() : type_(null_type) {
inline value::value(value&& x)throw() : type_(null_type), u_() {
swap(x);
}
inline value& value::operator=(value&& x)throw() {
......@@ -415,13 +408,13 @@ namespace picojson {
}
}
inline const value& value::get(size_t idx) const {
inline const value& value::get(const size_t idx) const {
static value s_null;
PICOJSON_ASSERT(is<array>());
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
}
inline value& value::get(size_t idx) {
inline value& value::get(const size_t idx) {
static value s_null;
PICOJSON_ASSERT(is<array>());
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
......@@ -441,7 +434,7 @@ namespace picojson {
return i != u_.object_->end() ? i->second : s_null;
}
inline bool value::contains(size_t idx) const {
inline bool value::contains(const size_t idx) const {
PICOJSON_ASSERT(is<array>());
return idx < u_.array_->size();
}
......@@ -662,9 +655,9 @@ namespace picojson {
}
}
}
bool expect(int expect) {
bool expect(const int expected) {
skip_ws();
if (getc() != expect) {
if (getc() != expected) {
ungetc();
return false;
}
......@@ -727,20 +720,20 @@ namespace picojson {
uni_ch += 0x10000;
}
if (uni_ch < 0x80) {
out.push_back(uni_ch);
out.push_back( static_cast<char>(uni_ch) );
} else {
if (uni_ch < 0x800) {
out.push_back(0xc0 | (uni_ch >> 6));
out.push_back( static_cast<char>(0xc0 | (uni_ch >> 6)) );
} else {
if (uni_ch < 0x10000) {
out.push_back(0xe0 | (uni_ch >> 12));
out.push_back( static_cast<char>(0xe0 | (uni_ch >> 12)) );
} else {
out.push_back(0xf0 | (uni_ch >> 18));
out.push_back(0x80 | ((uni_ch >> 12) & 0x3f));
out.push_back( static_cast<char>(0xf0 | (uni_ch >> 18)) );
out.push_back( static_cast<char>(0x80 | ((uni_ch >> 12) & 0x3f)) );
}
out.push_back(0x80 | ((uni_ch >> 6) & 0x3f));
out.push_back( static_cast<char>(0x80 | ((uni_ch >> 6) & 0x3f)) );
}
out.push_back(0x80 | (uni_ch & 0x3f));
out.push_back( static_cast<char>(0x80 | (uni_ch & 0x3f)) );
}
return true;
}
......@@ -777,7 +770,7 @@ namespace picojson {
return false;
}
} else {
out.push_back(ch);
out.push_back( static_cast<char>(ch) );
}
}
return false;
......@@ -827,7 +820,7 @@ namespace picojson {
int ch = in.getc();
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-'
|| ch == 'e' || ch == 'E') {
num_str.push_back(ch);
num_str.push_back( static_cast<char>(ch) );
} else if (ch == '.') {
#if PICOJSON_USE_LOCALE
num_str += localeconv()->decimal_point;
......@@ -867,7 +860,7 @@ namespace picojson {
double f;
char *endp;
in.ungetc();
std::string num_str = _parse_number(in);
std::string num_str( _parse_number(in) );
if (num_str.empty()) {
return false;
}
......@@ -1018,7 +1011,7 @@ namespace picojson {
if (ch == -1 || ch == '\n') {
break;
} else if (ch >= ' ') {
err->push_back(ch);
err->push_back( static_cast<char>(ch) );
}
}
}
......@@ -1092,7 +1085,7 @@ namespace std {
inline std::istream& operator>>(std::istream& is, picojson::value& x)
{
picojson::set_last_error(std::string());
std::string err = picojson::parse(x, is);
const std::string err( picojson::parse(x, is) );
if (! err.empty()) {
picojson::set_last_error(err);
is.setstate(std::ios::failbit);
......@@ -1108,8 +1101,5 @@ inline std::ostream& operator<<(std::ostream& os, const picojson::value& x)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif
......@@ -122,7 +122,7 @@ MACRO (SET_COMPILER_OPTIONS)
ENDIF()
IF(GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0)
IF (PLUGIN_IMISIO) #HACK: current OCCI does not support the short strings optimizations of gcc>=5
IF(PLUGIN_IMISIO) #HACK: current OCCI does not support the short strings optimizations of gcc>=5
SET(EXTRA "-D_GLIBCXX_USE_CXX11_ABI=0 ${EXTRA}")
ENDIF(PLUGIN_IMISIO)
ENDIF()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment