Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSon/JComparator.hh
Go to the documentation of this file.
1 #ifndef __JSON__JCOMPARATOR__
2 #define __JSON__JCOMPARATOR__
3 
4 #include <ostream>
5 #include <iomanip>
6 
7 #include "JSon/JSon.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JSON {}
15 namespace JPP { using namespace JSON; }
16 
17 namespace JSON {
18 
19  /**
20  * Auxiliary data structure to compare (part of) JSon data.
21  *
22  * The key can be used to specify which part of the JSon data to print.\n
23  * For example:
24  * <pre>
25  * "Error.Code"
26  * </pre>
27  * will compare the error codes some specific JSon data.
28  */
29  struct JComparator {
30 
31  char SEPARATOR = '.';
32 
33  /**
34  * Defaut constructor.
35  */
37  {}
38 
39 
40  /**
41  * Auxiliary method to compare (part of) JSon data.
42  *
43  * \param ja JSon data
44  * \param jb JSon data
45  * \param key key
46  */
47  inline json operator()(const json& ja, const json& jb, const std::string& key) const
48  {
49  using namespace std;
50 
51  const size_t pos = key.find(SEPARATOR);
52 
53  if (pos != string::npos) {
54  return (*this)(ja[key.substr(0,pos)], ja[key.substr(0,pos)], key.substr(pos + 1));
55  } else if (key != "") {
56  return json::diff(ja[key], jb[key]);
57  } else {
58  return json::diff(ja, jb);
59  }
60  }
61  };
62 }
63 
64 #endif
JComparator()
Defaut constructor.
then awk string
Auxiliary data structure to compare (part of) JSon data.
json operator()(const json &ja, const json &jb, const std::string &key) const
Auxiliary method to compare (part of) JSon data.
nlohmann::json json