TraDemGen Logo  0.2.2
C++ Simulated Travel Demand Generation Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
BomDisplay.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <ostream>
7 // StdAir
8 #include <stdair/basic/BasConst_BomDisplay.hpp>
9 #include <stdair/bom/BomManager.hpp>
10 #include <stdair/bom/EventQueue.hpp>
11 // TraDemGen
14 
15 namespace TRADEMGEN {
16 
22  struct FlagSaver {
23  public:
25  FlagSaver (std::ostream& oStream)
26  : _oStream (oStream), _streamFlags (oStream.flags()) {
27  }
28 
31  // Reset formatting flags of the given output stream
32  _oStream.flags (_streamFlags);
33  }
34 
35  private:
37  std::ostream& _oStream;
39  std::ios::fmtflags _streamFlags;
40  };
41 
42  // ////////////////////////////////////////////////////////////////////
43  std::string BomDisplay::csvDisplay (const stdair::EventQueue& iEventQueue) {
44  std::ostringstream oStream;
45 
49  oStream << std::endl;
50  oStream << "==============================================================="
51  << std::endl;
52  oStream << "EventQueue: " << iEventQueue.describeKey() << std::endl;
53  oStream << "==============================================================="
54  << std::endl;
55 
56  // Check whether there are DemandStream objects
57  if (stdair::BomManager::hasList<DemandStream> (iEventQueue) == false) {
58  return oStream.str();
59  }
60 
61  // Retrieve the DemandStream list
62  const DemandStreamList_T& lDemandStreamList =
63  stdair::BomManager::getList<DemandStream> (iEventQueue);
64 
65  // Browse the inventories
66  for (DemandStreamList_T::const_iterator itDemandStream =
67  lDemandStreamList.begin();
68  itDemandStream != lDemandStreamList.end(); ++itDemandStream) {
69  DemandStream* lDemandStream_ptr = *itDemandStream;
70  assert (lDemandStream_ptr != NULL);
71 
72  // Display the demand stream
73  csvDisplay (oStream, *lDemandStream_ptr);
74  }
75 
76  return oStream.str();
77  }
78 
79  // ////////////////////////////////////////////////////////////////////
80  void BomDisplay::csvDisplay (std::ostream& oStream,
81  const DemandStream& iDemandStream) {
82  // Save the formatting flags for the given STL output stream
83  FlagSaver flagSaver (oStream);
84 
88  oStream << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
89  oStream << iDemandStream.display();
90  oStream << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
91  }
92 
93 }