00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef _ATX_PROPERTIES_H_
00014 #define _ATX_PROPERTIES_H_
00015
00016
00017
00018
00019 #include "AtxInterfaces.h"
00020 #include "AtxTypes.h"
00021 #include "AtxIterator.h"
00022
00023
00024
00025
00026 #define ATX_ERROR_NO_SUCH_PROPERTY (ATX_ERROR_BASE_PROPERTIES - 0)
00027 #define ATX_ERROR_NO_SUCH_LISTENER (ATX_ERROR_BASE_PROPERTIES - 1)
00028 #define ATX_ERROR_PROPERTY_TYPE_MISMATCH (ATX_ERROR_BASE_PROPERTIES - 2)
00029
00030
00031
00032
00036 typedef enum {
00037 ATX_PROPERTY_TYPE_NONE,
00038 ATX_PROPERTY_TYPE_INTEGER,
00039 ATX_PROPERTY_TYPE_FLOAT,
00040 ATX_PROPERTY_TYPE_STRING,
00041 ATX_PROPERTY_TYPE_BOOLEAN,
00042 ATX_PROPERTY_TYPE_RAW_DATA
00043 } ATX_PropertyType;
00044
00045 typedef struct {
00046 ATX_Size size;
00047 ATX_Any data;
00048 } ATX_PropertyRawData;
00049
00054 typedef union {
00055 void* any;
00056 ATX_CString string;
00057 ATX_Int32 integer;
00058 ATX_Float fp;
00059 ATX_Boolean boolean;
00060 ATX_PropertyRawData raw_data;
00061 } ATX_PropertyValue;
00062
00063 typedef const void* ATX_PropertyListenerHandle;
00064
00069 typedef struct {
00070 ATX_CString name;
00071 ATX_PropertyType type;
00072 ATX_PropertyValue value;
00073 } ATX_Property;
00074
00075
00076
00077
00078 ATX_DECLARE_INTERFACE(ATX_PropertyListener)
00079 ATX_BEGIN_INTERFACE_DEFINITION(ATX_PropertyListener)
00090 void (*OnPropertyChanged)(ATX_PropertyListener* self,
00091 ATX_CString name,
00092 ATX_PropertyType type,
00093 const ATX_PropertyValue* value);
00094 ATX_END_INTERFACE_DEFINITION
00095
00096
00097
00098
00099 ATX_DECLARE_INTERFACE(ATX_Properties)
00108 ATX_BEGIN_INTERFACE_DEFINITION(ATX_Properties)
00120 ATX_Result (*GetProperty)(ATX_Properties* self,
00121 ATX_CString name,
00122 ATX_Property* property);
00123
00133 ATX_Result (*SetProperty)(ATX_Properties* self,
00134 ATX_CString name,
00135 ATX_PropertyType type,
00136 const ATX_PropertyValue* value);
00137
00144 ATX_Result (*UnsetProperty)(ATX_Properties* self,
00145 ATX_CString name);
00146
00152 ATX_Result (*Clear)(ATX_Properties* self);
00153
00154 ATX_Result (*GetIterator)(ATX_Properties* self,
00155 ATX_Iterator** iterator);
00156 #if 0
00157 ATX_Result (*AddAlias)(ATX_PropertiesInstance* instance,
00158 ATX_CString alias,
00159 ATX_CString name);
00160
00161 ATX_Result (*RemoveAlias)(ATX_PropertiesInstance* instance,
00162 ATX_CString alias);
00163
00173 ATX_Result (*GetAliases)(ATX_PropertiesInstance* instance,
00174 ATX_CString name,
00175 ATX_Iterator* iterator);
00176 #endif
00177
00188 ATX_Result (*AddListener)(ATX_Properties* self,
00189 ATX_CString name,
00190 ATX_PropertyListener* listener,
00191 ATX_PropertyListenerHandle* handle);
00192
00193 ATX_Result (*RemoveListener)(ATX_Properties* self,
00194 ATX_PropertyListenerHandle handle);
00195
00196 ATX_END_INTERFACE_DEFINITION
00197
00198
00199
00200
00205 #define ATX_Properties_GetProperty(object, name, property) \
00206 ATX_INTERFACE(object)->GetProperty(object, \
00207 name, \
00208 property)
00209
00214 #define ATX_Properties_SetProperty(object, name, type, value) \
00215 ATX_INTERFACE(object)->SetProperty(object, \
00216 name, \
00217 type, \
00218 value)
00219
00224 #define ATX_Properties_UnsetProperty(object, name) \
00225 ATX_INTERFACE(object)->UnsetProperty(object, name)
00226
00231 #define ATX_Properties_Clear(object) \
00232 ATX_INTERFACE(object)->Clear(object)
00233
00238 #define ATX_Properties_GetIterator(object, iterator) \
00239 ATX_INTERFACE(object)->GetIterator(object, iterator)
00240
00245 #define ATX_Properties_AddListener(object, name, listener, handle) \
00246 ATX_INTERFACE(object)->AddListener(object, \
00247 name, \
00248 listener, \
00249 handle)
00250
00255 #define ATX_Properties_RemoveListener(object, handle) \
00256 ATX_INTERFACE(object)->RemoveListener(object, handle)
00257
00262 #define ATX_PropertyListener_OnPropertyChanged(object, name, type, value) \
00263 ATX_INTERFACE(object)->OnPropertyChanged(object, \
00264 name, \
00265 type, \
00266 value)
00267
00268
00269
00270
00271 #ifdef __cplusplus
00272 extern "C" {
00273 #endif
00274
00275 ATX_Result ATX_Properties_Create(ATX_Properties** properties);
00276
00277 #ifdef __cplusplus
00278 }
00279 #endif
00280
00281 #endif