Main Page   Compound List   File List   Compound Members   File Members  

lib/gobj/nativetypes.h

Go to the documentation of this file.
00001 /* lib/nativetypes.h - Native types
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_nativetypes_h
00028 #define gobj_lib_nativetypes_h
00029 
00030 #include <gobj/decls.h>
00031 #include <gobj/context.h>
00032 #include <gobj/types.h>
00033 #include <gobj/path.h>
00034 #include <gobj/id.h>
00035 #include <gobj/stream.h>
00036 
00037 #ifdef HAVE_WCHAR_H
00038 #include <wchar.h>
00039 #endif
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif /* __cplusplus */
00044 #if 0
00045 }
00046 #endif
00047 
00048 
00049 /*
00050  * typedefs
00051  *
00052  */
00053 
00058 typedef int Gj_NInt;
00059 
00060 
00065 typedef double Gj_NFloat;
00066 
00067 
00072 #ifdef GJ_BIGNUMS
00073 typedef Gj_Bignum* Gj_NBignum;
00074 #endif
00075 
00080 #ifdef HAVE_WCHAR_H
00081 typedef wchar_t Gj_NChar;
00082 #else
00083 typedef char Gj_NChar
00084 #endif
00085 
00086 
00091 typedef char* Gj_NString;
00092 
00093 
00098 typedef Gj_Bool Gj_NBool;
00099 
00100 
00107 typedef struct gj_NLink_struct {
00108 
00109   Gj_Path* path;
00110 
00111   union { 
00112     /*Gj_Object* ptr;*/
00113     Gj_Comm* comm;
00114   } resolved;
00115 
00116   Gj_Bool remote;
00117 
00118 } gj_NLink;
00119 
00120 
00125 typedef Gj_Path* Gj_NLink;
00126 
00127 
00134 typedef struct gj_NParamLink_struct {
00135 
00136   int num;
00137 
00138   Gj_Object* ptr;
00139 
00140 } gj_NParamLink;
00141 
00142 
00147 typedef int Gj_NParamLink;
00148 
00149 
00156 typedef struct gj_NPropertyLink_struct {
00157 
00158   int num;
00159 
00160   Gj_Object* ptr;
00161 
00162 } gj_NPropertyLink;
00163 
00164 
00169 typedef int Gj_NPropertyLink;
00170 
00171 
00178 typedef struct gj_NData_struct {
00179 
00180   void* data;
00181 
00182   Gj_Bool own;
00183 
00184 } gj_NData;
00185 
00186 
00191 typedef void* Gj_NData;
00192 
00193 
00198 typedef enum Gj_Nativetype_enum {
00199 
00200   GJ_NTYPES_NONE = 0,
00201   GJ_NTYPES_INT,
00202   GJ_NTYPES_FLOAT,
00203 #ifdef GJ_BIGNUMS
00204   GJ_NTYPES_BIGNUM,
00205 #endif
00206   GJ_NTYPES_CHAR,
00207   GJ_NTYPES_STRING,
00208   GJ_NTYPES_BOOL,
00209   GJ_NTYPES_LINK,
00210   GJ_NTYPES_PARAMLINK,
00211   GJ_NTYPES_PROPERTYLINK,
00212   GJ_NTYPES_DATA
00213 
00214 } Gj_Nativetype;
00215 
00216 
00217 /*
00218  * Get the allocation size of a object with the given native type (for GJ_NTYPES_NONE it is sizeof(Gj_Object))
00219  *
00220  */
00221 int Gj_nativetypes_getAllocSize(Gj_Nativetype type);
00222 
00223 
00224 /*
00225  * Get the name of the given nativetype as a string
00226  *
00227  */
00228 const char* Gj_nativetypes_getName(Gj_Nativetype type);
00229 
00230 
00231 /*
00232  * Initialize a native type object
00233  * Error: returns 0 on success, -1 otherwise
00234  *
00235  */
00236 int Gj_nativetypes_init(Gj_Ctx* ctx, Gj_Object* obj, Gj_Nativetype type);
00237 
00238 
00239 /*
00240  * Read a native value form a stream and assign it to the given object
00241  * Error: returns 0 on success, -1 otherwise
00242  *
00243  */
00244 int Gj_nativetypes_read(Gj_Ctx* ctx, Gj_Object* obj, Gj_Nativetype type, Gj_Stream* stream);
00245 
00246 
00247 /*
00248  * Copy the native value from one object to another
00249  * Error: returns 0 on success, -1 otherwise
00250  *
00251  */
00252 int Gj_nativetypes_copy(Gj_Ctx* ctx, Gj_Nativetype type, Gj_Object* src, Gj_Object* dest, Gj_Bool flat);
00253 
00254 
00255 /*
00256  * Finalize a native type object
00257  * Error: returns 0 on success, -1 otherwise
00258  *
00259  */
00260 int Gj_nativetypes_finalize(Gj_Ctx* ctx, Gj_Object* obj, Gj_Nativetype type);
00261 
00262 
00263 /*
00264  * Write the native value of a given object to a stream
00265  * Error: returns 0 on success, -1 otherwise
00266  *
00267  */
00268 int Gj_nativetypes_write(Gj_Ctx* ctx, Gj_Object* obj, Gj_Nativetype type, Gj_Stream* stream);
00269 
00270 
00271 /*
00272  * Set native values
00273  * objects are NOT duplicated
00274  * Error: returns 0 on success, -1 otherwise
00275  *
00276  */
00277 int Gj_object_setNInt(Gj_Ctx* ctx, Gj_Object* obj, Gj_NInt val);
00278 int Gj_object_setNFloat(Gj_Ctx* ctx, Gj_Object* obj, Gj_NFloat val);
00279 #ifdef GJ_BIGNUMS
00280 int Gj_object_setNBignum(Gj_Ctx* ctx, Gj_Object* obj, Gj_NBignum val);
00281 #endif
00282 int Gj_object_setNChar(Gj_Ctx* ctx, Gj_Object* obj, Gj_NChar val);
00283 int Gj_object_setNString(Gj_Ctx* ctx, Gj_Object* obj, Gj_NString val); /* must be allocated via Gj_alloc() */
00284 int Gj_object_setNBool(Gj_Ctx* ctx, Gj_Object* obj, Gj_NBool val);
00285 int Gj_object_setNLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NLink val);
00286 int Gj_object_setNParamLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NParamLink val);
00287 int Gj_object_setNPropertyLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NPropertyLink val);
00288 int Gj_object_setNData(Gj_Ctx* ctx, Gj_Object* obj, Gj_NData val);
00289 
00290 int gj_object_setNParamPropertyLinkPtr(Gj_Ctx* ctx, Gj_Object* obj, Gj_Object* val); /* for NParamLink and NPropertyLink */
00291 
00292 
00293 /*
00294  * Get native values 
00295  * all returned objects are STILL OWNED by the model
00296  * Error: returns 0 on success, -1 otherwise 
00297  *
00298  */
00299 int Gj_object_getNInt(Gj_Ctx* ctx, Gj_Object* obj, Gj_NInt* val);
00300 int Gj_object_getNFloat(Gj_Ctx* ctx, Gj_Object* obj, Gj_NFloat* val);
00301 #ifdef GJ_BIGNUMS
00302 int Gj_object_getNBignum(Gj_Ctx* ctx, Gj_Object* obj, Gj_NBignum* val);
00303 #endif
00304 int Gj_object_getNChar(Gj_Ctx* ctx, Gj_Object* obj, Gj_NChar* val);
00305 int Gj_object_getNString(Gj_Ctx* ctx, Gj_Object* obj, Gj_NString* val);
00306 int Gj_object_getNBool(Gj_Ctx* ctx, Gj_Object* obj, Gj_NBool* val);
00307 int Gj_object_getNLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NLink* val);
00308 int gj_object_getNLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NLink* val); /* does not follow any links */
00309 int Gj_object_getNParamLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NParamLink* val);
00310 int Gj_object_getNPropertyLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_NPropertyLink* val);
00311 int Gj_object_getNData(Gj_Ctx* ctx, Gj_Object* obj, Gj_NData* val);
00312 
00313 /*int gj_object_getNLinkIsLocal(Gj_Ctx* ctx, Gj_Object* obj, Gj_Bool* val);*/ /* does not follow any links */
00314 /*int gj_object_getNLinkPtr(Gj_Ctx* ctx, Gj_Object* obj, void** val);*/ /* does not follow any links */
00315 
00316 int gj_object_getNParamPropertyLinkPtr(Gj_Ctx* ctx, Gj_Object* obj, Gj_Object** val); /* for NParamLink and NPropertyLink */
00317 
00318 
00319 /*
00320  * Write native values to a stream
00321  * Error: returns 0 on success, -1 otherwise
00322  *
00323  */
00324 #define Gj_stream_writeNInt(ctx, stream, val) Gj_stream_writeInt((ctx), (stream), (val))
00325 #define Gj_stream_writeNFloat(ctx, stream, val) Gj_stream_writeDouble((ctx), (stream), (val))
00326 #ifdef GJ_BIGNUMS
00327 #define Gj_stream_writeNBignum(ctx, stream, val) Gj_bignum_write((ctx), (val), (stream))
00328 #endif
00329 #ifdef HAVE_WCHAR_H
00330 #define Gj_stream_writeNChar(ctx, stream, val) Gj_stream_writeWchar((ctx), (stream), (val))
00331 #else
00332 #define Gj_stream_writeNChar(ctx, stream, val) Gj_stream_writeChar((ctx), (stream), (val))
00333 #endif
00334 #define Gj_stream_writeNString(ctx, stream, val) Gj_stream_writeStr((ctx), (stream), (val))
00335 #define Gj_stream_writeNBool(ctx, stream, val) Gj_stream_writeChar((ctx), (stream), (val))
00336 #define Gj_stream_writeNLink(ctx, stream, val) Gj_path_write((ctx), (val), (stream))
00337 #define Gj_stream_writeNParamLink(ctx, stream, val) Gj_stream_writeInt((ctx), (stream), (val))
00338 #define Gj_stream_writeNPropertyLink(ctx, stream, val) Gj_stream_writeInt((ctx), (stream), (val))
00339 #define Gj_stream_writeNData(ctx, stream, val) (-1)
00340 
00341 
00342 /*
00343  * Read native values from a stream 
00344  * the NString is allocated via Gj_alloc() 
00345  * Error: returns 0 on success, -1 otherwise 
00346  *
00347  */
00348 #define Gj_stream_readNInt(ctx, stream, val) Gj_stream_readInt((ctx), (stream), (val))
00349 #define Gj_stream_readNFloat(ctx, stream, val) Gj_stream_readDouble((ctx), (stream), (val))
00350 #ifdef GJ_BIGNUMS
00351 #define Gj_stream_readNBignum(ctx, stream, val) (*(val) = Gj_bignum_create((ctx), (stream)), *(val) == 0 ? -1 : 0)
00352 #endif
00353 #ifdef HAVE_WCHAR_H
00354 #define Gj_stream_readNChar(ctx, stream, val) Gj_stream_readWchar((ctx), (stream), (val))
00355 #else
00356 #define Gj_stream_readNChar(ctx, stream, val) Gj_stream_readChar((ctx), (stream), (val))
00357 #endif
00358 #define Gj_stream_readNString(ctx, stream, val) Gj_stream_readStr((ctx), (stream), (val))
00359 #define Gj_stream_readNBool(ctx, stream, val) Gj_stream_readChar((ctx), (stream), (val))
00360 #define Gj_stream_readNLink(ctx, stream, val) (*(val) = Gj_path_create((ctx), (stream)), *(val) == 0 ? -1 : 0)
00361 #define Gj_stream_readNParamLink(ctx, stream, val) Gj_stream_readInt((ctx), (stream), (val))
00362 #define Gj_stream_readNPropertyLink(ctx, stream, val) Gj_stream_readInt((ctx), (stream), (val))
00363 #define Gj_stream_readNData(ctx, stream, val) (-1)
00364 
00365 
00366 /*
00367  * Resolve a Gj_NLink object 
00368  * Error: returns the pointer to the resolved object or the corresponding communication (according to the remote flag) on success, 0 otherwise
00369  *
00370  */
00371 Gj_Object* gj_object_resolveNLink(Gj_Ctx* ctx, Gj_Object* obj, Gj_Bool* remote);
00372 
00373 
00374 /*
00375  * Resolves all param/property links of this object according to the linkrecord structure
00376  * Error: returns 0 on success, -1 otherwise
00377  *
00378  */
00379 typedef struct gj_Linkrecord_struct gj_Linkrecord;
00380 int gj_object_resolveParamPropertyLinks(Gj_Ctx* ctx, Gj_Object* obj, gj_Linkrecord* linkrecord);
00381 
00382 
00383 #ifdef __cplusplus
00384 }
00385 #endif /* __cplusplus */
00386 
00387 #endif /* !gobj_lib_nativetypes_h */
00388 

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