TvlSim Logo  1.01.6
C++ Simulated Travel-Oriented Distribution System Library
Loading...
Searching...
No Matches
BomJSONExport.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <ostream>
7#if BOOST_VERSION_MACRO >= 104100
8// Boost Property Tree
9#include <boost/property_tree/ptree.hpp>
10#include <boost/property_tree/json_parser.hpp>
11#include <boost/regex.hpp>
12#endif // BOOST_VERSION_MACRO >= 104100
13// TVLSIM
16
17#if BOOST_VERSION_MACRO >= 104100
18namespace bpt = boost::property_tree;
19#else // BOOST_VERSION_MACRO >= 104100
20namespace bpt {
21 typedef char ptree;
22}
23#endif // BOOST_VERSION_MACRO >= 104100
24
25namespace TVLSIM {
26
27 // ////////////////////////////////////////////////////////////////////
29 jsonExportSimulationStatus (std::ostream& oStream,
30 const SimulationStatus& iSimulationStatus) {
31
32#if BOOST_VERSION_MACRO >= 104100
33 // Create empty property tree objects
34 bpt::ptree ptSimulationStatus;
35 bpt::ptree ptEventStatusList;
36 bpt::ptree pt;
37
38 // Get the current mode of the simulation.
39 const SimulationMode& lSimulationMode =
40 iSimulationStatus.getSimulationMode();
41 ptSimulationStatus.put ("state", lSimulationMode.describe());
42 // Put the start date in the simulation status tree
43 const stdair::Date_T& lStartDate =
44 iSimulationStatus.getStartDate();
45 ptSimulationStatus.put ("start_date", lStartDate);
46 // Put the end date in the simulation status tree
47 const stdair::Date_T& lEndDate =
48 iSimulationStatus.getEndDate();
49 ptSimulationStatus.put ("end_date", lEndDate);
50 // Put the current date in the simulation status tree
51 const stdair::Date_T& lCurrentDate =
52 iSimulationStatus.getCurrentDate();
53 ptSimulationStatus.put ("current_date", lCurrentDate);
54 // Put the current number of bookings in the simulation status tree
55 const stdair::NbOfBookings_T& lCurrentNumberOfBookings =
56 iSimulationStatus.getCurrentNumberOfBookings();
57 ptSimulationStatus.put ("bks", lCurrentNumberOfBookings);
58 // Put the total elapsed time in the simulation status tree
59 const double& lCurrentElapsedTime =
60 iSimulationStatus.getCurrentElapsedTime();
61 ptSimulationStatus.put ("elapsed_time", lCurrentElapsedTime);
62 // Put the estimate remaining time in the simulation status tree
63 const double& lCurrentEstimatedRemainingTime =
64 iSimulationStatus.getCurrentEstimatedRemainingTime();
65 ptSimulationStatus.put ("remaining_time", lCurrentEstimatedRemainingTime);
66 // Get the current progress status
67 const stdair::ProgressStatus& lCurrentProgressStatus =
68 iSimulationStatus.getCurrentProgressStatus();
69 // Put the current number in the simulation status tree
70 const stdair::Count_T& lCurrentNumber =
71 lCurrentProgressStatus.getCurrentNb();
72 ptSimulationStatus.put ("current_number", lCurrentNumber);
73 // Put the actual number in the simulation status tree
74 const stdair::Count_T& lActualNumber =
75 lCurrentProgressStatus.getActualNb();
76 ptSimulationStatus.put ("actual_number", lActualNumber);
77
78 // Retrieve the progress status map
79 const SEVMGR::ProgressStatusMap_T& lProgressStatusMap =
80 iSimulationStatus.getProgressStatusMap();
81 // Put data for each event type in the simulation status tree
82 for (SEVMGR::ProgressStatusMap_T::const_iterator itPS =
83 lProgressStatusMap.begin(); itPS != lProgressStatusMap.end(); itPS++) {
84 bpt::ptree ptEventStatus;
85 const stdair::EventType::EN_EventType& lEventType = itPS->first;
86 const stdair::ProgressStatus& lProgressStatus = itPS->second;
87 // Put the event type
88 const std::string& lEventTypeStr =
89 stdair::EventType::getLabel(lEventType);
90 ptEventStatus.put ("type", lEventTypeStr);
91 // Put the current number of events for this event type
92 const stdair::Count_T& lCurrentNumber =
93 lProgressStatus.getCurrentNb();
94 ptEventStatus.put ("current_number", lCurrentNumber);
95 // Put the actual number of events for this event type
96 const stdair::Count_T& lActualNumber =
97 lProgressStatus.getActualNb();
98 ptEventStatus.put ("actual_number", lActualNumber);
99
100 // Put the current status tree in the status array
101 ptEventStatusList.push_back(std::make_pair("", ptEventStatus));
102 }
103
104 // Add the list of status to the status tree
105 ptSimulationStatus.add_child ("specific_status", ptEventStatusList);
106
107 // Store the status tree into the global tree
108 pt.add_child ("status", ptSimulationStatus);
109
110 // Write the property tree into the JSON stream.
111 write_json (oStream, pt);
112
113#endif // BOOST_VERSION_MACRO >= 104100
114 }
115
116}
static void jsonExportSimulationStatus(std::ostream &, const SimulationStatus &)
char ptree
Enumeration of json commands.
const std::string describe() const
const stdair::Date_T & getCurrentDate() const
const stdair::NbOfBookings_T & getCurrentNumberOfBookings() const
const stdair::Date_T & getEndDate() const
const double & getCurrentElapsedTime() const
const double & getCurrentEstimatedRemainingTime() const
const stdair::ProgressStatus & getCurrentProgressStatus() const
const SimulationMode & getSimulationMode() const
const SEVMGR::ProgressStatusMap_T & getProgressStatusMap() const
const stdair::Date_T & getStartDate() const