00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATTimePeriod.c,v 1.19 2004/04/02 12:31:58 hartmutkaiser Exp $";
00021
00022
00023 #include <string.h>
00024 #include <stdlib.h>
00025
00026
00027 #include "GATErrors.h"
00028 #include "GATInternal.h"
00029 #include "GATTime.h"
00030 #include "GATTimePeriod.h"
00031 #include "GATXdsWrapper.h"
00032
00033
00034
00035
00036
00037
00038 GATOBJECT_DEFINE_VTABLE(GATTimePeriod);
00039 GATSERIALISABLE_DEFINE_VTABLE(GATTimePeriod);
00040
00041
00042 GATOBJECT_DEFINE_CONVERTERS(GATTimePeriod);
00043
00044 struct GATTimePeriod_S
00045 {
00046 GATTimePeriod_vtable *GATObject__vtable;
00047 GATTimePeriod_ISerialisable_vtable *GATSerialisable__vtable;
00048
00049 GATdouble64 internalDuration;
00050 };
00051
00052
00053 static GATResult
00054 GATTimePeriod_DeSerialise_Create(GATContext context, GATObject stream,
00055 GATdouble64 duration, GATTimePeriod *new_object);
00056
00057
00058 static GATTimePeriod_vtable GATTimePeriod__vtable = {
00059 GATTimePeriod_GetType,
00060 GATTimePeriod_Destroy,
00061 GATTimePeriod_Equals,
00062 GATTimePeriod_Clone,
00063 GATTimePeriod_GetInterface,
00064 NULL
00065 };
00066
00067 static GATTimePeriod_ISerialisable_vtable
00068 GATTimePeriod_ISerialisable__vtable =
00069 {
00070 GATTimePeriod_Serialise,
00071 GATTimePeriod_DeSerialise,
00072 GATTimePeriod_GetIsDirty,
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 GATResult GATTimePeriod_Register_GATSerialisable(void)
00084 {
00085 return GATObject_Register_GATSerialisable(GATType_GATTimePeriod,
00086 &GATTimePeriod_ISerialisable__vtable);
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 GATTimePeriod GATTimePeriod_Create(GATdouble64 duration)
00099 {
00100 GATTimePeriod newobject =
00101 (GATTimePeriod) malloc(sizeof(struct GATTimePeriod_S));
00102 if(NULL != newobject)
00103 {
00104 newobject->GATObject__vtable = &GATTimePeriod__vtable;
00105 newobject->GATSerialisable__vtable = &GATTimePeriod_ISerialisable__vtable;
00106
00107 newobject->internalDuration = duration;
00108 }
00109 return newobject;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 GATTimePeriod GATTimePeriod_Create_Difference(GATTime start, GATTime end)
00125 {
00126 GATTimePeriod newobject = NULL;
00127 if (NULL != start && NULL != end)
00128 {
00129 newobject = (GATTimePeriod) malloc(sizeof(struct GATTimePeriod_S));
00130 if(NULL != newobject)
00131 {
00132 memset(newobject, 0, sizeof(struct GATTimePeriod_S));
00133 newobject->GATObject__vtable = &GATTimePeriod__vtable;
00134 newobject->GATSerialisable__vtable = &GATTimePeriod_ISerialisable__vtable;
00135
00136 newobject->internalDuration = GATTime_GetTime(end) - GATTime_GetTime(start);
00137 }
00138 }
00139 return newobject;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148 void GATTimePeriod_Destroy(GATTimePeriod *object)
00149 {
00150 if( (NULL != object) && (NULL != *object) )
00151 {
00152 free(*object);
00153 *object = NULL;
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 GATResult
00167 GATTimePeriod_Equals(GATTimePeriod_const lhs, GATTimePeriod_const that,
00168 GATBool *isequal)
00169 {
00170 GATResult retval = GAT_INVALID_HANDLE;
00171 if( (NULL != lhs) && (NULL != that) )
00172 {
00173 if (NULL != isequal)
00174 {
00175 (*isequal) = (lhs->internalDuration == that->internalDuration) ?
00176 GATTrue : GATFalse;
00177 retval = GAT_SUCCESS;
00178 }
00179 else
00180 {
00181 retval = GAT_INVALID_PARAMETER;
00182 }
00183 }
00184 return retval;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194 GATType GATTimePeriod_GetType(GATTimePeriod_const this)
00195 {
00196 GAT_UNUSED_PARAMETER(this);
00197 return GATType_GATTimePeriod;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 GATResult
00210 GATTimePeriod_Clone(GATTimePeriod_const object, GATTimePeriod *thisClone)
00211 {
00212 GATResult retval = GAT_INVALID_HANDLE;
00213 if (NULL != object)
00214 {
00215 GATTimePeriod newGATTimePeriod =
00216 (GATTimePeriod) malloc( sizeof(struct GATTimePeriod_S) );
00217
00218 if(NULL != newGATTimePeriod)
00219 {
00220 memset(newGATTimePeriod, 0, sizeof(struct GATTimePeriod_S));
00221 newGATTimePeriod->GATObject__vtable = object->GATObject__vtable;
00222 newGATTimePeriod->GATSerialisable__vtable = &GATTimePeriod_ISerialisable__vtable;
00223 newGATTimePeriod->internalDuration = object->internalDuration;
00224
00225 if (NULL != thisClone)
00226 {
00227 (*thisClone) = newGATTimePeriod;
00228 retval = GAT_SUCCESS;
00229 }
00230 else
00231 {
00232 GATTimePeriod_Destroy(&newGATTimePeriod);
00233 retval = GAT_INVALID_PARAMETER;
00234 }
00235 }
00236 else
00237 {
00238 retval = GAT_MEMORYFAILURE;
00239 }
00240 }
00241 return retval;
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 GATResult
00257 GATTimePeriod_GetInterface(GATTimePeriod_const object, GATInterface iftype,
00258 void const **ifp)
00259 {
00260 GATResult retval = GAT_INVALID_PARAMETER;
00261
00262 if (NULL != ifp)
00263 {
00264 *ifp = NULL;
00265 if (GATInterface_ISerialisable == iftype)
00266 {
00267 *ifp = (void const *) &object->GATSerialisable__vtable;
00268 retval = GAT_SUCCESS;
00269 }
00270 else
00271 {
00272 retval = GAT_NO_INTERFACE;
00273 }
00274 }
00275 return retval;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 GATResult
00295 GATTimePeriod_Serialise(GATTimePeriod object, GATObject stream,
00296 GATBool clear_dirty)
00297 {
00298 GATResult retval = GAT_INVALID_HANDLE;
00299 if (NULL != object)
00300 {
00301 retval = GATXds_SerialiseObject(GATTimePeriod_ToGATObject(object), stream,
00302 clear_dirty, 0, "uint32 double_fmt",
00303 GATTIMEPERIOD_VERSION1, "%15.6lf", object->internalDuration);
00304 }
00305 return retval;
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 static GATBool
00323 GATTimePeriod_VersionCallback(GATuint32 version)
00324 {
00325 GATBool retval = GATFalse;
00326 if ((version & ~GATTIMEPERIOD_MINOR_MASK) <= GATTIMEPERIOD_LASTVERSION)
00327 {
00328 retval = GATTrue;
00329 }
00330 return retval;
00331 }
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 static GATResult
00357 GATTimePeriod_DeSerialiseCallback(GATContext context, GATObject stream,
00358 GATObject *new_object, GATuint32 version, va_list args)
00359 {
00360
00361 GATdouble64 *duration = va_arg(args, GATdouble64 *);
00362 GATTimePeriod object = NULL;
00363
00364
00365 GATResult retval = GATTimePeriod_DeSerialise_Create(context, stream,
00366 *duration, &object);
00367
00368 GAT_UNUSED_PARAMETER(version);
00369
00370 if (GAT_SUCCESS == retval)
00371 {
00372 if (NULL != object)
00373 {
00374 *new_object = GATTimePeriod_ToGATObject(object);
00375 }
00376 else
00377 {
00378 GATTimePeriod_Destroy(&object);
00379 retval = GAT_INVALID_PARAMETER;
00380 }
00381 }
00382 return retval;
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 GATTimePeriod
00400 GATTimePeriod_DeSerialise(GATContext context, GATObject stream,
00401 GATResult *result)
00402 {
00403 GAT_USES_STATUS(context, "GATTimePeriod_DeSerialise");
00404 GATObject object = NULL;
00405
00406
00407
00408 GATuint32 version = 0;
00409 GATdouble64 duration = 0;
00410
00411
00412 GAT_CREATE_STATUS(GATXds_DeSerialiseObject(context, stream,
00413 GATTimePeriod_DeSerialiseCallback, GATTimePeriod_VersionCallback, &object,
00414 "uint32 double", &version, &duration));
00415
00416 if (NULL != result)
00417 {
00418 *result = GAT_CURRENT_STATUS();
00419 }
00420 else
00421 {
00422 GAT_STORE_STATUS();
00423 }
00424 return GATObject_ToGATTimePeriod(object);
00425 }
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 GATResult GATTimePeriod_GetIsDirty(GATTimePeriod_const object, GATBool *isdirty)
00438 {
00439 GATResult retval = GAT_INVALID_HANDLE;
00440 if (NULL != object)
00441 {
00442 if (NULL != isdirty)
00443 {
00444 *isdirty = GATFalse;
00445 retval = GAT_SUCCESS;
00446 }
00447 else
00448 {
00449 retval = GAT_INVALID_PARAMETER;
00450 }
00451 }
00452 return retval;
00453 }
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 GATdouble64 GATTimePeriod_GetDuration(GATTimePeriod_const object)
00467 {
00468 GATdouble64 retval = 0.;
00469 if (NULL != object)
00470 {
00471 retval = object->internalDuration;
00472 }
00473 return retval;
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 static GATResult
00494 GATTimePeriod_DeSerialise_Create(GATContext context, GATObject stream,
00495 GATdouble64 duration, GATTimePeriod *object)
00496 {
00497 GAT_USES_STATUS(context, "GATTimePeriod_DeSerialise_Create");
00498 GATTimePeriod new_object =
00499 (GATTimePeriod) malloc(sizeof(struct GATTimePeriod_S));
00500
00501 GAT_UNUSED_PARAMETER(stream);
00502
00503 if(NULL != new_object)
00504 {
00505 memset(new_object, 0, sizeof(struct GATTimePeriod_S));
00506 new_object->GATObject__vtable = &GATTimePeriod__vtable;
00507 new_object->GATSerialisable__vtable = &GATTimePeriod_ISerialisable__vtable;
00508
00509 new_object->internalDuration = duration;
00510 }
00511 else
00512 {
00513 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00514 }
00515
00516 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00517 {
00518 if (NULL != new_object)
00519 {
00520 *object = new_object;
00521 }
00522 else
00523 {
00524 GATTimePeriod_Destroy(&new_object);
00525 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00526 }
00527 }
00528 else
00529 {
00530 GATTimePeriod_Destroy(&new_object);
00531 }
00532 return GAT_RETURN_STATUS();
00533 }
00534
00535
00536