Scarab  v2.2.3
Project 8 C++ Utility Library
test_param_array.cc
Go to the documentation of this file.
1 /*
2  * test_param_array.cc
3  *
4  * Created on: Jul 17, 2018
5  * Author: N.S. Oblath
6  *
7  * Output should be something like:
8  *
9 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(54): Creating param array
10 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(57): Adding a value
11 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(60): Adding an array
12 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(69): Printing contents:
13 [
14  5
15 
16  {
17  five-hundred : 500
18  }
19 
20 
21  [
22  5000
23  ]
24 
25 ]
26 
27 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(71): After move, should be full:
28 {
29  five-hundred : 500
30 }
31 
32 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(72): After move, should be empty:
33 [
34 ]
35 
36 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(74): Access:
37 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(75): 5
38 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(76): 5
39 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(77): 500
40 2018-07-18 01:33:38 [ INFO] (tid 0x7fff9c9dc380) t_param_array.cc(78): 5000
41  *
42  */
43 
44 #include "param.hh"
45 
46 #include "logger.hh"
47 
48 LOGGER( testlog, "test_param_array" )
49 
50 using namespace scarab;
51 
52 int main()
53 {
54  LINFO( testlog, "Creating param array" );
55  param_array array;
56 
57  LINFO( testlog, "Adding a value" );
58  array.push_back( 5 );
59 
60  LINFO( testlog, "Adding an array" );
61  param_node subnode;
62  subnode.add( "five-hundred", 500 );
63  array.push_back( subnode );
64 
65  param_array subarray;
66  subarray.push_back( "5000" );
67  array.push_back( std::move(subarray) );
68 
69  LINFO( testlog, "Printing contents:" << array );
70 
71  LINFO( testlog, "After copy, should be full: " << subnode );
72  LINFO( testlog, "After move, should be empty: " << subarray );
73 
74  LINFO( testlog, "Access:" );
75  LINFO( testlog, array.get_value(0, 99999) );
76  LINFO( testlog, array[0]() );
77  LINFO( testlog, array[1]["five-hundred"]() );
78  LINFO( testlog, array[2].get_value( 0, "value doesn't exist" ) );
79 
80  return 0;
81 }
82 
83 
84 
std::string get_value(unsigned a_index, const std::string &a_default) const
Definition: param_array.hh:171
#define LOGGER(I, K)
Definition: logger.hh:352
Contains the logger class and macros, based on Kasper&#39;s KLogger class.
#define LINFO(...)
Definition: logger.hh:362
int main()
void push_back(const param &a_value)
Definition: param_array.hh:238
bool add(const std::string &a_name, const param &a_value)
Definition: param_node.hh:228