MeteoIODoc 20240427.aefd3c94
JsonWrapper.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2021 SLF */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef JSONWRAPPER_H
20#define JSONWRAPPER_H
21
22#include <meteoio/IOInterface.h>
23#include <meteoio/thirdParty/picojson.h>
24
25#include <curl/curl.h>
26#include <string>
27#include <vector>
28
29#ifdef _MSC_VER
30 #pragma warning(disable:4512) //we don't need any = operator!
31#endif
32
33namespace mio {
34
76 public:
78 JsonWrapper( const JsonWrapper& );
81
82 void setConnectionParams(const std::string& i_proxy_url, const int& i_http_timeout, const bool& i_debug=false);
83 void readAndParse(const std::string& request, const std::string& where);
84
85 static void printJSON(const picojson::value& v, const unsigned int& depth);
86 std::vector<picojson::value> JSONQuery(const std::string& path) const;
87 picojson::value goToJSONPath(const std::string& path) const;
88
89 std::string getString(const std::string& path) const;
90 std::vector<std::string> getStrings(const std::string& path) const;
91 double getDouble(const std::string& path) const;
92 std::vector<double> getDoubles(const std::string& path) const;
93
94 private:
95 static std::string indent(const unsigned int& depth);
96 static void JSONQuery(const std::string& path, const picojson::value& v, std::vector<picojson::value>& results);
97 static picojson::value goToJSONPath(const std::string& path, const picojson::value& v);
98 static size_t data_write(void* buf, const size_t size, const size_t nmemb, void* userp);
99 bool curl_read(const std::string& url, std::ostream& os);
100
101 picojson::value json_tree;
102 CURL *curl;
103 std::string proxy_url;
104 int http_timeout; //time out for http connections
105 bool debug, proxy;
106 static const int http_timeout_dflt;
107};
108
109} //end namespace mio
110
111#endif
This is a wrapper class around picoJson and Curl.
Definition: JsonWrapper.h:75
static void printJSON(const picojson::value &v, const unsigned int &depth)
Definition: JsonWrapper.cc:85
std::vector< double > getDoubles(const std::string &path) const
Definition: JsonWrapper.cc:221
std::vector< picojson::value > JSONQuery(const std::string &path) const
Definition: JsonWrapper.cc:143
double getDouble(const std::string &path) const
Definition: JsonWrapper.cc:209
JsonWrapper & operator=(const mio::JsonWrapper &)
Definition: JsonWrapper.cc:43
std::vector< std::string > getStrings(const std::string &path) const
Definition: JsonWrapper.cc:190
std::string getString(const std::string &path) const
Definition: JsonWrapper.cc:178
picojson::value goToJSONPath(const std::string &path) const
Definition: JsonWrapper.cc:113
~JsonWrapper()
Definition: JsonWrapper.cc:57
void readAndParse(const std::string &request, const std::string &where)
Definition: JsonWrapper.cc:240
JsonWrapper()
Definition: JsonWrapper.cc:34
void setConnectionParams(const std::string &i_proxy_url, const int &i_http_timeout, const bool &i_debug=false)
Set the connection parameters for CURL.
Definition: JsonWrapper.cc:68
Definition: Config.cc:31