Scarab  v2.4.5
Project 8 C++ Utility Library
test_json.cc
Go to the documentation of this file.
1 /*
2  * test_json.cc
3  *
4  * Created on: Jul 18, 2018
5  * Author: N.S. Oblath
6  *
7  * Usage: test_json [filename]
8  */
9 
10 #include "param.hh"
11 #include "param_json.hh"
12 #include "logger.hh"
13 
14 using namespace scarab;
15 
16 LOGGER( slog, "test_json" );
17 
18 int main( int argc, char** argv )
19 {
20  if( argc < 2 )
21  {
22  LERROR( slog, "Please provide a JSON file to read" );
23  return -1;
24  }
25 
26  //read file
27  param_input_json t_input;
28  param_ptr_t t_param_location( t_input.read_file( argv[1] ) );
29  if( ! t_param_location )
30  {
31  LERROR( slog, "File did not read!" );
32  return -1;
33  }
34 
35  LINFO( slog, "File read and parsed: \n" << *t_param_location );
36 
37  //write file
38  param_output_json t_output;
39  bool t_did_write_file = t_output.write_file( *t_param_location, "test_output.json" );
40 
41  if( ! t_did_write_file )
42  {
43  LERROR( slog, "File did not write!" );
44  return -1;
45  }
46 
47  LINFO( slog, "File written successfully (test_output.json)" );
48  return 0;
49 }
LOGGER(mtlog, "authentication")
#define LERROR(...)
Definition: logger.hh:365
virtual param_ptr_t read_file(const std::string &a_filename, const param_node &a_options=param_node())
Definition: param_json.cc:38
Contains the logger class and macros, based on Kasper&#39;s KLogger class.
Convert JSON to Param.
Definition: param_json.hh:43
Convert Param to JSON.
Definition: param_json.hh:71
#define LINFO(...)
Definition: logger.hh:362
std::unique_ptr< param > param_ptr_t
Definition: param_base.hh:23
int main(int argc, char **argv)
Definition: test_json.cc:18
virtual bool write_file(const param &a_to_write, const std::string &a_filename, const param_node &a_options=param_node())
Definition: param_json.cc:182