diff -r 78b5ea23f0f1 -r ffa7c6e96330 lemon/bits/item_writer.h --- a/lemon/bits/item_writer.h Tue Dec 06 18:44:26 2005 +0000 +++ b/lemon/bits/item_writer.h Wed Dec 07 11:57:30 2005 +0000 @@ -53,7 +53,7 @@ /// \brief Writes a quoted string to the given stream. /// /// Writes a quoted string to the given stream. - void write(std::ostream& os, const std::string& value) { + void write(std::ostream& os, const std::string& value) const { os << "\""; if (escaped) { std::ostringstream ls; @@ -136,7 +136,7 @@ /// \brief Writes a quoted char array to the given stream. /// /// Writes a quoted char array to the given stream. - void write(std::ostream& os, const char* value) { + void write(std::ostream& os, const char* value) const { QuotedStringWriter(escaped).write(os, std::string(value)); } @@ -169,6 +169,9 @@ public: + IterableWriter(const ItemWriter& _item_writer = ItemWriter()) + : item_writer(_item_writer) {} + /// \brief Writes the values of the container to the given stream. /// /// Writes the values of the container to the given stream. @@ -185,6 +188,53 @@ }; /// \ingroup item_io + /// + /// \brief Writer for standard pairs. + /// + /// Writer for standard pairs. The representation of a pair is + /// \code ( first_value => second_value ) \endcode. + /// \author Balazs Dezso + template , + typename _SecondWriter = + DefaultWriter > + class PairWriter { + public: + + typedef _Pair Value; + + typedef _FirstWriter FirstWriter; + typedef _SecondWriter SecondWriter; + + private: + + FirstWriter first_writer; + SecondWriter second_writer; + + public: + + /// \brief Constructor. + /// + /// Constructor for the PairWriter. + PairWriter(const FirstWriter& _first_writer = FirstWriter(), + const SecondWriter& _second_writer = SecondWriter()) + : first_writer(_first_writer), second_writer(_second_writer) {} + + /// \brief Writes the pair from the given stream. + /// + /// Writes the pair from the given stream. + void write(std::ostream& os, const Value& value) const { + os << "( "; + first_writer.write(os, value.first); + os << " => "; + second_writer.write(os, value.second); + os << " )"; + } + + }; + + /// \ingroup item_io /// /// \brief The default item writer template class. /// @@ -217,6 +267,14 @@ class DefaultWriter : public QuotedCharArrayWriter {}; + template <> + class DefaultWriter + : public QuotedCharArrayWriter {}; + + template <> + class DefaultWriter + : public QuotedCharArrayWriter {}; + template class DefaultWriter > : public IterableWriter > {}; @@ -233,10 +291,22 @@ class DefaultWriter > : public IterableWriter > {}; + template + class DefaultWriter > + : public IterableWriter > {}; + template class DefaultWriter > : public IterableWriter > {}; + template + class DefaultWriter > + : public IterableWriter > {}; + + template + class DefaultWriter > + : public PairWriter > {}; + /// \ingroup item_io /// \brief Standard WriterTraits for the section writers. ///