licornea_tools
json.h
Go to the documentation of this file.
1 #ifndef LICORNEA_JSON_H_
2 #define LICORNEA_JSON_H_
3 
4 #include <json.hpp>
5 #include <string>
6 #include "common.h"
7 #include "args.h"
8 
9 namespace tlz {
10 
12 
13 void export_json_file(const json&, const std::string& filename, bool compact = false);
14 json import_json_file(const std::string& filename);
15 
16 cv::Mat_<real> decode_mat(const json&);
17 
18 json encode_mat_(const cv::Mat_<real>&);
19 template<typename Mat> json encode_mat(const Mat& mat) {
20  return encode_mat_(cv::Mat_<real>(mat));
21 }
22 
23 
24 inline bool has(const json& j, const std::string& key) {
25  return (j.count(key) == 1);
26 }
27 template<typename T>
28 T get_or(const json& j, const std::string& key, const T& default_value) {
29  if(has(j, key)) return j[key];
30  else return default_value;
31 }
32 
33 
34 inline json json_arg()
35  { return import_json_file(in_filename_arg()); }
36 
37 }
38 
39 #endif
bool has(const json &j, const std::string &key)
Definition: json.h:24
std::string in_filename_arg()
Definition: args.cc:98
cv::Mat_< real > decode_mat(const json &j)
Definition: json.cc:32
json json_arg()
Definition: json.h:34
json encode_mat(const Mat &mat)
Definition: json.h:19
void export_json_file(const json &j, const std::string &filename, bool compact)
Definition: json.cc:9
nlohmann::json json
Definition: json.h:11
T get_or(const json &j, const std::string &key, const T &default_value)
Definition: json.h:28
json import_json_file(const std::string &filename)
Definition: json.cc:24
json encode_mat_(const cv::Mat_< real > &mat)
Definition: json.cc:51