From: <den...@us...> - 2010-01-21 19:35:25
|
Revision: 102 http://stdair.svn.sourceforge.net/stdair/?rev=102&view=rev Author: denis_arnaud Date: 2010-01-21 19:35:16 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The log output stream initialisation has been moved into the StdAir library. Modified Paths: -------------- trunk/stdair/stdair/basic/sources.mk Added Paths: ----------- trunk/stdair/stdair/basic/StructAbstract.hpp Added: trunk/stdair/stdair/basic/StructAbstract.hpp =================================================================== --- trunk/stdair/stdair/basic/StructAbstract.hpp (rev 0) +++ trunk/stdair/stdair/basic/StructAbstract.hpp 2010-01-21 19:35:16 UTC (rev 102) @@ -0,0 +1,81 @@ +#ifndef __STDAIR_BAS_STRUCTABSTRACT_HPP +#define __STDAIR_BAS_STRUCTABSTRACT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> + +namespace stdair { + + /** Base class for the light structures. */ + struct StructAbstract { + public: + + /** Destructor. */ + virtual ~StructAbstract() {} + + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const { + ioOut << describe(); + } + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + virtual void fromStream (std::istream& ioIn) {} + + /** Display of the structure. */ + virtual const std::string describe() const = 0; + + protected: + /** Protected Default Constructor to ensure this class is abtract. */ + StructAbstract() {} + }; +} + +/** + Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing + Output Operators" (p653) of his book "The C++ Standard Library: A Tutorial + and Reference", published by Addison-Wesley. +*/ +template <class charT, class traits> +inline +std::basic_ostream<charT, traits>& +operator<< (std::basic_ostream<charT, traits>& ioOut, + const stdair::StructAbstract& iStruct) { + /** + string stream: + - with same format + - without special field width + */ + std::basic_ostringstream<charT,traits> ostr; + ostr.copyfmt (ioOut); + ostr.width (0); + + // Fill string stream + iStruct.toStream (ostr); + + // Print string stream + ioOut << ostr.str(); + + return ioOut; +} + +/** + Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing + Output Operators" (pp655-657) of his book "The C++ Standard Library: + A Tutorial and Reference", published by Addison-Wesley. +*/ +template <class charT, class traits> +inline +std::basic_istream<charT, traits>& +operator>> (std::basic_istream<charT, traits>& ioIn, + stdair::StructAbstract& ioStruct) { + // Fill the Structure object with the input stream. + ioStruct.fromStream (ioIn); + return ioIn; + +} +#endif // __STDAIR_BAS_STRUCTABSTRACT_HPP Modified: trunk/stdair/stdair/basic/sources.mk =================================================================== --- trunk/stdair/stdair/basic/sources.mk 2010-01-21 13:26:12 UTC (rev 101) +++ trunk/stdair/stdair/basic/sources.mk 2010-01-21 19:35:16 UTC (rev 102) @@ -6,6 +6,7 @@ $(top_srcdir)/stdair/basic/BasConst_Yield.hpp \ $(top_srcdir)/stdair/basic/BasConst_Period_BOM.hpp \ $(top_srcdir)/stdair/basic/BasConst_TravelSolution.hpp \ + $(top_srcdir)/stdair/basic/StructAbstract.hpp \ $(top_srcdir)/stdair/basic/BasChronometer.hpp \ $(top_srcdir)/stdair/basic/BasFileMgr.hpp \ $(top_srcdir)/stdair/basic/BasLogParams.hpp \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |