concepts.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // See http://www.boost.org/libs/iostreams for documentation.
  6. #ifndef BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED
  8. #if defined(_MSC_VER)
  9. # pragma once
  10. #endif
  11. #include <boost/config.hpp> // BOOST_MSVC
  12. #include <boost/detail/workaround.hpp>
  13. #include <boost/iostreams/categories.hpp>
  14. #include <boost/iostreams/detail/default_arg.hpp>
  15. #include <boost/iostreams/detail/ios.hpp> // openmode.
  16. #include <boost/iostreams/positioning.hpp>
  17. #include <boost/static_assert.hpp>
  18. #include <boost/type_traits/is_convertible.hpp>
  19. namespace boost { namespace iostreams {
  20. //--------------Definitions of helper templates for device concepts-----------//
  21. template<typename Mode, typename Ch = char>
  22. struct device {
  23. typedef Ch char_type;
  24. struct category
  25. : Mode,
  26. device_tag,
  27. closable_tag,
  28. localizable_tag
  29. { };
  30. void close()
  31. {
  32. using namespace detail;
  33. BOOST_STATIC_ASSERT((!is_convertible<Mode, two_sequence>::value));
  34. }
  35. void close(BOOST_IOS::openmode)
  36. {
  37. using namespace detail;
  38. BOOST_STATIC_ASSERT((is_convertible<Mode, two_sequence>::value));
  39. }
  40. template<typename Locale>
  41. void imbue(const Locale&) { }
  42. };
  43. template<typename Mode, typename Ch = wchar_t>
  44. struct wdevice : device<Mode, Ch> { };
  45. typedef device<input> source;
  46. typedef wdevice<input> wsource;
  47. typedef device<output> sink;
  48. typedef wdevice<output> wsink;
  49. //--------------Definitions of helper templates for simple filter concepts----//
  50. template<typename Mode, typename Ch = char>
  51. struct filter {
  52. typedef Ch char_type;
  53. struct category
  54. : Mode,
  55. filter_tag,
  56. closable_tag,
  57. localizable_tag
  58. { };
  59. template<typename Device>
  60. void close(Device&)
  61. {
  62. using namespace detail;
  63. BOOST_STATIC_ASSERT((!is_convertible<Mode, two_sequence>::value));
  64. BOOST_STATIC_ASSERT((!is_convertible<Mode, dual_use>::value));
  65. }
  66. template<typename Device>
  67. void close(Device&, BOOST_IOS::openmode)
  68. {
  69. using namespace detail;
  70. BOOST_STATIC_ASSERT(
  71. (is_convertible<Mode, two_sequence>::value) ||
  72. (is_convertible<Mode, dual_use>::value)
  73. );
  74. }
  75. template<typename Locale>
  76. void imbue(const Locale&) { }
  77. };
  78. template<typename Mode, typename Ch = wchar_t>
  79. struct wfilter : filter<Mode, Ch> { };
  80. typedef filter<input> input_filter;
  81. typedef wfilter<input> input_wfilter;
  82. typedef filter<output> output_filter;
  83. typedef wfilter<output> output_wfilter;
  84. typedef filter<seekable> seekable_filter;
  85. typedef wfilter<seekable> seekable_wfilter;
  86. typedef filter<dual_use> dual_use_filter;
  87. typedef wfilter<dual_use> dual_use_wfilter;
  88. //------Definitions of helper templates for multi-character filter cncepts----//
  89. template<typename Mode, typename Ch = char>
  90. struct multichar_filter : filter<Mode, Ch> {
  91. struct category : filter<Mode, Ch>::category, multichar_tag { };
  92. };
  93. template<typename Mode, typename Ch = wchar_t>
  94. struct multichar_wfilter : multichar_filter<Mode, Ch> { };
  95. typedef multichar_filter<input> multichar_input_filter;
  96. typedef multichar_wfilter<input> multichar_input_wfilter;
  97. typedef multichar_filter<output> multichar_output_filter;
  98. typedef multichar_wfilter<output> multichar_output_wfilter;
  99. typedef multichar_filter<dual_use> multichar_dual_use_filter;
  100. typedef multichar_wfilter<dual_use> multichar_dual_use_wfilter;
  101. //----------------------------------------------------------------------------//
  102. } } // End namespaces iostreams, boost.
  103. #endif // #ifndef BOOST_IOSTREAMS_CONCEPTS_HPP_INCLUDED