Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

vdkprops.h

00001 // -*- c++ -*- 00002 /* 00003 * =========================== 00004 * VDK Visual Development Kit 00005 * Version 0.4 00006 * October 1998 00007 * =========================== 00008 * 00009 * Copyright (C) 1998, Mario Motta 00010 * Developed by Mario Motta <mmotta@guest.net> 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Library General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Library General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Library General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00025 * 02111-130 00026 */ 00027 00028 #ifndef VDKPROPS_H 00029 #define VDKPROPS_H 00030 #include <vdk/vdkstring.h> 00031 #include <vdk/vdkfont.h> 00032 #include <cstdio> 00033 00034 #ifdef USE_SIGCPLUSPLUS 00035 # include <vdk/sigc_addon.h> 00036 #endif // USE_SIGCPLUSPLUS 00037 00038 #define __rwproperty(ownerClass,propertyType) \ 00039 VDKReadWriteValueProp<ownerClass, propertyType> 00040 #define __rproperty(ownerClass,propertyType) \ 00041 VDKReadOnlyValueProp<ownerClass, propertyType> 00042 #ifdef NULL 00043 #undef NULL 00044 #define NULL 0x0000 00045 #endif 00046 #define PFREAD_NULL (PFRead) 0x0000 00047 #define PFWRITE_NULL (PFWrite) 0x0000 00048 //================================================== 00049 /* 00050 read/write values property 00051 */ 00052 template <class T, typename S> 00053 class VDKReadWriteValueProp 00054 #ifdef USE_SIGCPLUSPLUS 00055 : public SigC::Object 00056 #endif 00057 { 00058 // checked out because confuse some compiler 00059 //friend class T; 00060 protected: 00061 typedef S (T::* PFRead)(void); 00062 typedef void (T::*PFWrite)(S); 00063 00064 VDKString name; 00065 T* object; 00066 S (T::* get)(void); 00067 void (T::*set)(S); 00068 S value; 00069 VDKReadWriteValueProp(VDKReadWriteValueProp& p) { } 00070 void operator=(VDKReadWriteValueProp& p) { } 00071 public: 00072 00073 VDKReadWriteValueProp(): 00074 name(""), 00075 object(NULL), 00076 get(NULL /*PFREAD_NULL*/), 00077 set(NULL /*PFWRITE_NULL*/) 00078 { } 00079 00080 VDKReadWriteValueProp( 00081 const char* name, 00082 T* object, 00083 S defValue, 00084 void (T::*write)(S) = NULL,//PFWRITE_NULL, 00085 S (T::*read)(void) = NULL //PFREAD_NULL 00086 ): 00087 name(name),object(object), 00088 get(read),set(write), 00089 value(defValue) 00090 { } 00091 00092 virtual ~VDKReadWriteValueProp() {} 00093 00094 // raw setting (functor) 00095 // caution using it in read only props breaks 00096 // data hiding and can lead in ugly errors. 00097 // user: use it at your own risk. 00098 virtual void operator()(S val) 00099 { 00100 value = val; 00101 #ifdef USE_SIGCPLUSPLUS 00102 OnValueChanged.emit(object, value); 00103 #endif 00104 } 00105 // setting prop value operator 00106 virtual void operator = (S val) 00107 { 00108 if(set && object) 00109 ((*object).*set)(val); 00110 value = val; 00111 #ifdef USE_SIGCPLUSPLUS 00112 OnValueChanged.emit(object, value); 00113 #endif 00114 } 00115 // getting prop value operator 00116 virtual operator S()const 00117 { 00118 if(get && object) 00119 // return (*((const_cast<VDKReadWriteValueProp<T,S>*>(this))->object).*get)(); 00120 return ((*object).*get)(); 00121 else 00122 return value; 00123 } 00124 char* Name() { return name; } 00125 S Value()const { return value; } 00126 #ifdef USE_SIGCPLUSPLUS 00127 DualSignal1<void, T*,S> OnValueChanged; 00128 #endif 00129 }; 00130 00131 /* 00132 read only values property 00133 */ 00134 template <class T, class S> 00135 class VDKReadOnlyValueProp: public VDKReadWriteValueProp<T,S> 00136 { 00137 void operator = (S) { } 00138 public: 00139 VDKReadOnlyValueProp():VDKReadWriteValueProp<T,S>() { } 00140 VDKReadOnlyValueProp( 00141 const char* name, 00142 T* object, 00143 S defValue, 00144 S (T::*read)(void) = NULL, //PFREAD_NULL, 00145 void (T::*write)(S) = NULL //PFWRITE_NULL 00146 ): 00147 VDKReadWriteValueProp<T,S>( 00148 name, 00149 object, 00150 defValue, 00151 write, 00152 read) { } 00153 00154 virtual ~VDKReadOnlyValueProp() {} 00155 00156 }; 00157 #endif 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169

Generated on Tue Aug 17 12:39:51 2004 for vdk 2.4.0 by doxygen 1.3.7