OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
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
11namespace OPENTREP {
12
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
60template <class charT, class traits>
61inline
62std::basic_ostream<charT, traits>&
63operator<< (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
88template <class charT, class traits>
89inline
90std::basic_istream<charT, traits>&
91operator>> (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
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &ioIn, OPENTREP::StructAbstract &ioStruct)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &ioOut, const OPENTREP::StructAbstract &iStruct)
Base class for the light structures.
void toStream(std::ostream &ioOut) const
virtual std::string describe() const =0
virtual void fromStream(std::istream &ioIn)