File: member_function_pointer_kernel_abstract.h

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (483 lines) | stat: -rw-r--r-- 12,121 bytes parent folder | download | duplicates (14)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// Copyright (C) 2005  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_MEMBER_FUNCTION_POINTER_KERNEl_ABSTRACT_
#ifdef DLIB_MEMBER_FUNCTION_POINTER_KERNEl_ABSTRACT_

namespace dlib
{

// ----------------------------------------------------------------------------------------

    template <
        typename PARAM1 = void,
        typename PARAM2 = void,
        typename PARAM3 = void,
        typename PARAM4 = void
        >
    class member_function_pointer;

// ----------------------------------------------------------------------------------------

    template <>
    class member_function_pointer<void,void,void,void>
    {
        /*!
            INITIAL VALUE
                is_set() == false

            WHAT THIS OBJECT REPRESENTS
                This object represents a member function pointer.  It is useful because
                instances of this object can be created without needing to know the type
                of object whose member function we will be calling.

                There are five template specializations of this object.  The first 
                represents a pointer to a member function taking no parameters, the
                second represents a pointer to a member function taking one parameter, 
                the third to one taking two parameters, and so on.

                You specify the parameters to your member function pointer by filling in
                the PARAM template parameters.  For example:

                    To use a pointer to a function with no parameters you would say:
                        member_function_pointer<> my_pointer;
                    To use a pointer to a function that takes a single int you would say:
                        member_function_pointer<int> my_pointer;
                    To use a pointer to a function that takes an int and then a reference
                    to a string you would say:
                        member_function_pointer<int,string&> my_pointer;

                Also note that the formal comments are only present for the first 
                template specialization.  They are all exactly the same except for the 
                number of parameters each takes in its member function pointer.
        !*/

    public:
        typedef void param1_type;
        typedef void param2_type;
        typedef void param3_type;
        typedef void param4_type;

        member_function_pointer (  
        );
        /*!
            ensures                
                - #*this is properly initialized
        !*/

        member_function_pointer(
            const member_function_pointer& item
        );
        /*!
            ensures
                - *this == item
        !*/

        ~member_function_pointer (
        );
        /*!
            ensures
                - any resources associated with *this have been released
        !*/

        member_function_pointer& operator=(
            const member_function_pointer& item
        );
        /*!
            ensures
                - *this == item
        !*/

        bool operator == (
            const member_function_pointer& item
        ) const;
        /*!
            ensures
                - if (is_set() == false && item.is_set() == false) then
                    - returns true
                - else if (both *this and item point to the same member function
                  in the same object instance) then
                    - returns true
                - else
                    - returns false
        !*/

        bool operator != (
            const member_function_pointer& item
        ) const;
        /*!
            ensures
                - returns !(*this == item)
        !*/

        void clear(
        );
        /*!
            ensures
                - #*this has its initial value
        !*/

        bool is_set (
        ) const;
        /*!
            ensures
                - if (this->set() has been called) then
                    - returns true
                - else
                    - returns false
        !*/

        template <
            typename T
            >
        void set (
            T& object,
            void (T::*cb)()
        );
        /*!
            requires
                - cb == a valid member function pointer for class T
            ensures
                - #is_set() == true
                - calls to this->operator() will call (object.*cb)()
        !*/

        template <
            typename T
            >
        void set (
            const T& object,
            void (T::*cb)()const
        );
        /*!
            requires
                - cb == a valid member function pointer for class T
            ensures
                - #is_set() == true
                - calls to this->operator() will call (object.*cb)()
        !*/

        operator some_undefined_pointer_type (
        ) const;
        /*!
            ensures
                - if (is_set()) then
                    - returns a non 0 value
                - else
                    - returns a 0 value
        !*/

        bool operator! (
        ) const;
        /*!
            ensures
                - returns !is_set()
        !*/

        void operator () (
        ) const;
        /*!
            requires
                - is_set() == true
            ensures
                - calls the member function on the object specified by the last 
                  call to this->set()
            throws
                - any exception thrown by the member function specified by
                  the previous call to this->set().
                    If any of these exceptions are thrown then the call to this 
                    function will have no effect on *this.                  
        !*/

        void swap (
            member_function_pointer& item
        );
        /*!
            ensures
                - swaps *this and item
        !*/ 

    };    

// ----------------------------------------------------------------------------------------

    template <
        typename PARAM1
        >
    class member_function_pointer<PARAM1,void,void,void>
    {
    public:
        typedef PARAM1 param1_type;
        typedef void param2_type;
        typedef void param3_type;
        typedef void param4_type;

        member_function_pointer ();

        member_function_pointer(
            const member_function_pointer& item
        );

        ~member_function_pointer (
        );

        member_function_pointer& operator=(
            const member_function_pointer& item
        );

        bool operator == (
            const member_function_pointer& item
        ) const;

        bool operator != (
            const member_function_pointer& item
        ) const;

        void clear();

        bool is_set () const;

        template <typename T>
        void set (
            T& object,
            void (T::*cb)(PARAM1)
        );

        template <typename T>
        void set (
            const T& object,
            void (T::*cb)(PARAM1)const
        );

        operator some_undefined_pointer_type (
        ) const;

        bool operator! (
        ) const;

        void operator () (
            PARAM1 param1
        ) const;

        void swap (
            member_function_pointer& item
        );

    };    

// ----------------------------------------------------------------------------------------

    template <
        typename PARAM1,
        typename PARAM2
        >
    class member_function_pointer<PARAM1,PARAM2,void,void>
    {
    public:
        typedef PARAM1 param1_type;
        typedef PARAM2 param2_type;
        typedef void param3_type;
        typedef void param4_type;

        member_function_pointer ();

        member_function_pointer(
            const member_function_pointer& item
        );

        ~member_function_pointer (
        );

        member_function_pointer& operator=(
            const member_function_pointer& item
        );

        bool operator == (
            const member_function_pointer& item
        ) const;

        bool operator != (
            const member_function_pointer& item
        ) const;

        void clear();

        bool is_set () const;

        template <typename T>
        void set (
            T& object,
            void (T::*cb)(PARAM1,PARAM2)
        );

        template <typename T>
        void set (
            const T& object,
            void (T::*cb)(PARAM1,PARAM2)const
        );

        operator some_undefined_pointer_type (
        ) const;

        bool operator! (
        ) const;

        void operator () (
            PARAM1 param1,
            PARAM2 param2
        ) const;

        void swap (
            member_function_pointer& item
        );

    };    

// ----------------------------------------------------------------------------------------

    template <
        typename PARAM1,
        typename PARAM2,
        typename PARAM3
        >
    class member_function_pointer<PARAM1,PARAM2,PARAM3,void>
    {
    public:
        typedef PARAM1 param1_type;
        typedef PARAM2 param2_type;
        typedef PARAM3 param3_type;
        typedef void param4_type;

        member_function_pointer ();

        member_function_pointer(
            const member_function_pointer& item
        );

        ~member_function_pointer (
        );

        member_function_pointer& operator=(
            const member_function_pointer& item
        );

        bool operator == (
            const member_function_pointer& item
        ) const;

        bool operator != (
            const member_function_pointer& item
        ) const;

        void clear();

        bool is_set () const;

        template <typename T>
        void set (
            T& object,
            void (T::*cb)(PARAM1,PARAM2,PARAM3)
        );

        template <typename T>
        void set (
            const T& object,
            void (T::*cb)(PARAM1,PARAM2,PARAM3)const
        );

        operator some_undefined_pointer_type (
        ) const;

        bool operator! (
        ) const;

        void operator () (
            PARAM1 param1,
            PARAM2 param2,
            PARAM2 param3
        ) const;

        void swap (
            member_function_pointer& item
        );

    };    

// ----------------------------------------------------------------------------------------

    template <
        typename PARAM1,
        typename PARAM2,
        typename PARAM3,
        typename PARAM4
        >
    class member_function_pointer
    {
    public:
        typedef PARAM1 param1_type;
        typedef PARAM2 param2_type;
        typedef PARAM3 param3_type;
        typedef PARAM4 param4_type;

        member_function_pointer ();

        member_function_pointer(
            const member_function_pointer& item
        );

        ~member_function_pointer (
        );

        member_function_pointer& operator=(
            const member_function_pointer& item
        );

        bool operator == (
            const member_function_pointer& item
        ) const;

        bool operator != (
            const member_function_pointer& item
        ) const;

        void clear();

        bool is_set () const;

        template <typename T>
        void set (
            T& object,
            void (T::*cb)(PARAM1,PARAM2,PARAM3,PARAM4)
        );

        template <typename T>
        void set (
            const T& object,
            void (T::*cb)(PARAM1,PARAM2,PARAM3,PARAM4)const
        );

        operator some_undefined_pointer_type (
        ) const;

        bool operator! (
        ) const;

        void operator () (
            PARAM1 param1,
            PARAM2 param2,
            PARAM2 param3,
            PARAM2 param4
        ) const;

        void swap (
            member_function_pointer& item
        );

    };    

// ----------------------------------------------------------------------------------------


}

#endif // DLIB_MEMBER_FUNCTION_POINTER_KERNEl_ABSTRACT_