123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <chapter xml:id="writers">
- <title><tt>__vic/writers/</tt></title>
- <chapter xml:id="writer-concept">
- <title><tt>Writer</tt> concept</title>
- <code-block lang="C++"><![CDATA[
- template<class ElementT>
- class ]]><nt>Writer</nt><![CDATA[
- {
- public:
- Writer(Writer &&o); or Writer(const Writer &o);
- void write(ElementT v); // throws on errors
- };
- ]]></code-block>
- <p>A concept used by the library algorithms to write logical sequence of elements
- of type <tt>ElementT</tt> element by element. It is a generalization and rework
- of the <tt>OutputIterator</tt> concept. In particular it handles streams
- and other output sequences where <tt>end</tt>-iterator is meaningless or
- expensive to obtain better. At the same time, a traditional output iterators
- are just a particular case and fully and well handled by
- <tt>__vic::iterator_writer</tt> adapter.</p>
- <p>When the particular class meets the requirements of this concept for some
- <tt>ElementT = T</tt> it is said <b>to model</b> the <tt>Writer<T></tt>
- concept.</p>
- <p>Each instance of the class has to be move- or copy-constructible.</p>
- <section><title>Class members</title>
- <synopsis>
- <prototype>void write(ElementT v)</prototype>
- <p>Writes the element or throws an exception on error.</p>
- </synopsis>
- </section>
- </chapter>
- <chapter xml:id="null_writer">
- <title><tt>null_writer</tt></title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/writers/null.h>
- class null_writer
- {
- public:
- template<class T> void write(T v) {}
- };
- null_writer make_null_writer();
- ]]></code-block>
- <p>Fake writer that accepts any value and does nothing with it (like UNIX
- <tt>/dev/null</tt>).</p>
- </chapter>
- <chapter xml:id="push_back_writer">
- <title><tt>push_back_writer</tt></title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/writers/push_back.h>
- template<class Cont, class T = typename Cont::value_type>
- class push_back_writer
- {
- public:
- explicit push_back_writer(Cont &c);
- void write(T v) { c->push_back(v); }
- };
- template<class Cont>
- push_back_writer<Cont> make_push_back_writer(Cont &c);
- template<class T, class Cont>
- push_back_writer<Cont,T> make_push_back_writer_for(Cont &c);
- ]]></code-block>
- <p>An adapter. Uses <tt>push_back()</tt> member function to write elements.
- Can be created using constructor or one of <tt>make_...</tt> functions.</p>
- </chapter>
- <chapter xml:id="iterator_writer">
- <title><tt>iterator_writer</tt></title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/writers/iterator.h>
- template<class OutputIterator,
- class T = typename std::iterator_traits<OutputIterator>::value_type>
- class iterator_writer
- {
- public:
- explicit iterator_writer(OutputIterator it);
- void write(T v);
- };
- template<class OutputIterator>
- iterator_writer<OutputIterator> make_iterator_writer(OutputIterator it);
- template<class T, class OutputIterator>
- iterator_writer<OutputIterator,T> make_iterator_writer_for(OutputIterator it);
- ]]></code-block>
- <p>Output iterator writer. Can be created using constructor or one of
- <tt>make_...</tt> functions.</p>
- </chapter>
- <chapter xml:id="string_writer">
- <title><tt>string_writer</tt></title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/writers/string.h>
- template<
- class charT,
- class Tr = std::char_traits<charT>,
- class Al = std::allocator<charT>
- >
- class basic_string_writer
- {
- public:
- explicit basic_string_writer(std::basic_string<charT,Tr,Al> &s);
- void write(charT ch);
- };
- using string_writer = basic_string_writer<char>;
- template<class charT, class Tr, class Al>
- basic_string_writer<charT,Tr,Al>
- make_string_writer(std::basic_string<charT,Tr,Al> &s);
- ]]></code-block>
- <p>An adapter for <tt>std::basic_string</tt>. Can be created using constructor
- or <tt>make_...</tt> function.</p>
- </chapter>
- <chapter xml:id="cstream_writer">
- <title><tt>cstream_writer</tt></title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/writers/cstream.h>
- class cstream_writer
- {
- public:
- explicit cstream_writer(std::FILE *fp);
- void write(char ch) { __vic::write(fp, ch); }
- };
- cstream_writer make_cstream_writer(std::FILE *fp);
- ]]></code-block>
- <p>Models <tt>Writer<char></tt> for <tt>std::FILE</tt>. Can be created using
- constructor or <tt>make_...</tt> function.</p>
- </chapter>
- </chapter>
|