compat_workarounds.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // ----------------------------------------------------------------------------
  2. // compat_workarounds : general framework for non-conformance workarounds
  3. // ----------------------------------------------------------------------------
  4. // Copyright Samuel Krempp 2003. Use, modification, and distribution are
  5. // subject to the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // see http://www.boost.org/libs/format for library home page
  8. // ----------------------------------------------------------------------------
  9. // this file defines wrapper classes to hide non-conforming
  10. // std::char_traits<> and std::allocator<> traits
  11. // and Includes : config_macros.hpp (defines config macros
  12. // and compiler-specific switches)
  13. // Non-conformant Std-libs fail to supply conformant traits (std::char_traits,
  14. // std::allocator) and/or the std::string doesnt support them.
  15. // We don't want to have hundreds of #ifdef workarounds, so we define
  16. // replacement traits.
  17. // But both char_traits and allocator traits are visible in the interface,
  18. // (inside the final string type), thus we need to keep both
  19. // the replacement type (typedefed to 'compatible_type') for real use,
  20. // and the original stdlib type (typedef to 'type_for_string') for interface
  21. // visibility. This is what Compat* classes do (as well as be transparent
  22. // when good allocator and char traits are present)
  23. #ifndef BOOST_FORMAT_COMPAT_WORKAROUNDS_HPP
  24. #define BOOST_FORMAT_COMPAT_WORKAROUNDS_HPP
  25. namespace boost {
  26. namespace io {
  27. // gcc-2.95 char traits (non-conformantly named string_char_traits)
  28. // lack several functions so we extend them in a replacement class.
  29. template<class Tr>
  30. class CompatTraits;
  31. // std::allocator<Ch> in gcc-2.95 is ok, but basic_string only works
  32. // with plain 'std::alloc' still, alt_stringbuf requires a functionnal
  33. // alloc template argument, so we need a replacement allocator
  34. template<class Alloc>
  35. class CompatAlloc;
  36. } // N.S. io
  37. }// N.S. boost
  38. #include <boost/format/detail/config_macros.hpp>
  39. // sets-up macros and load compiler-specific workarounds headers.
  40. #if !defined(BOOST_FORMAT_STREAMBUF_DEFINED)
  41. // workarounds-gcc-2.95 might have defined own streambuf
  42. #include <streambuf>
  43. #endif
  44. #if !defined(BOOST_FORMAT_OSTREAM_DEFINED)
  45. // workarounds-gcc-2.95 might already have included <iostream>
  46. #include <ostream>
  47. #endif
  48. namespace boost {
  49. namespace io {
  50. // **** CompatTraits general definitions : ----------------------------
  51. template<class Tr>
  52. class CompatTraits
  53. { // general case : be transparent
  54. public:
  55. typedef Tr compatible_type;
  56. };
  57. // **** CompatAlloc general definitions : -----------------------------
  58. template<class Alloc>
  59. class CompatAlloc
  60. { // general case : be transparent
  61. public:
  62. typedef Alloc compatible_type;
  63. };
  64. } //N.S. io
  65. } // N.S. boost
  66. #endif // include guard