blob: f2098cba6cf432f7e4eb083766fa7e860e9bcb01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
// Copyright (C) 2005 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_REMOVER_KERNEl_INTERFACE_
#define DLIB_REMOVER_KERNEl_INTERFACE_
#include <functional>
namespace dlib
{
template <
typename T
>
class remover
{
/*!
REQUIREMENTS ON T
T is swappable by a global swap() and
T must have a default constructor
POINTERS AND REFERENCES TO INTERNAL DATA
The size() function does not invalidate pointers or
references to internal data. All other functions have no such
guarantee.
WHAT THIS OBJECT REPRESENTS
This object represents some generalized interface for removing
single items from container classes.
!*/
public:
typedef T type;
virtual ~remover(
);
/*!
ensures
- all resources associated with *this have been released.
!*/
virtual void remove_any (
T& item
) = 0;
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- removes an element from *this and swaps it into item.
- if (*this implements the enumerable interface) then
- #at_start() == true
!*/
virtual size_t size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
remover& operator=(const remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename T,
typename compare
>
class asc_remover : public remover<T>
{
/*!
REQUIREMENTS ON T
T is swappable by a global swap() and
T must have a default constructor and
T must be comparable by compare where compare is a functor compatible with std::less
WHAT THIS OBJECT REPRESENTS
This object represents the same thing as remover except
that remove_any() will remove elements in ascending order
according to the compare functor.
!*/
public:
typedef compare compare_type;
protected:
// restricted functions
asc_remover& operator=(const asc_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range
>
class pair_remover
{
/*!
REQUIREMENTS ON domain
domain is swappable by a global swap() and
domain must have a default constructor
REQUIREMENTS ON range
range is swappable by a global swap() and
range must have a default constructor
POINTERS AND REFERENCES TO INTERNAL DATA
The size() function does not invalidate pointers or
references to internal data. All other functions have no such
guarantee.
WHAT THIS OBJECT REPRESENTS
This object represents some generalized interface for removing
pairs from container classes which enforce some kind of pairing on
the elements that they contain.
!*/
public:
typedef domain domain_type;
typedef range range_type;
virtual ~pair_remover(
);
/*!
ensures
- all resources associated with *this have been released.
!*/
virtual void remove_any (
domain& d,
range& r
) = 0;
/*!
requires
- &d != &r (i.e. d and r cannot be the same variable)
- size() != 0
ensures
- #size() == size() - 1
- removes an element from the domain of *this and swaps it
into d.
- removes the element in *this's range that is associated
with #d and swaps it into r.
- if (*this implements the enumerable interface) then
- #at_start() == true
!*/
virtual size_t size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
pair_remover& operator=(const pair_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename compare
>
class asc_pair_remover : public pair_remover<domain,range>
{
/*!
REQUIREMENTS ON domain
domain is swappable by a global swap() and
domain must have a default constructor and
domain must be comparable by compare where compare is a functor compatible with std::less
REQUIREMENTS ON range
range is swappable by a global swap() and
range must have a default constructor
WHAT THIS OBJECT REPRESENTS
This object represents the same thing as pair_remover except
that remove_any() will remove domain elements in ascending
order according to the compare functor.
!*/
public:
typedef compare compare_type;
protected:
// restricted functions
asc_pair_remover& operator=(const asc_pair_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
// destructor does nothing
template <typename T>
remover<T>::~remover() {}
// destructor does nothing
template <typename domain, typename range>
pair_remover<domain,range>::~pair_remover() {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_REMOVER_KERNEl_INTERFACE_
|