SEvMgr Logo  1.00.10
C++ Simulation-Oriented Discrete Event Management 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// StdAir
14#include <stdair/STDAIR_Service.hpp>
15#include <stdair/bom/EventStruct.hpp>
16// SEVMGR
19
20#if BOOST_VERSION_MACRO >= 104100
21namespace bpt = boost::property_tree;
22#else // BOOST_VERSION_MACRO >= 104100
23namespace bpt {
24 typedef char ptree;
25}
26#endif // BOOST_VERSION_MACRO >= 104100
27
28namespace SEVMGR {
29
30 // ////////////////////////////////////////////////////////////////////
32 jsonExportEventQueue (stdair::STDAIR_ServicePtr_T& ioSTDAIR_ServicePtr,
33 std::ostream& oStream,
34 const EventQueue& iEventQueue,
35 const stdair::EventType::EN_EventType& iEventType) {
36
37 // Retrieve the event list
38 const stdair::EventList_T& lEventList = iEventQueue.getEventList();
39
40#if BOOST_VERSION_MACRO >= 104100
41 // Create empty property tree objects
42 bpt::ptree ptEvents;
43 bpt::ptree pt;
44
45 // Browse the events
46 for (stdair::EventList_T::const_iterator itEvent = lEventList.begin();
47 itEvent != lEventList.end(); ++itEvent) {
48 const stdair::EventStruct& lEvent = itEvent->second;
49 const stdair::EventType::EN_EventType& lEventType =
50 lEvent.getEventType();
51
52 const bool isEventTypeLastValue =
53 (iEventType == stdair::EventType::LAST_VALUE);
54 if (lEventType == iEventType || isEventTypeLastValue == true) {
55
56 // Delegate the JSON export to the dedicated service
57 const std::string lCurrentEvent =
58 ioSTDAIR_ServicePtr->jsonExportEventObject (lEvent);
59
60 // Load the JSON formatted string into the property tree.
61 // If reading fails (cannot open stream, parse error), an
62 // exception is thrown.
63 if (lCurrentEvent.empty () == false) {
64 bpt::ptree ptCurrentEvent;
65 std::istringstream lStrCurrentEvent(lCurrentEvent);
66 read_json (lStrCurrentEvent, ptCurrentEvent);
67
68 // Put the current inventory tree in the events array
69 ptEvents.push_back(std::make_pair("", ptCurrentEvent));
70 }
71 }
72 }
73
74 // Store the events array tree into the global tree
75 pt.add_child ("events", ptEvents);
76
77 // Write the property tree into the JSON stream.
78 write_json (oStream, pt);
79
80#endif // BOOST_VERSION_MACRO >= 104100
81 }
82
83}
static void jsonExportEventQueue(stdair::STDAIR_ServicePtr_T &, std::ostream &, const EventQueue &, const stdair::EventType::EN_EventType &)
Class holding event structures.
const stdair::EventList_T & getEventList() const
char ptree