TraDemGen Logo  0.2.2
C++ Simulated Travel Demand Generation Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
BomDisplay.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <ostream>
00007 // StdAir
00008 #include <stdair/basic/BasConst_BomDisplay.hpp>
00009 #include <stdair/bom/BomManager.hpp>
00010 #include <stdair/bom/EventQueue.hpp>
00011 // TraDemGen
00012 #include <trademgen/bom/DemandStream.hpp>
00013 #include <trademgen/bom/BomDisplay.hpp>
00014 
00015 namespace TRADEMGEN {
00016 
00022   struct FlagSaver {
00023   public:
00025     FlagSaver (std::ostream& oStream)
00026       : _oStream (oStream), _streamFlags (oStream.flags()) {
00027     }
00028 
00030     ~FlagSaver() {
00031       // Reset formatting flags of the given output stream
00032       _oStream.flags (_streamFlags);
00033     }
00034     
00035   private:
00037     std::ostream& _oStream;
00039     std::ios::fmtflags _streamFlags;
00040   };
00041 
00042   // ////////////////////////////////////////////////////////////////////
00043   std::string BomDisplay::csvDisplay (const stdair::EventQueue& iEventQueue) {
00044     std::ostringstream oStream;
00045 
00049     oStream << std::endl;
00050     oStream << "==============================================================="
00051             << std::endl;
00052     oStream << "EventQueue: " << iEventQueue.describeKey() << std::endl;
00053     oStream << "==============================================================="
00054             << std::endl;
00055 
00056     // Check whether there are DemandStream objects
00057     if (stdair::BomManager::hasList<DemandStream> (iEventQueue) == false) {
00058       return oStream.str();
00059     }
00060     
00061     // Retrieve the DemandStream list
00062     const DemandStreamList_T& lDemandStreamList =
00063       stdair::BomManager::getList<DemandStream> (iEventQueue);
00064 
00065     // Browse the inventories
00066     for (DemandStreamList_T::const_iterator itDemandStream =
00067            lDemandStreamList.begin();
00068          itDemandStream != lDemandStreamList.end(); ++itDemandStream) {
00069       DemandStream* lDemandStream_ptr = *itDemandStream;
00070       assert (lDemandStream_ptr != NULL);
00071 
00072       // Display the demand stream
00073       csvDisplay (oStream, *lDemandStream_ptr);
00074     }
00075 
00076     return oStream.str();
00077   }
00078 
00079   // ////////////////////////////////////////////////////////////////////
00080   void BomDisplay::csvDisplay (std::ostream& oStream,
00081                                const DemandStream& iDemandStream) {
00082     // Save the formatting flags for the given STL output stream
00083     FlagSaver flagSaver (oStream);
00084 
00088     oStream << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00089     oStream << iDemandStream.display();
00090     oStream << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00091   }
00092 
00093 }