Jpp  master_rocky
the software that should make you happy
Public Member Functions | Public Attributes | List of all members
JSON::JPrinter Struct Reference

Auxiliary data structure to print (part of) JSon data. More...

#include <JPrinter.hh>

Public Member Functions

 JPrinter ()
 Defaut constructor. More...
 
std::ostream & operator() (std::ostream &out, const JSON::json &js, const std::string &key) const
 Auxiliary method to print (part of) JSon data. More...
 

Public Attributes

char SEPARATOR [2] = { '.', '+' }
 
int WIDTH = 2
 

Detailed Description

Auxiliary data structure to print (part of) JSon data.

The key can be used to specify which part of the JSon data to print.
For example:

  "Error.Code+Message"

will print both the error code and message of some specific JSon data.

Definition at line 29 of file JPrinter.hh.

Constructor & Destructor Documentation

◆ JPrinter()

JSON::JPrinter::JPrinter ( )
inline

Defaut constructor.

Definition at line 37 of file JPrinter.hh.

38  {}

Member Function Documentation

◆ operator()()

std::ostream& JSON::JPrinter::operator() ( std::ostream &  out,
const JSON::json js,
const std::string &  key 
) const
inline

Auxiliary method to print (part of) JSon data.

Parameters
outoutput stream
jsJSon data
keykey

Definition at line 48 of file JPrinter.hh.

49  {
50  using namespace std;
51 
52  size_t pos = key.find(SEPARATOR[0]);
53 
54  if (pos != string::npos) {
55 
56  if (js[key.substr(0, pos)].is_array()) {
57 
58  for (const auto& element : js[key.substr(0, pos)]) {
59  (*this)(out, element, key.substr(pos + 1));
60  }
61 
62  } else {
63 
64  (*this)(out, js[key.substr(0, pos)], key.substr(pos + 1));
65  }
66 
67  } else if (key != "") {
68 
69  pos = key.find(SEPARATOR[1]);
70 
71  out << setw(WIDTH) << js[key.substr(0, pos)] << ' ';
72 
73  if (pos != string::npos)
74  (*this)(out, js, key.substr(pos + 1));
75  else
76  out << endl;
77 
78  } else {
79 
80  out << setw(WIDTH) << js << endl;
81  }
82 
83  return out;
84  }
Definition: JSTDTypes.hh:14
char SEPARATOR[2]
Definition: JPrinter.hh:31
Auxiliary data structure for alignment of data.
Definition: JManip.hh:231

Member Data Documentation

◆ SEPARATOR

char JSON::JPrinter::SEPARATOR[2] = { '.', '+' }

Definition at line 31 of file JPrinter.hh.

◆ WIDTH

int JSON::JPrinter::WIDTH = 2

Definition at line 32 of file JPrinter.hh.


The documentation for this struct was generated from the following file: