vdk 2.4.0
vdkprops.h
1// -*- c++ -*-
2/*
3 * ===========================
4 * VDK Visual Development Kit
5 * Version 0.4
6 * October 1998
7 * ===========================
8 *
9 * Copyright (C) 1998, Mario Motta
10 * Developed by Mario Motta <mmotta@guest.net>
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 * 02111-130
26 */
27
28#ifndef VDKPROPS_H
29#define VDKPROPS_H
30#include <vdk/vdkstring.h>
31#include <vdk/vdkfont.h>
32#include <cstdio>
33
34#ifdef USE_SIGCPLUSPLUS
35# include <vdk/sigc_addon.h>
36#endif // USE_SIGCPLUSPLUS
37
38#define __rwproperty(ownerClass,propertyType) \
39 VDKReadWriteValueProp<ownerClass, propertyType>
40#define __rproperty(ownerClass,propertyType) \
41 VDKReadOnlyValueProp<ownerClass, propertyType>
42#ifdef NULL
43#undef NULL
44#define NULL 0x0000
45#endif
46#define PFREAD_NULL (PFRead) 0x0000
47#define PFWRITE_NULL (PFWrite) 0x0000
48//==================================================
49/*
50read/write values property
51*/
52template <class T, typename S>
53class VDKReadWriteValueProp
54#ifdef USE_SIGCPLUSPLUS
55 : public SigC::Object
56#endif
57{
58 // checked out because confuse some compiler
59 //friend class T;
60 protected:
61 typedef S (T::* PFRead)(void);
62 typedef void (T::*PFWrite)(S);
63
64 VDKString name;
65 T* object;
66 S (T::* get)(void);
67 void (T::*set)(S);
68 S value;
69 VDKReadWriteValueProp(VDKReadWriteValueProp& p) { }
70 void operator=(VDKReadWriteValueProp& p) { }
71 public:
72
73 VDKReadWriteValueProp():
74 name(""),
75 object(NULL),
76 get(NULL /*PFREAD_NULL*/),
77 set(NULL /*PFWRITE_NULL*/)
78 { }
79
80 VDKReadWriteValueProp(
81 const char* name,
82 T* object,
83 S defValue,
84 void (T::*write)(S) = NULL,//PFWRITE_NULL,
85 S (T::*read)(void) = NULL //PFREAD_NULL
86 ):
87 name(name),object(object),
88 get(read),set(write),
89 value(defValue)
90 { }
91
92 virtual ~VDKReadWriteValueProp() {}
93
94 // raw setting (functor)
95 // caution using it in read only props breaks
96 // data hiding and can lead in ugly errors.
97 // user: use it at your own risk.
98 virtual void operator()(S val)
99 {
100 value = val;
101#ifdef USE_SIGCPLUSPLUS
102 OnValueChanged.emit(object, value);
103#endif
104 }
105 // setting prop value operator
106 virtual void operator = (S val)
107 {
108 if(set && object)
109 ((*object).*set)(val);
110 value = val;
111#ifdef USE_SIGCPLUSPLUS
112 OnValueChanged.emit(object, value);
113#endif
114 }
115 // getting prop value operator
116 virtual operator S()const
117 {
118 if(get && object)
119// return (*((const_cast<VDKReadWriteValueProp<T,S>*>(this))->object).*get)();
120 return ((*object).*get)();
121 else
122 return value;
123 }
124 char* Name() { return name; }
125 S Value()const { return value; }
126#ifdef USE_SIGCPLUSPLUS
127 DualSignal1<void, T*,S> OnValueChanged;
128#endif
129};
130
131/*
132read only values property
133*/
134template <class T, class S>
135class VDKReadOnlyValueProp: public VDKReadWriteValueProp<T,S>
136{
137 void operator = (S) { }
138 public:
139 VDKReadOnlyValueProp():VDKReadWriteValueProp<T,S>() { }
140 VDKReadOnlyValueProp(
141 const char* name,
142 T* object,
143 S defValue,
144 S (T::*read)(void) = NULL, //PFREAD_NULL,
145 void (T::*write)(S) = NULL //PFWRITE_NULL
146 ):
147 VDKReadWriteValueProp<T,S>(
148 name,
149 object,
150 defValue,
151 write,
152 read) { }
153
154 virtual ~VDKReadOnlyValueProp() {}
155
156};
157#endif
158
159
160
161
162
163
164
165
166
167
168
169
Implements famous cont referenced string objects.
Definition: vdkstring.h:46