Main Page   Compound List   File List   Compound Members   File Members  

lib/gobj/object.h

Go to the documentation of this file.
00001 /* lib/object.h - common object type implementation
00002    Copyright (C) 1999, 2000, 2001 Thomas Uehlinger
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00017 
00025 #include <gobjconfig.h>
00026 
00027 #ifndef gobj_lib_object_h
00028 #define gobj_lib_object_h
00029 
00030 #include <gobj/decls.h>
00031 #include <gobj/id.h>
00032 #include <gobj/context.h>
00033 #include <gobj/nativetypes.h>
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif /* __cplusplus */
00038 #if 0
00039 }
00040 #endif
00041 
00042 
00053 Gj_Object* Gj_object_new(Gj_Ctx* ctx, Gj_Id* type, char* name);
00054 
00055 
00065 Gj_Object* Gj_object_duplicate(Gj_Ctx* ctx, Gj_Object* obj);
00066 
00067 
00068 /*
00069    @brief Create a new object as a copy of existing object, but do not copy the native data (for convert copy).
00070    
00071    @param c
00072  * Error: returns the poindter to the new object on success, 0 otherwise
00073  *
00074  */
00075 /*Gj_Object* gj_object_duplicateInternal(Gj_Ctx* ctx, Gj_Object* obj);*/
00076 
00077 
00088 Gj_Object* Gj_object_create(Gj_Ctx* ctx, Gj_Stream* stream, Gj_Object* update);
00089 
00090 
00100 int Gj_object_delete(Gj_Ctx* ctx, Gj_Object* ptr);
00101 
00102 
00112 int Gj_object_deleteLocal(Gj_Ctx* ctx, Gj_Object* ptr);
00113 
00114 
00125 int Gj_object_write(Gj_Ctx* ctx, Gj_Object* obj, Gj_Stream* stream);
00126 
00127 
00134 #ifdef GJ_LOCKING
00135 void gj_object_initLocks(Gj_Object* obj);
00136 #else
00137 #define gj_object_initLocks(a)
00138 #endif
00139 
00140 
00147 #ifdef GJ_LOCKING
00148 void gj_object_finalizeLocks(Gj_Object* obj);
00149 #else
00150 #define gj_object_finalizeLocks(a)
00151 #endif
00152 
00153 
00154 /*
00155  * Aquire a "delete lock" for the object (aquire a exclusive lock even if there is one shared lock aquired)
00156  *
00157  */
00158 /*void gj_object_lockDelete(Gj_Object* obj);*/
00159 
00160 
00167 #ifdef GJ_LOCKING
00168 void gj_object_lockShared(Gj_Object* obj);
00169 #else
00170 #define gj_object_lockShared(a)
00171 #endif
00172 
00173 
00182 #ifdef GJ_LOCKING
00183 void Gj_object_unlockShared(Gj_Object* obj);
00184 #else
00185 #define Gj_object_unlockShared(a)
00186 #endif
00187 
00188 
00201 int Gj_object_release(Gj_Ctx* ctx, Gj_Object* obj);
00202 
00203  
00212 #ifdef GJ_LOCKING
00213 void Gj_object_lockExcl(Gj_Object* obj);
00214 #else
00215 #define Gj_object_lockExcl(a)
00216 #endif
00217 
00218 
00225 #ifdef GJ_LOCKING
00226 void Gj_object_unlockExcl(Gj_Object* obj);
00227 #else
00228 #define Gj_object_unlockExcl(a)
00229 #endif
00230 
00231 
00232 /*
00233    @brief Activate the "follow link" mode for this object.
00234  * Error: returns 0 on success, -1 otherwise
00235  *
00236  */
00237 /*int Gj_object_followLinksOn(Gj_Ctx* ctx, Gj_Object* obj);*/
00238 
00239 
00240 /*
00241  * Disactivate the "follow link" mode for this object
00242  * set links to the number of links the function should follow at most (-1 means as many as possible)
00243  * Error: returns 0 on success, -1 otherwise
00244  * 
00245  */
00246 /*int Gj_object_followLinksOff(Gj_Ctx* ctx, Gj_Object* obj, int links);*/
00247 
00248 
00258 Gj_Id* Gj_object_assignId(Gj_Ctx* ctx, Gj_Object* obj);
00259 
00260 
00269 void Gj_object_markTemp(Gj_Object* obj);
00270 
00271 
00280 Gj_Bool Gj_object_isTemp(Gj_Object* obj);
00281 
00282 
00291 int Gj_object_getName(Gj_Ctx* ctx, Gj_Object* obj, char** name);
00292 
00293 
00294 /*
00295  * Set the name of the object
00296  * the name is being DUPLICATED
00297  * name may be 0
00298  * Error: returns 0 on success, -1 otherwise
00299  *
00300  */
00301 int Gj_object_setName(Gj_Ctx* ctx, Gj_Object* obj, char* name);
00302 
00303 
00304 /*
00305  * Get the native type of the object
00306  * Error: returns the nativetype on success, GJ_NTYPES_NONE (=0) on error
00307  *
00308  */
00309 Gj_Nativetype Gj_object_getNativetype(Gj_Ctx* ctx, Gj_Object* obj);
00310 
00311  
00312 /*
00313  * Set the value of a property given by name (only used for instances of models with fixed properties)
00314  * the value object is NOT duplicated
00315  * Error: returns 0 on success, -1 otherwise
00316  *
00317  */
00318 int Gj_object_setByName(Gj_Ctx* ctx, Gj_Object* obj, char* name, Gj_Object* value);
00319 
00320 
00321 /*
00322  * Set the value of a property/child given by its number
00323  * the value object is NOT duplicated
00324  * Error: returns 0 on success, -1 otherwise
00325  *
00326  */
00327 int Gj_object_setByNumber(Gj_Ctx* ctx, Gj_Object* obj, int index, Gj_Object* value);
00328 
00329 
00330 /*
00331  * Get the value of a property given by its name (only used for instances of models with fixed properties)
00332  * the *value object is STILL OWNED by the object
00333  * *value == 0 means that this property has no value
00334  * Error: returns 0 on success, -1 otherwise
00335  *
00336  */
00337 int Gj_object_getByName(Gj_Ctx* ctx, Gj_Object* obj, char* name, Gj_Object** value, Gj_Bool convert);
00338  
00339 
00340 /*
00341  * Get the value of a property/child given by its number
00342  * the *value object is STILL OWNED by the object
00343  * *value == 0 means that this property has no value
00344  * Error: returns 0 on success, -1 otherwise
00345  *
00346  */
00347 int Gj_object_getByNumber(Gj_Ctx* ctx, Gj_Object* obj, int index, Gj_Object** value, Gj_Bool convert);
00348 
00349 
00350 /*
00351  * Set *last to the next element of the child walkthrough (only used for instances of models with non-fixed properties) 
00352  * if *last is 0, the first element is set
00353  * the returned child is STILL OWNED by the object
00354  * a null pointer is set if the last element was already reached
00355  * if the object is a link, DO NOT change the followLinks flag and/or the link itself during calls to this function
00356  * Error: returns 0 on success, -1 otherwise
00357  *
00358  */
00359 int Gj_object_nextChild(Gj_Ctx* ctx, Gj_Object* obj, Gj_Object** last, Gj_Bool convert);
00360 
00361 
00362 /*
00363  * Get the child count of the object (only used for instances of models with non-fixed properties)
00364  * Error: returns the child count on success, -1 otherwise
00365  *
00366  */
00367 int Gj_object_getChildCount(Gj_Ctx* ctx, Gj_Object* obj);
00368 
00369 
00370 /*
00371  * Add a child (only used for types with non-fixed properties)
00372  * the value object is NOT DUPLICATED
00373  * Error: returns the number of the new add child on success, -1 otherwise
00374  *
00375  */
00376 int Gj_object_add(Gj_Ctx* ctx, Gj_Object* obj, Gj_Object* value);
00377 
00378 
00379 /* INTERNAL (no link following and native function calls are made)
00380  * Add a child (only used for types with non-fixed properties)
00381  * the value object is NOT DUPLICATED
00382  * Error: returns the number of the new add child on success, -1 otherwise
00383  *
00384  */
00385 int gj_object_add(Gj_Ctx* ctx, Gj_Object* obj, Gj_Object* value);
00386 
00387 
00388 /*
00389  * Remove a child given by name (only used for types with non-fixed properties)
00390  * the value object is deleted
00391  * Error: returns 0 on success, -1 otherwise
00392  *
00393  */
00394 /*int Gj_object_removeByName(Gj_Ctx* ctx, Gj_Object* obj, char* name);*/
00395 
00396 
00397 /*
00398  * Remove a child given by its number (only used for types with non-fixed properties)
00399  * the value object is deleted
00400  * Error: returns 0 on success, -1 otherwise
00401  *
00402  */
00403 int Gj_object_removeByNumber(Gj_Ctx* ctx, Gj_Object* obj, int index);
00404 
00405 
00406 /*
00407  * Pass the object them through the viewers and convert it to a given type
00408  * if type == 0 no final type conversion is done
00409  * if the resulting pointer is != obj, delete the resulting object afterwards via Gj_object_deleteTemp()
00410  * Error: returns the pointer to the resulting object on success, 0 otherwise
00411  *
00412  */
00413 Gj_Object* Gj_object_convert(Gj_Ctx* ctx, Gj_Object* obj, Gj_Id* type);
00414 
00415 
00416 /*
00417  * Add a viewer to the object
00418  * the viewer is NOT DUPLICATED
00419  * Error: returns 0 on success, -1 otherwise
00420  *
00421  */
00422 int Gj_object_addViewer(Gj_Ctx* ctx, Gj_Object* obj, Gj_Viewer* viewer);
00423 
00424 
00425 /*
00426  * Delete all viewers of the object
00427  * Error: returns 0 on success, -1 otherwise
00428  *
00429  */
00430 int Gj_object_deleteViewers(Gj_Ctx* ctx, Gj_Object* obj);
00431 
00432 
00433 #ifdef GJ_STDIO
00434 #include <stdio.h>
00435 /*
00436  * Dump the object onto the given stream
00437  * if you call this function yourself *indent should be 0
00438  *
00439  */
00440 void Gj_object_dump(Gj_Ctx* ctx, Gj_Object* obj, FILE* s, int* indent);
00441 #endif
00442 
00443 
00449 struct Gj_Object_struct {
00450   
00451   char* name;
00452 
00453   Gj_Model* model;
00454 
00455   Gj_Object* parent;
00456   Gj_Object* update;
00457 
00458   Gj_Viewer* viewers;
00459 
00460   Gj_Bool fixedProperties;
00461   Gj_Bool vaccess;
00462   Gj_Bool temp;
00463   Gj_Bool link;
00464 
00465 #ifdef GJ_LOCKING
00466   Gj_Bool exclLock;
00467   int sharedLocks;
00468 #endif
00469 
00470   union {
00471     Gj_Object** fix;
00472     
00473     struct {
00474       Gj_Object* first;
00475       Gj_Object* last;
00476     } notfix;
00477   } children;
00478 
00479   Gj_Object* next;
00480 
00481 };
00482 
00483 
00484 /* INTERNAL
00485  * the linkrecord structure
00486  *
00487  */
00488 struct gj_Linkrecord_struct {
00489 
00490   Gj_Object* obj;
00491 
00492   Gj_Viewer* viewer;
00493 
00494 };
00495 
00496 
00497 #ifdef __cplusplus
00498 }
00499 #endif /* __cplusplus */
00500 
00501 #endif /* !gobj_lib_object_h */
00502 

Generated at Fri Aug 17 18:28:55 2001 for Gobj by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000