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 
6 #ifndef BOOST_GRAPH_BUFFER_CONCEPTS_HPP
7 #define BOOST_GRAPH_BUFFER_CONCEPTS_HPP 1
8 #include <boost/concept_check.hpp>
9 #include <boost/concept/detail/concept_def.hpp>
10 #include <boost/property_map/property_map.hpp>
11 #include <boost/typeof/typeof.hpp>
12 #include <boost/type_traits/add_const.hpp>
13 #include <boost/type_traits/add_reference.hpp>
14 #include <boost/type_traits/remove_reference.hpp>
15 
16 namespace boost {
17 
18   BOOST_concept(Buffer, (B))
19   {
20     typedef typename B::value_type value_type;
21     typedef typename B::size_type size_type;
22 
BOOST_CONCEPT_USAGE(Buffer)23     BOOST_CONCEPT_USAGE(Buffer) {
24       typedef typename boost::add_reference<value_type>::type reference;
25 
26       BOOST_CONCEPT_ASSERT((Assignable<value_type>));
27 
28       buf.push(g_ct);
29       buf.pop();
30       reference t = buf.top();
31       boost::ignore_unused_variable_warning(t);
32     }
33 
const_constraints(const B & cbuf)34     void const_constraints(const B& cbuf) {
35       typedef typename boost::add_const<typename boost::remove_reference<value_type>::type>::type& const_reference;
36 
37       const_reference ct = cbuf.top();
38       s = cbuf.size();
39       if (cbuf.empty())
40         dummy = __LINE__;
41     }
42 
43     int dummy;
44 
45     static const value_type g_ct;
46     size_type s;
47     B buf;
48   };
49 
50   BOOST_concept(UpdatableQueue, (Q))
51     : Buffer<Q>
52   {
BOOST_CONCEPT_USAGE(UpdatableQueue)53     BOOST_CONCEPT_USAGE(UpdatableQueue) {
54       q.update(g_ct);
55     }
56 
const_constraints(const Q & cq)57     void const_constraints(const Q& cq) {
58       if (cq.contains(g_ct))
59         dummy = __LINE__;
60     }
61 
62     int dummy;
63 
64     static const typename Buffer<Q>::value_type g_ct;
65     Q q;
66   };
67 
68   BOOST_concept(KeyedUpdatableQueue, (Q))
69     : UpdatableQueue<Q>
70   {
71     typedef typename Q::key_type key_type;
72     typedef typename Q::key_map key_map;
73 
BOOST_CONCEPT_USAGE(KeyedUpdatableQueue)74     BOOST_CONCEPT_USAGE(KeyedUpdatableQueue) {
75       BOOST_CONCEPT_ASSERT((boost::ReadWritePropertyMapConcept<key_map, typename Buffer<Q>::value_type>));
76     }
77 
const_constraints(const Q & cq)78     void const_constraints(const Q& cq) {
79       km = cq.keys();
80       k = get(km, g_ct);
81     }
82 
83     static const typename Buffer<Q>::value_type g_ct;
84     key_type k;
85     key_map km;
86     Q q;
87   };
88 
89 } // end `namespace boost`
90 
91 #endif // !BOOST_GRAPH_BUFFER_CONCEPTS_HPP
92