BVB Source Codes

mars Show close.hpp Source code

Return Download mars: download close.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 close_impl;
  14.  
  15. } // End namespace detail.
  16.  
  17. template<typename T>
  18. void close(T& t) { detail::close_all(t); }
  19.  
  20. template<typename T>
  21. void close(T& t, BOOST_IOS::openmode which)
  22. {
  23.     typedef typename detail::unwrapped_type<T>::type unwrapped;
  24.     detail::close_impl<T>::inner<unwrapped>::close(detail::unwrap(t), which);
  25. }
  26.  
  27. template<typename T, typename Sink>
  28. void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  29. {
  30.     typedef typename detail::unwrapped_type<T>::type unwrapped;
  31.     detail::close_impl<T>::inner<unwrapped>::close(detail::unwrap(t), snk, which);
  32. }
  33.  
  34. namespace detail {
  35.  
  36. //------------------Definition of close_impl----------------------------------//
  37.  
  38. template<typename T>
  39. struct close_tag {
  40.     typedef typename category_of<T>::type category;
  41.     typedef typename
  42.             mpl::eval_if<
  43.                 is_convertible<category, closable_tag>,
  44.                 mpl::if_<
  45.                     mpl::or_<
  46.                         is_convertible<category, two_sequence>,
  47.                         is_convertible<category, dual_use>
  48.                     >,
  49.                     two_sequence,
  50.                     closable_tag
  51.                 >,
  52.                 mpl::identity<any_tag>
  53.             >::type type;
  54. };
  55.  
  56. template<typename T>
  57. struct close_impl
  58.     : mpl::if_<
  59.           is_custom<T>,
  60.           operations<T>,
  61.           close_impl<BOOST_DEDUCED_TYPENAME close_tag<T>::type>
  62.       >::type
  63.     { };
  64.  
  65. template<>
  66. struct close_impl<any_tag> {
  67.     template<typename T>
  68.     struct inner {
  69.         static void close(T& t, BOOST_IOS::openmode which)
  70.         {
  71.             if (which == BOOST_IOS::out)
  72.                 iostreams::flush(t);
  73.         }
  74.  
  75.         template<typename Sink>
  76.         static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  77.         {
  78.             if (which == BOOST_IOS::out) {
  79.                 non_blocking_adapter<Sink> nb(snk);
  80.                 iostreams::flush(t, nb);
  81.             }
  82.         }
  83.     };
  84. };
  85.  
  86. template<>
  87. struct close_impl<closable_tag> {
  88.     template<typename T>
  89.     struct inner {
  90.         static void close(T& t, BOOST_IOS::openmode which)
  91.         {
  92.             typedef typename category_of<T>::type category;
  93.             const bool in =  is_convertible<category, input>::value &&
  94.                             !is_convertible<category, output>::value;
  95.             if (in == (which == BOOST_IOS::in))
  96.                 t.close();
  97.         }
  98.         template<typename Sink>
  99.         static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  100.         {
  101.             typedef typename category_of<T>::type category;
  102.             const bool in =  is_convertible<category, input>::value &&
  103.                             !is_convertible<category, output>::value;
  104.             if (in == (which == BOOST_IOS::in)) {
  105.                 non_blocking_adapter<Sink> nb(snk);
  106.                 t.close(nb);
  107.             }
  108.         }
  109.     };
  110. };
  111.  
  112. template<>
  113. struct close_impl<two_sequence> {
  114.     template<typename T>
  115.     struct inner {
  116.         static void close(T& t, BOOST_IOS::openmode which) { t.close(which); }
  117.  
  118.         template<typename Sink>
  119.         static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  120.         {
  121.             non_blocking_adapter<Sink> nb(snk);
  122.             t.close(nb, which);
  123.         }
  124.     };
  125. };
  126.  
  127. } // End namespace detail.
  128.  
  129. } } // End namespaces iostreams, boost.
  130.  
downloadclose.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