writers.xml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <chapter>
  2. <title><tt>__vic/writers/</tt></title>
  3. <chapter>
  4. <title><tt>Writer</tt> concept</title>
  5. <code-block lang="C++"><![CDATA[
  6. template<class ElementT>
  7. class ]]><nt>Writer</nt><![CDATA[
  8. {
  9. public:
  10. Writer(Writer &&o); or Writer(const Writer &o);
  11. void write(ElementT v); // throws on errors
  12. };
  13. ]]></code-block>
  14. <p>A concept used by the library algorihms to write logical sequence of elements
  15. of type <tt>ElementT</tt> element by element. It is a generalization and rework
  16. of the <tt>OutputIterator</tt> concept. In particular it better handles streams
  17. and other output sequences where <tt>end</tt>-iterator is meaningless or
  18. expensive to obtain. At the same time, traditional output iterators as
  19. <tt>std::back_insert_iterator</tt> are just a particular case and fully and well
  20. handled by <tt>__vic::push_back_writer</tt> adapter.</p>
  21. <p>When the particular class meets the requirements of this concept for some
  22. <tt>ElementT = T</tt> it is said <b>to model</b> the <tt>Writer&lt;T></tt>
  23. concept.</p>
  24. <p>Each instance of the class has to be move- or copy-constructible.</p>
  25. <section><title>Class members</title>
  26. <synopsis>
  27. <prototype>void write(ElementT v)</prototype>
  28. <p>Writes the element or throws an exception on error.</p>
  29. </synopsis>
  30. </section>
  31. </chapter>
  32. <chapter>
  33. <title><tt>push_back_writer</tt></title>
  34. <code-block lang="C++"><![CDATA[
  35. #include<__vic/writers/push_back.h>
  36. template<class Cont, class T = typename Cont::value_type>
  37. class push_back_writer
  38. {
  39. public:
  40. explicit push_back_writer(Cont &c);
  41. void write(T v) { c->push_back(v); }
  42. };
  43. ]]></code-block>
  44. <p>An adapter. Uses <tt>push_back()</tt> member function to write elements.</p>
  45. </chapter>
  46. <chapter>
  47. <title><tt>string_writer</tt></title>
  48. <code-block lang="C++"><![CDATA[
  49. #include<__vic/writers/string.h>
  50. template<
  51. class charT,
  52. class Tr = std::char_traits<charT>,
  53. class Al = std::allocator<charT>
  54. >
  55. class basic_string_writer
  56. {
  57. public:
  58. explicit basic_string_writer(std::basic_string<charT,Tr,Al> &s);
  59. void write(charT ch);
  60. };
  61. using string_writer = basic_string_writer<char>;
  62. ]]></code-block>
  63. <p>An adapter for <tt>std::basic_string</tt>.</p>
  64. </chapter>
  65. <chapter>
  66. <title><tt>cstream_writer</tt></title>
  67. <code-block lang="C++"><![CDATA[
  68. #include<__vic/writers/cstream.h>
  69. class cstream_writer
  70. {
  71. public:
  72. explicit cstream_writer(std::FILE *fp);
  73. void write(char ch) { __vic::write(fp, ch); }
  74. };
  75. ]]></code-block>
  76. <p>Models <tt>Writer&lt;char></tt> for <tt>std::FILE</tt>.</p>
  77. </chapter>
  78. </chapter>