aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Accessor.hh
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-27 21:55:24 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-27 21:55:24 (GMT)
commitb5c354b994bc06667abe35e2d528c0f025703c4e (patch)
tree081fd3207053a06cb50931ccec3237bc614f10eb /src/FbTk/Accessor.hh
parent1f5cd12facc662de240b36bf3c5c14f40adf391b (diff)
downloadfluxbox-b5c354b994bc06667abe35e2d528c0f025703c4e.zip
fluxbox-b5c354b994bc06667abe35e2d528c0f025703c4e.tar.bz2
architecture astronomy
Diffstat (limited to 'src/FbTk/Accessor.hh')
-rw-r--r--src/FbTk/Accessor.hh85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/FbTk/Accessor.hh b/src/FbTk/Accessor.hh
new file mode 100644
index 0000000..88db1aa
--- /dev/null
+++ b/src/FbTk/Accessor.hh
@@ -0,0 +1,85 @@
1// Accessor.hh
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#ifndef FBTK_ACCESSOR_HH
23#define FBTK_ACCESSOR_HH
24
25namespace FbTk {
26
27// base class for objects that act like data type T
28template <typename T>
29class Accessor {
30public:
31 virtual Accessor<T> &operator =(const T &val) = 0;
32 virtual operator T() const = 0;
33};
34
35// essentially just a reference
36template <typename T>
37class SimpleAccessor: public Accessor<T> {
38public:
39 SimpleAccessor(T &val): m_val(val) { }
40 inline Accessor<T> &operator =(const T &val) { m_val = val; return *this; }
41 inline operator T() const { return m_val; }
42
43private:
44 T &m_val;
45};
46
47// use object methods as an accessor
48template <typename T, typename Receiver>
49class ObjectAccessor: public Accessor<T> {
50public:
51 typedef T (Receiver:: *Getter)() const;
52 typedef void (Receiver:: *Setter)(T &);
53 ObjectAccessor(Receiver &r, Getter g, Setter s):
54 m_receiver(r), m_getter(g), m_setter(s) { }
55
56 inline operator T() const { return (m_receiver.*m_getter)(); }
57 inline Accessor<T> &operator =(const T &val) {
58 (m_receiver.*m_setter)(val); return *this;
59 }
60
61private:
62 Receiver &m_receiver;
63 Getter m_getter;
64 Setter m_setter;
65};
66
67// same as above but with no set method
68template <typename T, typename Receiver>
69class ConstObjectAccessor: public Accessor<T> {
70public:
71 typedef T (Receiver:: *Getter)() const;
72 ConstObjectAccessor(const Receiver &r, Getter g):
73 m_receiver(r), m_getter(g) { }
74
75 inline operator T() const { return (m_receiver.*m_getter)(); }
76 inline Accessor<T> &operator =(const T &val) { return *this; }
77
78private:
79 const Receiver &m_receiver;
80 Getter m_getter;
81};
82
83}; // end namespace FbTk
84
85#endif // FBTK_ACCESSOR_HH