1.1 --- a/lemon/bits/item_writer.h Tue Dec 06 18:44:26 2005 +0000
1.2 +++ b/lemon/bits/item_writer.h Wed Dec 07 11:57:30 2005 +0000
1.3 @@ -53,7 +53,7 @@
1.4 /// \brief Writes a quoted string to the given stream.
1.5 ///
1.6 /// Writes a quoted string to the given stream.
1.7 - void write(std::ostream& os, const std::string& value) {
1.8 + void write(std::ostream& os, const std::string& value) const {
1.9 os << "\"";
1.10 if (escaped) {
1.11 std::ostringstream ls;
1.12 @@ -136,7 +136,7 @@
1.13 /// \brief Writes a quoted char array to the given stream.
1.14 ///
1.15 /// Writes a quoted char array to the given stream.
1.16 - void write(std::ostream& os, const char* value) {
1.17 + void write(std::ostream& os, const char* value) const {
1.18 QuotedStringWriter(escaped).write(os, std::string(value));
1.19 }
1.20
1.21 @@ -169,6 +169,9 @@
1.22
1.23 public:
1.24
1.25 + IterableWriter(const ItemWriter& _item_writer = ItemWriter())
1.26 + : item_writer(_item_writer) {}
1.27 +
1.28 /// \brief Writes the values of the container to the given stream.
1.29 ///
1.30 /// Writes the values of the container to the given stream.
1.31 @@ -185,6 +188,53 @@
1.32 };
1.33
1.34 /// \ingroup item_io
1.35 + ///
1.36 + /// \brief Writer for standard pairs.
1.37 + ///
1.38 + /// Writer for standard pairs. The representation of a pair is
1.39 + /// \code ( first_value => second_value ) \endcode.
1.40 + /// \author Balazs Dezso
1.41 + template <typename _Pair,
1.42 + typename _FirstWriter =
1.43 + DefaultWriter<typename _Pair::first_type>,
1.44 + typename _SecondWriter =
1.45 + DefaultWriter<typename _Pair::second_type> >
1.46 + class PairWriter {
1.47 + public:
1.48 +
1.49 + typedef _Pair Value;
1.50 +
1.51 + typedef _FirstWriter FirstWriter;
1.52 + typedef _SecondWriter SecondWriter;
1.53 +
1.54 + private:
1.55 +
1.56 + FirstWriter first_writer;
1.57 + SecondWriter second_writer;
1.58 +
1.59 + public:
1.60 +
1.61 + /// \brief Constructor.
1.62 + ///
1.63 + /// Constructor for the PairWriter.
1.64 + PairWriter(const FirstWriter& _first_writer = FirstWriter(),
1.65 + const SecondWriter& _second_writer = SecondWriter())
1.66 + : first_writer(_first_writer), second_writer(_second_writer) {}
1.67 +
1.68 + /// \brief Writes the pair from the given stream.
1.69 + ///
1.70 + /// Writes the pair from the given stream.
1.71 + void write(std::ostream& os, const Value& value) const {
1.72 + os << "( ";
1.73 + first_writer.write(os, value.first);
1.74 + os << " => ";
1.75 + second_writer.write(os, value.second);
1.76 + os << " )";
1.77 + }
1.78 +
1.79 + };
1.80 +
1.81 + /// \ingroup item_io
1.82 ///
1.83 /// \brief The default item writer template class.
1.84 ///
1.85 @@ -217,6 +267,14 @@
1.86 class DefaultWriter<const char[length]>
1.87 : public QuotedCharArrayWriter {};
1.88
1.89 + template <>
1.90 + class DefaultWriter<char*>
1.91 + : public QuotedCharArrayWriter {};
1.92 +
1.93 + template <>
1.94 + class DefaultWriter<const char*>
1.95 + : public QuotedCharArrayWriter {};
1.96 +
1.97 template <typename Item>
1.98 class DefaultWriter<std::vector<Item> >
1.99 : public IterableWriter<std::vector<Item> > {};
1.100 @@ -233,10 +291,22 @@
1.101 class DefaultWriter<std::set<Item> >
1.102 : public IterableWriter<std::set<Item> > {};
1.103
1.104 + template <typename Key, typename Value>
1.105 + class DefaultWriter<std::map<Key, Value> >
1.106 + : public IterableWriter<std::map<Key, Value> > {};
1.107 +
1.108 template <typename Item>
1.109 class DefaultWriter<std::multiset<Item> >
1.110 : public IterableWriter<std::multiset<Item> > {};
1.111
1.112 + template <typename Key, typename Value>
1.113 + class DefaultWriter<std::multimap<Key, Value> >
1.114 + : public IterableWriter<std::multimap<Key, Value> > {};
1.115 +
1.116 + template <typename First, typename Second>
1.117 + class DefaultWriter<std::pair<First, Second> >
1.118 + : public PairWriter<std::pair<First, Second> > {};
1.119 +
1.120 /// \ingroup item_io
1.121 /// \brief Standard WriterTraits for the section writers.
1.122 ///