$treeview $search $mathjax
SEvMgr Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

BomJSONExport.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <ostream>
00007 #if BOOST_VERSION >= 104100
00008 // Boost Property Tree
00009 #include <boost/property_tree/ptree.hpp>
00010 #include <boost/property_tree/json_parser.hpp>
00011 #include <boost/regex.hpp>
00012 #endif // BOOST_VERSION >= 104100
00013 // StdAir
00014 #include <stdair/STDAIR_Service.hpp>
00015 #include <stdair/bom/EventStruct.hpp>
00016 // SEVMGR
00017 #include <sevmgr/bom/EventQueue.hpp>
00018 #include <sevmgr/bom/BomJSONExport.hpp>
00019 
00020 #if BOOST_VERSION >= 104100
00021 namespace bpt = boost::property_tree;
00022 #else // BOOST_VERSION >= 104100
00023 namespace bpt {
00024   typedef char ptree;
00025 }
00026 #endif // BOOST_VERSION >= 104100
00027 
00028 namespace SEVMGR { 
00029 
00030   // ////////////////////////////////////////////////////////////////////
00031   void BomJSONExport::
00032   jsonExportEventQueue (stdair::STDAIR_ServicePtr_T& ioSTDAIR_ServicePtr,
00033                         std::ostream& oStream,
00034                         const EventQueue& iEventQueue,
00035                         const stdair::EventType::EN_EventType& iEventType) { 
00036 
00037     // Retrieve the event list
00038     const stdair::EventList_T& lEventList = iEventQueue.getEventList();
00039  
00040 #if BOOST_VERSION >= 104100  
00041     // Create empty property tree objects
00042     bpt::ptree ptEvents;   
00043     bpt::ptree pt;  
00044 
00045     // Browse the events
00046     for (stdair::EventList_T::const_iterator itEvent = lEventList.begin();
00047          itEvent != lEventList.end(); ++itEvent) {
00048       const stdair::EventStruct& lEvent = itEvent->second;   
00049       const stdair::EventType::EN_EventType& lEventType = 
00050         lEvent.getEventType();
00051 
00052       const bool isEventTypeLastValue = 
00053         (iEventType == stdair::EventType::LAST_VALUE);
00054       if (lEventType == iEventType || isEventTypeLastValue == true) {
00055  
00056         // Delegate the JSON export to the dedicated service
00057         const std::string lCurrentEvent = 
00058           ioSTDAIR_ServicePtr->jsonExportEventObject (lEvent);  
00059         
00060         // Load the JSON formatted string into the property tree.
00061         // If reading fails (cannot open stream, parse error), an
00062         // exception is thrown. 
00063         if (lCurrentEvent.empty () == false) {
00064           bpt::ptree ptCurrentEvent;  
00065           std::istringstream lStrCurrentEvent(lCurrentEvent);
00066           read_json (lStrCurrentEvent, ptCurrentEvent); 
00067         
00068           // Put the current inventory tree in the events array
00069           ptEvents.push_back(std::make_pair("", ptCurrentEvent));
00070         }
00071       }
00072     }
00073 
00074     // Store the events array tree into the global tree
00075     pt.add_child ("events", ptEvents); 
00076     
00077     // Write the property tree into the JSON stream.
00078     write_json (oStream, pt);
00079 
00080 #endif // BOOST_VERSION >= 104100  
00081   }
00082 
00083 }