cwidget
0.5.16
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
cwidget
generic
util
slotarg.h
Go to the documentation of this file.
1
// slotarg.h -*-c++-*-
2
//
3
// Copyright 2000 Daniel Burrows
4
//
5
// Provides a mechanism for nicely passing in optional slots to a function.
6
// (you can pass either a reference to one or a pointer (which can be NULL))
7
//
8
// Eg: some_slot_function(slotarg, slotarg, slotarg) can be called as:
9
// some_slot_function(arg(slota), NULL, arg(slotb)) to omit the second slot.
10
17
#ifndef SLOTARG_H
18
#define SLOTARG_H
19
20
#include <sigc++/functors/slot.h>
21
22
namespace
cwidget
23
{
27
namespace
util
28
{
35
template
<
typename
T>
36
class
slotarg
37
{
38
bool
hasslot;
39
T theslot;
40
public
:
45
slotarg
(
const
T *slot)
46
{
47
if
(slot)
48
{
49
theslot=*slot;
50
hasslot=
true
;
51
}
52
else
53
hasslot=
false
;
54
}
55
57
slotarg
(
const
T &slot)
58
:hasslot(true), theslot(slot)
59
{
60
}
61
63
template
<
typename
S>
64
operator
slotarg<S>
()
const
65
{
66
if
(hasslot)
67
return
slotarg<S>
(theslot);
68
else
69
return
slotarg<S>
(NULL);
70
}
71
73
operator
bool
()
const
{
return
hasslot;}
75
const
T &
operator*
()
const
{
return
theslot;}
77
T &
operator*
() {
return
theslot;}
78
};
79
83
typedef
slotarg<sigc::slot0<void>
>
slot0arg
;
84
97
template
<
typename
T>
98
slotarg<T>
arg
(
const
T &slot)
99
{
100
return
slotarg<T>
(slot);
101
}
102
}
103
}
104
105
#endif
Generated on Tue Mar 18 2014 22:48:00 for cwidget by
1.8.1.2