writers.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <chapter xml:id="writers">
  2. <title><tt>__vic/writers/</tt></title>
  3. <chapter xml:id="writer-concept">
  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 algorithms 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 handles streams
  17. and other output sequences where <tt>end</tt>-iterator is meaningless or
  18. expensive to obtain better. At the same time, a traditional output iterators
  19. are just a particular case and fully and well handled by
  20. <tt>__vic::iterator_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 xml:id="null_writer">
  33. <title><tt>null_writer</tt></title>
  34. <code-block lang="C++"><![CDATA[
  35. #include<__vic/writers/null.h>
  36. class null_writer
  37. {
  38. public:
  39. template<class T> void write(T v) {}
  40. };
  41. null_writer make_null_writer();
  42. ]]></code-block>
  43. <p>Fake writer that accepts any value and does nothing with it (like UNIX
  44. <tt>/dev/null</tt>).</p>
  45. </chapter>
  46. <chapter xml:id="push_back_writer">
  47. <title><tt>push_back_writer</tt></title>
  48. <code-block lang="C++"><![CDATA[
  49. #include<__vic/writers/push_back.h>
  50. template<class Cont, class T = typename Cont::value_type>
  51. class push_back_writer
  52. {
  53. public:
  54. explicit push_back_writer(Cont &c);
  55. void write(T v) { c->push_back(v); }
  56. };
  57. template<class Cont>
  58. push_back_writer<Cont> make_push_back_writer(Cont &c);
  59. template<class T, class Cont>
  60. push_back_writer<Cont,T> make_push_back_writer_for(Cont &c);
  61. ]]></code-block>
  62. <p>An adapter. Uses <tt>push_back()</tt> member function to write elements.
  63. Can be created using constructor or one of <tt>make_...</tt> functions.</p>
  64. </chapter>
  65. <chapter xml:id="iterator_writer">
  66. <title><tt>iterator_writer</tt></title>
  67. <code-block lang="C++"><![CDATA[
  68. #include<__vic/writers/iterator.h>
  69. template<class OutputIterator,
  70. class T = typename std::iterator_traits<OutputIterator>::value_type>
  71. class iterator_writer
  72. {
  73. public:
  74. explicit iterator_writer(OutputIterator it);
  75. void write(T v);
  76. };
  77. template<class OutputIterator>
  78. iterator_writer<OutputIterator> make_iterator_writer(OutputIterator it);
  79. template<class T, class OutputIterator>
  80. iterator_writer<OutputIterator,T> make_iterator_writer_for(OutputIterator it);
  81. ]]></code-block>
  82. <p>Output iterator writer. Can be created using constructor or one of
  83. <tt>make_...</tt> functions.</p>
  84. </chapter>
  85. <chapter xml:id="string_writer">
  86. <title><tt>string_writer</tt></title>
  87. <code-block lang="C++"><![CDATA[
  88. #include<__vic/writers/string.h>
  89. template<
  90. class charT,
  91. class Tr = std::char_traits<charT>,
  92. class Al = std::allocator<charT>
  93. >
  94. class basic_string_writer
  95. {
  96. public:
  97. explicit basic_string_writer(std::basic_string<charT,Tr,Al> &s);
  98. void write(charT ch);
  99. };
  100. using string_writer = basic_string_writer<char>;
  101. template<class charT, class Tr, class Al>
  102. basic_string_writer<charT,Tr,Al>
  103. make_string_writer(std::basic_string<charT,Tr,Al> &s);
  104. ]]></code-block>
  105. <p>An adapter for <tt>std::basic_string</tt>. Can be created using constructor
  106. or <tt>make_...</tt> function.</p>
  107. </chapter>
  108. <chapter xml:id="cstream_writer">
  109. <title><tt>cstream_writer</tt></title>
  110. <code-block lang="C++"><![CDATA[
  111. #include<__vic/writers/cstream.h>
  112. class cstream_writer
  113. {
  114. public:
  115. explicit cstream_writer(std::FILE *fp);
  116. void write(char ch) { __vic::write(fp, ch); }
  117. };
  118. cstream_writer make_cstream_writer(std::FILE *fp);
  119. ]]></code-block>
  120. <p>Models <tt>Writer&lt;char></tt> for <tt>std::FILE</tt>. Can be created using
  121. constructor or <tt>make_...</tt> function.</p>
  122. </chapter>
  123. </chapter>