buffer_concepts.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright Daniel Trebbien 2010.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or the copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_GRAPH_BUFFER_CONCEPTS_HPP
  6. #define BOOST_GRAPH_BUFFER_CONCEPTS_HPP 1
  7. #include <boost/concept_check.hpp>
  8. #include <boost/property_map/property_map.hpp>
  9. #include <boost/typeof/typeof.hpp>
  10. #include <boost/type_traits/add_const.hpp>
  11. #include <boost/type_traits/add_reference.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. #include <boost/concept/detail/concept_def.hpp>
  14. namespace boost {
  15. BOOST_concept(Buffer, (B))
  16. {
  17. typedef typename B::value_type value_type;
  18. typedef typename B::size_type size_type;
  19. BOOST_CONCEPT_USAGE(Buffer) {
  20. typedef typename boost::add_reference<value_type>::type reference;
  21. BOOST_CONCEPT_ASSERT((Assignable<value_type>));
  22. buf.push(g_ct);
  23. buf.pop();
  24. reference t = buf.top();
  25. boost::ignore_unused_variable_warning(t);
  26. }
  27. void const_constraints(const B& cbuf) {
  28. typedef typename boost::add_const<typename boost::remove_reference<value_type>::type>::type& const_reference;
  29. const_reference ct = cbuf.top();
  30. s = cbuf.size();
  31. if (cbuf.empty())
  32. dummy = __LINE__;
  33. }
  34. int dummy;
  35. static const value_type g_ct;
  36. size_type s;
  37. B buf;
  38. };
  39. BOOST_concept(UpdatableQueue, (Q))
  40. : Buffer<Q>
  41. {
  42. BOOST_CONCEPT_USAGE(UpdatableQueue) {
  43. q.update(g_ct);
  44. }
  45. void const_constraints(const Q& cq) {
  46. if (cq.contains(g_ct))
  47. dummy = __LINE__;
  48. }
  49. int dummy;
  50. static const typename Buffer<Q>::value_type g_ct;
  51. Q q;
  52. };
  53. BOOST_concept(KeyedUpdatableQueue, (Q))
  54. : UpdatableQueue<Q>
  55. {
  56. typedef typename Q::key_type key_type;
  57. typedef typename Q::key_map key_map;
  58. BOOST_CONCEPT_USAGE(KeyedUpdatableQueue) {
  59. BOOST_CONCEPT_ASSERT((boost::ReadWritePropertyMapConcept<key_map, typename Buffer<Q>::value_type>));
  60. }
  61. void const_constraints(const Q& cq) {
  62. km = cq.keys();
  63. k = get(km, g_ct);
  64. }
  65. static const typename Buffer<Q>::value_type g_ct;
  66. key_type k;
  67. key_map km;
  68. Q q;
  69. };
  70. } // end `namespace boost`
  71. #include <boost/concept/detail/concept_undef.hpp>
  72. #endif // !BOOST_GRAPH_BUFFER_CONCEPTS_HPP