OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StructAbstract.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_BAS_STRUCTABSTRACT_HPP
2 #define __OPENTREP_BAS_STRUCTABSTRACT_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <iosfwd>
9 #include <string>
10 
11 namespace OPENTREP {
12 
16  struct StructAbstract {
17  public:
18 
22  virtual ~StructAbstract() {}
23 
29  void toStream (std::ostream& ioOut) const {
30  ioOut << describe();
31  }
32 
38  virtual void fromStream (std::istream& ioIn) {}
39 
45  virtual std::string describe() const = 0;
46 
47  protected:
52  };
53 }
54 
60 template <class charT, class traits>
61 inline
62 std::basic_ostream<charT, traits>&
63 operator<< (std::basic_ostream<charT, traits>& ioOut,
64  const OPENTREP::StructAbstract& iStruct) {
70  std::basic_ostringstream<charT,traits> ostr;
71  ostr.copyfmt (ioOut);
72  ostr.width (0);
73 
74  // Fill string stream
75  iStruct.toStream (ostr);
76 
77  // Print string stream
78  ioOut << ostr.str();
79 
80  return ioOut;
81 }
82 
88 template <class charT, class traits>
89 inline
90 std::basic_istream<charT, traits>&
91 operator>> (std::basic_istream<charT, traits>& ioIn,
92  OPENTREP::StructAbstract& ioStruct) {
93  // Fill the Structure object with the input stream.
94  ioStruct.fromStream (ioIn);
95  return ioIn;
96 
97 }
98 #endif // __OPENTREP_BAS_STRUCTABSTRACT_HPP
virtual std::string describe() const =0
Base class for the light structures.
void toStream(std::ostream &ioOut) const
virtual void fromStream(std::istream &ioIn)
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &ioIn, OPENTREP::StructAbstract &ioStruct)