Subordination
A framework for distributed programming
container_traits.hh
1 #ifndef SUBORDINATION_BASE_CONTAINER_TRAITS_HH
2 #define SUBORDINATION_BASE_CONTAINER_TRAITS_HH
3 
4 #include <stdexcept>
5 
6 namespace sbn {
7 
19  template <class Container>
21 
23  typedef Container container_type;
25  typedef typename Container::value_type value_type;
26 
27  };
28 
34  template <class Container>
35  struct vector_traits: public container_traits<Container> {
36 
39 
41  inline static void
42  push(container_type& cnt, const value_type& rhs) {
43  cnt.push_back(rhs);
44  }
45 
47  inline static value_type&
49  return cnt.front();
50  }
51 
53  inline static const value_type&
54  front(const container_type& cnt) {
55  return cnt.front();
56  }
57 
58  };
59 
64  template <class Container>
65  struct queue_traits: public container_traits<Container> {
66 
69 
71  inline static void
72  push(container_type& cnt, const value_type& rhs) {
73  cnt.push(rhs);
74  }
75 
77  inline static value_type&
79  return cnt.front();
80  }
81 
83  inline static const value_type&
84  front(const container_type& cnt) {
85  return cnt.front();
86  }
87 
89  inline static void
91  cnt.pop();
92  }
93 
94  };
95 
100  template <class Container>
101  struct priority_queue_traits: public container_traits<Container> {
102 
105 
107  inline static void
108  push(container_type& cnt, const value_type& rhs) {
109  cnt.push(rhs);
110  }
111 
113  inline static const value_type&
114  front(const container_type& cnt) {
115  return cnt.top();
116  }
117 
119  inline static void
121  cnt.pop();
122  }
123 
124  };
125 
130  template <class Container>
131  struct deque_traits: public container_traits<Container> {
132 
135 
137  inline static void
138  push(container_type& cnt, const value_type& rhs) {
139  cnt.push_back(rhs);
140  }
141 
143  inline static value_type&
145  return cnt.front();
146  }
147 
149  inline static const value_type&
150  front(const container_type& cnt) {
151  return cnt.front();
152  }
153 
155  inline static void
157  cnt.pop_front();
158  }
159 
160  };
161 
162 }
163 
164 #endif // vim:filetype=cpp
static const value_type & front(const container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:114
static void pop(container_type &cnt)
Removes the first element in the container.
Definition: container_traits.hh:120
static void push(container_type &cnt, const value_type &rhs)
Push element to the container.
Definition: container_traits.hh:138
Container traits for queue-like containers.
Definition: container_traits.hh:65
Container container_type
Container type.
Definition: container_traits.hh:23
Container traits for vector-like containers.Method pop is not supported.
Definition: container_traits.hh:35
static const value_type & front(const container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:84
static void push(container_type &cnt, const value_type &rhs)
Push element to the container.
Definition: container_traits.hh:72
Container traits for priority queue container.
Definition: container_traits.hh:101
Container trais.
Definition: container_traits.hh:20
static void push(container_type &cnt, const value_type &rhs)
Push element to the container.
Definition: container_traits.hh:108
static value_type & front(container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:78
static const value_type & front(const container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:150
Container::value_type value_type
Container value type.
Definition: container_traits.hh:25
static void pop(container_type &cnt)
Removes the first element in the container.
Definition: container_traits.hh:156
static const value_type & front(const container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:54
static value_type & front(container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:144
Container traits for deque container.
Definition: container_traits.hh:131
static void pop(container_type &cnt)
Removes the first element in the container.
Definition: container_traits.hh:90
static value_type & front(container_type &cnt)
Returns the first element in the container.
Definition: container_traits.hh:48
static void push(container_type &cnt, const value_type &rhs)
Push element to the container.
Definition: container_traits.hh:42