Changeset 1852:ffa7c6e96330 in lemon-0.x for lemon/bits/item_writer.h
- Timestamp:
- 12/07/05 12:57:30 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2420
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/item_writer.h
r1535 r1852 54 54 /// 55 55 /// Writes a quoted string to the given stream. 56 void write(std::ostream& os, const std::string& value) {56 void write(std::ostream& os, const std::string& value) const { 57 57 os << "\""; 58 58 if (escaped) { … … 137 137 /// 138 138 /// Writes a quoted char array to the given stream. 139 void write(std::ostream& os, const char* value) {139 void write(std::ostream& os, const char* value) const { 140 140 QuotedStringWriter(escaped).write(os, std::string(value)); 141 141 } … … 169 169 170 170 public: 171 172 IterableWriter(const ItemWriter& _item_writer = ItemWriter()) 173 : item_writer(_item_writer) {} 171 174 172 175 /// \brief Writes the values of the container to the given stream. … … 186 189 187 190 /// \ingroup item_io 191 /// 192 /// \brief Writer for standard pairs. 193 /// 194 /// Writer for standard pairs. The representation of a pair is 195 /// \code ( first_value => second_value ) \endcode. 196 /// \author Balazs Dezso 197 template <typename _Pair, 198 typename _FirstWriter = 199 DefaultWriter<typename _Pair::first_type>, 200 typename _SecondWriter = 201 DefaultWriter<typename _Pair::second_type> > 202 class PairWriter { 203 public: 204 205 typedef _Pair Value; 206 207 typedef _FirstWriter FirstWriter; 208 typedef _SecondWriter SecondWriter; 209 210 private: 211 212 FirstWriter first_writer; 213 SecondWriter second_writer; 214 215 public: 216 217 /// \brief Constructor. 218 /// 219 /// Constructor for the PairWriter. 220 PairWriter(const FirstWriter& _first_writer = FirstWriter(), 221 const SecondWriter& _second_writer = SecondWriter()) 222 : first_writer(_first_writer), second_writer(_second_writer) {} 223 224 /// \brief Writes the pair from the given stream. 225 /// 226 /// Writes the pair from the given stream. 227 void write(std::ostream& os, const Value& value) const { 228 os << "( "; 229 first_writer.write(os, value.first); 230 os << " => "; 231 second_writer.write(os, value.second); 232 os << " )"; 233 } 234 235 }; 236 237 /// \ingroup item_io 188 238 /// 189 239 /// \brief The default item writer template class. … … 218 268 : public QuotedCharArrayWriter {}; 219 269 270 template <> 271 class DefaultWriter<char*> 272 : public QuotedCharArrayWriter {}; 273 274 template <> 275 class DefaultWriter<const char*> 276 : public QuotedCharArrayWriter {}; 277 220 278 template <typename Item> 221 279 class DefaultWriter<std::vector<Item> > … … 234 292 : public IterableWriter<std::set<Item> > {}; 235 293 294 template <typename Key, typename Value> 295 class DefaultWriter<std::map<Key, Value> > 296 : public IterableWriter<std::map<Key, Value> > {}; 297 236 298 template <typename Item> 237 299 class DefaultWriter<std::multiset<Item> > 238 300 : public IterableWriter<std::multiset<Item> > {}; 301 302 template <typename Key, typename Value> 303 class DefaultWriter<std::multimap<Key, Value> > 304 : public IterableWriter<std::multimap<Key, Value> > {}; 305 306 template <typename First, typename Second> 307 class DefaultWriter<std::pair<First, Second> > 308 : public PairWriter<std::pair<First, Second> > {}; 239 309 240 310 /// \ingroup item_io
Note: See TracChangeset
for help on using the changeset viewer.