BVB Source Codes

mars Show write.hpp Source code

Return Download mars: download write.hpp Source code - Download mars Source code - Type:.hpp
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2005-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5.  
  6. // See http://www.boost.org/libs/iostreams for documentation.
  7.  
  8. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams {
  9.  
  10. namespace detail {
  11.  
  12. template<typename T>
  13. struct write_device_impl;
  14.  
  15. template<typename T>
  16. struct write_filter_impl;
  17.  
  18. } // End namespace detail.
  19.  
  20. template<typename T>
  21. bool put(T& t, typename char_type_of<T>::type c)
  22. {
  23.     typedef typename detail::unwrapped_type<T>::type unwrapped;
  24.     return detail::write_device_impl<T>::inner<unwrapped>::put(detail::unwrap(t), c);
  25. }
  26.  
  27. template<typename T>
  28. inline std::streamsize write
  29.     (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
  30. {
  31.     typedef typename detail::unwrapped_type<T>::type unwrapped;
  32.     return detail::write_device_impl<T>::inner<unwrapped>::write(detail::unwrap(t), s, n);
  33. }
  34.  
  35. template<typename T, typename Sink>
  36. inline std::streamsize
  37. write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
  38.        std::streamsize n )
  39. {
  40.     typedef typename detail::unwrapped_type<T>::type unwrapped;
  41.     return detail::write_filter_impl<T>::inner<unwrapped>::write(detail::unwrap(t), snk, s, n);
  42. }
  43.  
  44. namespace detail {
  45.  
  46. //------------------Definition of write_device_impl---------------------------//
  47.  
  48. template<typename T>
  49. struct write_device_impl
  50.     : mpl::if_<
  51.           is_custom<T>,
  52.           operations<T>,
  53.           write_device_impl<
  54.               BOOST_DEDUCED_TYPENAME
  55.               dispatch<
  56.                   T, ostream_tag, streambuf_tag, output
  57.               >::type
  58.           >
  59.       >::type
  60.     { };
  61.  
  62. template<>
  63. struct write_device_impl<ostream_tag> {
  64.     template<typename T>
  65.     struct inner {
  66.         static bool put(T& t, typename char_type_of<T>::type c)
  67.         {
  68.             typedef typename char_type_of<T>::type          char_type;
  69.             typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type)  traits_type;
  70.             return !traits_type::eq_int_type( t.rdbuf()->s.sputc(),
  71.                                             traits_type::eof() );
  72.         }
  73.  
  74.         static std::streamsize write
  75.             (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
  76.         { return t.rdbuf()->sputn(s, n); }
  77.     };
  78. };
  79.  
  80. template<>
  81. struct write_device_impl<streambuf_tag> {
  82.     template<typename T>
  83.     struct inner {
  84.         static bool put(T& t, typename char_type_of<T>::type c)
  85.         {
  86.             typedef typename char_type_of<T>::type          char_type;
  87.             typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type)  traits_type;
  88.             return !traits_type::eq_int_type(t.sputc(c), traits_type::eof());
  89.         }
  90.  
  91.         template<typename T>
  92.         static std::streamsize write
  93.             (T& t, const typename char_type_of<T>::type* s, std::streamsize n)
  94.         { return t.sputn(s, n); }
  95.     };
  96. };
  97.  
  98. template<>
  99. struct write_device_impl<output> {
  100.     template<typename T>
  101.     struct inner {
  102.         static bool put(T& t, typename char_type_of<T>::type c)
  103.         { return t.write(&c, 1) == 1; }
  104.  
  105.         template<typename T>
  106.         static std::streamsize
  107.         write(T& t, const typename char_type_of<T>::type* s, std::streamsize n)
  108.         { return t.write(s, n); }
  109.     };
  110. };
  111.  
  112. //------------------Definition of write_filter_impl---------------------------//
  113.  
  114. template<typename T>
  115. struct write_filter_impl
  116.     : mpl::if_<
  117.           is_custom<T>,
  118.           operations<T>,
  119.           write_filter_impl<
  120.               BOOST_DEDUCED_TYPENAME
  121.               dispatch<
  122.                   T, multichar_tag, any_tag
  123.               >::type
  124.           >
  125.       >::type
  126.     { };
  127.  
  128. template<>
  129. struct write_filter_impl<multichar_tag> {
  130.     template<typename T>
  131.     struct inner {
  132.         template<typename Sink>
  133.         static std::streamsize
  134.         write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
  135.                std::streamsize n )
  136.         { return t.write(snk, s, n); }
  137.     };
  138. };
  139.  
  140. template<>
  141. struct write_filter_impl<any_tag> {
  142.     template<typename T>
  143.     struct inner {
  144.         template<typename Sink>
  145.         static std::streamsize
  146.         write( T& t, Sink& snk, const typename char_type_of<T>::type* s,
  147.                std::streamsize n )
  148.         {
  149.             for (std::streamsize off = 0; off < n; ++off)
  150.                 if (!t.put(snk, s[off]))
  151.                     return off;
  152.             return n;
  153.         }
  154.     };
  155. };
  156.  
  157. } // End namespace detail.
  158.  
  159. } } // End namespaces iostreams, boost.
  160.  
downloadwrite.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top