ConfigurationParameters.h
1 /*
2  * PFPSim: Library for the Programmable Forwarding Plane Simulation Framework
3  *
4  * Copyright (C) 2016 Concordia Univ., Montreal
5  * Samar Abdi
6  * Umair Aftab
7  * Gordon Bailey
8  * Faras Dewal
9  * Shafigh Parsazad
10  * Eric Tremblay
11  *
12  * Copyright (C) 2016 Ericsson
13  * Bochra Boughzala
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28  * 02110-1301, USA.
29  */
30 
31 /*
32 * Author: Lemniscate Snickets
33 * Created On: 04/04/2016
34 */
35 #ifndef CORE_CONFIGURATIONPARAMETERS_H_
36 #define CORE_CONFIGURATIONPARAMETERS_H_
37 
38 #include <iostream>
39 #include <fstream>
40 #include <string>
41 #include "json.hpp"
42 using json = nlohmann::json;
43 
44 namespace pfp{
45 namespace core{
46 
47 class PFPObject;
49  public:
50  typedef json Matrix; // Dom representation is in json format using json lib.
51 
52  explicit ConfigurationParameterNode(std::string filename);
53  ConfigurationParameterNode(Matrix object); // NOLINT(runtime/explicit)
55 
62  // std::cout << "Operator["<<position<<"] called"<<std::endl;
63  auto returnvalue = HeirarchalSearch(position);
64  return ConfigurationParameterNode(returnvalue);
65  }
66 
72  ConfigurationParameterNode operator[] (const std::string Value) {
73  // std::cout<<"Operator["<<Value<<"] called " <<std::endl;
74  auto returnvalue = HeirarchalSearch(Value);
75  return ConfigurationParameterNode(returnvalue);
76  }
81  Matrix get();
82 
83  template<typename T>
84  T get() {
85  return ConfigurationParameters.get<T>();
86  }
87 
88  Matrix LocalSearch(std::string param);
89  Matrix LocalSearch(int position);
90  Matrix HeirarchalSearch(std::string param);
91  Matrix HeirarchalSearch(int position);
92  Matrix Searchinparent(std::string Value, pfp::core::PFPObject* ParentModule);
93  Matrix Searchinparent(int position, pfp::core::PFPObject* ParentModule);
94 
95 
96  struct CompareResult{
97  bool result;
98  Matrix resultobject;
99  };
100 
101  CompareResult CompareStructure(Matrix compareto, Matrix golden);
102  ConfigurationParameterNode MatchandFill(
103  ConfigurationParameterNode matchagainst);
104  void raiseError(std::string message, Matrix compare, Matrix golden);
105  void raiseError(std::string);
106 
107  private:
108  /*Variable that stores the JSON/XML DOM object*/
109  Matrix ConfigurationParameters;
110 };
111 }; // namespace core
112 }; // namespace pfp
113 
114 #endif // CORE_CONFIGURATIONPARAMETERS_H_
ValueType get() const
get a value (explicit)
Definition: json.hpp:2790
Definition: ConfigurationParameters.h:48
a class to store JSON values
Definition: json.hpp:174
ConfigurationParameterNode operator[](const int position)
[operator[] overloads for searching and chaining to maintain intuitive syntax Default behaviour is fo...
Definition: ConfigurationParameters.h:61
Definition: PFPObject.h:102
Definition: ConfigurationParameters.h:96
basic_json<> json
default JSON class
Definition: json.hpp:8672
PacketBase.h.
Definition: ConfigurationParameters.cpp:36