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 2003-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. #ifndef BOOST_IOSTREAMS_CLOSE_HPP_INCLUDED
  9. #define BOOST_IOSTREAMS_CLOSE_HPP_INCLUDED
  10.  
  11. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  12. # pragma once
  13. #endif
  14.  
  15. #include <boost/config.hpp>  // DEDUCED_TYPENAME, MSVC.
  16. #include <boost/detail/workaround.hpp>
  17. #include <boost/iostreams/categories.hpp>
  18. #include <boost/iostreams/flush.hpp>
  19. #include <boost/iostreams/detail/adapter/non_blocking_adapter.hpp>
  20. #include <boost/iostreams/detail/ios.hpp> // BOOST_IOS
  21. #include <boost/iostreams/detail/select.hpp>
  22. #include <boost/iostreams/detail/wrap_unwrap.hpp>
  23. #include <boost/iostreams/operations_fwd.hpp>
  24. #include <boost/iostreams/traits.hpp>
  25. #include <boost/mpl/identity.hpp>
  26. #include <boost/mpl/if.hpp>
  27. #include <boost/type_traits/is_convertible.hpp>
  28. #include <boost/type_traits/is_integral.hpp>
  29. #include <boost/type_traits/remove_cv.hpp>
  30. #include <boost/type_traits/remove_reference.hpp>
  31. #include <boost/detail/no_exceptions_support.hpp>
  32.  
  33. // Must come last.
  34. #include <boost/iostreams/detail/config/disable_warnings.hpp>
  35.  
  36. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams {
  37.  
  38. template<typename T>
  39. void close(T& t);
  40.  
  41. template<typename T>
  42. void close(T& t, BOOST_IOS::openmode which);
  43.  
  44. template<typename T, typename Sink>
  45. void close(T& t, Sink& snk, BOOST_IOS::openmode which);
  46.    
  47. namespace detail {
  48.  
  49. template<typename T>
  50. void close_all(T& t)
  51. {
  52.     BOOST_TRY {
  53.         mars_boost::iostreams::close(t, BOOST_IOS::in);
  54.     } BOOST_CATCH (...) {
  55.         BOOST_TRY {
  56.             mars_boost::iostreams::close(t, BOOST_IOS::out);
  57.         } BOOST_CATCH (...) { } BOOST_CATCH_END
  58.         BOOST_RETHROW;
  59.     } BOOST_CATCH_END
  60.     mars_boost::iostreams::close(t, BOOST_IOS::out);
  61. }
  62.  
  63. template<typename T, typename Sink>
  64. void close_all(T& t, Sink& snk)
  65. {
  66.     BOOST_TRY {
  67.         mars_boost::iostreams::close(t, snk, BOOST_IOS::in);
  68.     } BOOST_CATCH (...) {
  69.         BOOST_TRY {
  70.             mars_boost::iostreams::close(t, snk, BOOST_IOS::out);
  71.         } BOOST_CATCH (...) { } BOOST_CATCH_END
  72.         BOOST_RETHROW;
  73.     } BOOST_CATCH_END
  74.     mars_boost::iostreams::close(t, snk, BOOST_IOS::out);
  75. }
  76.  
  77. } // End namespace detail.
  78.  
  79. } } // End namespaces iostreams, boost.
  80.  
  81. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-----------------------------------//
  82. # include <boost/iostreams/detail/vc6/close.hpp>
  83. #else // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //--------------------------//
  84.  
  85. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams {
  86.  
  87. namespace detail {
  88.  
  89. template<typename T>
  90. struct close_impl;
  91.  
  92. } // End namespace detail.
  93.  
  94. template<typename T>
  95. void close(T& t) { detail::close_all(t); }
  96.  
  97. template<typename T>
  98. void close(T& t, BOOST_IOS::openmode which)
  99. {
  100. #ifdef BOOST_IOSTREAMS_STRICT
  101.     BOOST_ASSERT(which == BOOST_IOS::in || which == BOOST_IOS::out);
  102. #else
  103.     if (which == (BOOST_IOS::in | BOOST_IOS::out)) {
  104.         detail::close_all(t);
  105.         return;
  106.     }
  107. #endif
  108.     detail::close_impl<T>::close(detail::unwrap(t), which);
  109. }
  110.  
  111. template<typename T, typename Sink>
  112. void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  113. {
  114. #ifdef BOOST_IOSTREAMS_STRICT
  115.     BOOST_ASSERT(which == BOOST_IOS::in || which == BOOST_IOS::out);
  116. #else
  117.     if (which == (BOOST_IOS::in | BOOST_IOS::out)) {
  118.         detail::close_all(t, snk);
  119.         return;
  120.     }
  121. #endif
  122.     detail::close_impl<T>::close(detail::unwrap(t), snk, which);
  123. }
  124.  
  125. namespace detail {
  126.  
  127. //------------------Definition of close_impl----------------------------------//
  128.  
  129. struct close_boost_stream { };
  130. struct close_filtering_stream { };
  131.  
  132. template<typename T>
  133. struct close_tag {
  134.     typedef typename category_of<T>::type             category;
  135.     typedef typename detail::unwrapped_type<T>::type  unwrapped;
  136.     typedef typename
  137.             iostreams::select<
  138.                 mpl::not_< is_convertible<category, closable_tag> >,
  139.                 any_tag,
  140.                 mpl::or_<
  141.                     is_boost_stream<unwrapped>,
  142.                     is_boost_stream_buffer<unwrapped>
  143.                 >,
  144.                 close_boost_stream,
  145.                 mpl::or_<
  146.                     is_filtering_stream<unwrapped>,
  147.                     is_filtering_streambuf<unwrapped>
  148.                 >,
  149.                 close_filtering_stream,
  150.                 mpl::or_<
  151.                     is_convertible<category, two_sequence>,
  152.                     is_convertible<category, dual_use>
  153.                 >,
  154.                 two_sequence,
  155.                 else_,
  156.                 closable_tag
  157.             >::type type;
  158. };
  159.  
  160. template<typename T>
  161. struct close_impl
  162.     : mpl::if_<
  163.           is_custom<T>,
  164.           operations<T>,
  165.           close_impl<BOOST_DEDUCED_TYPENAME close_tag<T>::type>
  166.       >::type
  167.     { };
  168.  
  169. template<>
  170. struct close_impl<any_tag> {
  171.     template<typename T>
  172.     static void close(T& t, BOOST_IOS::openmode which)
  173.     {
  174.         if (which == BOOST_IOS::out)
  175.             iostreams::flush(t);
  176.     }
  177.  
  178.     template<typename T, typename Sink>
  179.     static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  180.     {
  181.         if (which == BOOST_IOS::out) {
  182.             non_blocking_adapter<Sink> nb(snk);
  183.             iostreams::flush(t, nb);
  184.         }
  185.     }
  186. };
  187.  
  188. template<>
  189. struct close_impl<close_boost_stream> {
  190.     template<typename T>
  191.     static void close(T& t)
  192.     {
  193.         t.close();
  194.     }
  195.     template<typename T>
  196.     static void close(T& t, BOOST_IOS::openmode which)
  197.     {
  198.         if (which == BOOST_IOS::out)
  199.             t.close();
  200.     }
  201. };
  202.  
  203. template<>
  204. struct close_impl<close_filtering_stream> {
  205.     template<typename T>
  206.     static void close(T& t, BOOST_IOS::openmode which)
  207.     {
  208.         typedef typename category_of<T>::type category;
  209.         const bool in =  is_convertible<category, input>::value &&
  210.                         !is_convertible<category, output>::value;
  211.         if (in == (which == BOOST_IOS::in) && t.is_complete())
  212.             t.pop();
  213.     }
  214. };
  215.  
  216. template<>
  217. struct close_impl<closable_tag> {
  218.     template<typename T>
  219.     static void close(T& t, BOOST_IOS::openmode which)
  220.     {
  221.         typedef typename category_of<T>::type category;
  222.         const bool in =  is_convertible<category, input>::value &&
  223.                         !is_convertible<category, output>::value;
  224.         if (in == (which == BOOST_IOS::in))
  225.             t.close();
  226.     }
  227.     template<typename T, typename Sink>
  228.     static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  229.     {
  230.         typedef typename category_of<T>::type category;
  231.         const bool in =  is_convertible<category, input>::value &&
  232.                         !is_convertible<category, output>::value;
  233.         if (in == (which == BOOST_IOS::in)) {
  234.             non_blocking_adapter<Sink> nb(snk);
  235.             t.close(nb);
  236.         }
  237.     }
  238. };
  239.  
  240. template<>
  241. struct close_impl<two_sequence> {
  242.     template<typename T>
  243.     static void close(T& t, BOOST_IOS::openmode which) { t.close(which); }
  244.     template<typename T, typename Sink>
  245.     static void close(T& t, Sink& snk, BOOST_IOS::openmode which)
  246.     {
  247.         non_blocking_adapter<Sink> nb(snk);
  248.         t.close(nb, which);
  249.     }
  250. };
  251.  
  252. } // End namespace detail.
  253.  
  254. } } // End namespaces iostreams, boost.
  255.  
  256. #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-------------------------//
  257.  
  258. #include <boost/iostreams/detail/config/enable_warnings.hpp>
  259.  
  260. #endif // #ifndef BOOST_IOSTREAMS_CLOSE_HPP_INCLUDED
  261.  
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