cwidget 0.5.18
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
22namespace 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
84
97 template<typename T>
98 slotarg<T> arg(const T &slot)
99 {
100 return slotarg<T>(slot);
101 }
102 }
103}
104
105#endif
Wraps a slot that may not be present.
Definition: slotarg.h:37
slotarg(const T *slot)
Create a slotarg from an optional slot.
Definition: slotarg.h:45
T & operator*()
Return the encapsulated slot, if any.
Definition: slotarg.h:77
slotarg(const T &slot)
Create a slotarg from an existing slot.
Definition: slotarg.h:57
const T & operator*() const
Return the encapsulated slot, if any.
Definition: slotarg.h:75
slotarg< T > arg(const T &slot)
Convenience routine to construct a slotarg.
Definition: slotarg.h:98
slotarg< sigc::slot0< void > > slot0arg
Convenience typedefs for slot arguments that take no parameters and return nothing.
Definition: slotarg.h:83
The namespace containing everything defined by cwidget.
Definition: columnify.cc:28