libDXF 0.0.1
A library with DXF related functions written in C.

object.c

Go to the documentation of this file.
00001 
00036 #include "object.h"
00037 
00038 
00044 DxfObject *
00045 dxf_object_new ()
00046 {
00047 #if DEBUG
00048         DXF_DEBUG_BEGIN
00049 #endif
00050         DxfObject *object = NULL;
00051         size_t size;
00052 
00053         size = sizeof (DxfObject);
00054         /* avoid malloc of 0 bytes */
00055         if (size == 0) size = 1;
00056         if ((object = malloc (size)) == NULL)
00057         {
00058                 fprintf (stderr,
00059                   (_("Error in %s () could not allocate memory for a DxfObject struct.\n")),
00060                   __FUNCTION__);
00061                 object = NULL;
00062         }
00063         else
00064         {
00065                 memset (object, 0, size);
00066         }
00067 #if DEBUG
00068         DXF_DEBUG_END
00069 #endif
00070         return (object);
00071 }
00072 
00073 
00081 DxfObject *
00082 dxf_object_init
00083 (
00084         DxfObject *object
00086 )
00087 {
00088 #if DEBUG
00089         DXF_DEBUG_BEGIN
00090 #endif
00091         int i;
00092 
00093         /* Do some basic checks. */
00094         if (object == NULL)
00095         {
00096                 fprintf (stderr,
00097                   (_("Warning in %s () a NULL pointer was passed.\n")),
00098                   __FUNCTION__);
00099                 object = dxf_object_new ();
00100         }
00101         if (object == NULL)
00102         {
00103               fprintf (stderr,
00104                 (_("Error in %s () could not allocate memory for a DxfObject struct.\n")),
00105                 __FUNCTION__);
00106               return (NULL);
00107         }
00108         object->entity_type = UNKNOWN_ENTITY;
00109         for (i = 0; i < DXF_MAX_PARAM; i++)
00110         {
00112         }
00113         object->next = NULL;
00114 #if DEBUG
00115         DXF_DEBUG_END
00116 #endif
00117         return (object);
00118 }
00119 
00120 
00126 int
00127 dxf_object_write_objects
00128 (
00129         DxfFile *fp,
00131         DxfObject *dxf_objects_list
00133 )
00134 {
00135 #if DEBUG
00136         DXF_DEBUG_BEGIN
00137 #endif
00138 
00139 #if DEBUG
00140         DXF_DEBUG_END
00141 #endif
00142         return (EXIT_SUCCESS);
00143 }
00144 
00145 
00153 int
00154 dxf_object_free
00155 (
00156         DxfObject *object
00159 )
00160 {
00161 #if DEBUG
00162         DXF_DEBUG_BEGIN
00163 #endif
00164         /* Do some basic checks. */
00165         if (object == NULL)
00166         {
00167                 fprintf (stderr,
00168                   (_("Error in %s () a NULL pointer was passed.\n")),
00169                   __FUNCTION__);
00170                 return (EXIT_FAILURE);
00171         }
00172         if (object->next != NULL)
00173         {
00174                 fprintf (stderr,
00175                   (_("Error in %s () pointer to next was not NULL.\n")),
00176                   __FUNCTION__);
00177                 return (EXIT_FAILURE);
00178         }
00179         free (object);
00180         object = NULL;
00181 #if DEBUG
00182         DXF_DEBUG_END
00183 #endif
00184         return (EXIT_SUCCESS);
00185 }
00186 
00187 
00193 void
00194 dxf_object_free_chain
00195 (
00196         DxfObject *objects
00198 )
00199 {
00200 #ifdef DEBUG
00201         DXF_DEBUG_BEGIN
00202 #endif
00203         if (objects == NULL)
00204         {
00205                 fprintf (stderr,
00206                   (_("Warning in %s () a NULL pointer was passed.\n")),
00207                   __FUNCTION__);
00208         }
00209         while (objects != NULL)
00210         {
00211                 struct DxfObject *iter = objects->next;
00212                 dxf_object_free (objects);
00213                 objects = (DxfObject *) iter;
00214         }
00215 #if DEBUG
00216         DXF_DEBUG_END
00217 #endif
00218 }
00219 
00220 
00228 DxfEntityType *
00229 dxf_object_get_entity_type
00230 (
00231         DxfObject *object
00233 )
00234 {
00235 #if DEBUG
00236         DXF_DEBUG_BEGIN
00237 #endif
00238         /* Do some basic checks. */
00239         if (object == NULL)
00240         {
00241                 fprintf (stderr,
00242                   (_("Error in %s () a NULL pointer was passed.\n")),
00243                   __FUNCTION__);
00244                 return (NULL);
00245         }
00246         if (object->entity_type == 0)
00247         {
00248                 fprintf (stderr,
00249                   (_("Warning in %s () a zero value was found.\n")),
00250                   __FUNCTION__);
00251         }
00252 #if DEBUG
00253         DXF_DEBUG_END
00254 #endif
00255         return ((DxfEntityType *) object->entity_type);
00256 }
00257 
00258 
00262 DxfObject *
00263 dxf_object_set_entity_type
00264 (
00265         DxfObject *object,
00267         DxfEntityType entity_type
00270 )
00271 {
00272 #if DEBUG
00273         DXF_DEBUG_BEGIN
00274 #endif
00275         /* Do some basic checks. */
00276         if (object == NULL)
00277         {
00278                 fprintf (stderr,
00279                   (_("Error in %s () a NULL pointer was passed.\n")),
00280                   __FUNCTION__);
00281                 return (NULL);
00282         }
00283         if (entity_type == 0)
00284         {
00285                 fprintf (stderr,
00286                   (_("Error in %s () a NULL pointer was passed.\n")),
00287                   __FUNCTION__);
00288                 return (NULL);
00289         }
00290         object->entity_type = entity_type;
00291 #if DEBUG
00292         DXF_DEBUG_END
00293 #endif
00294         return (object);
00295 }
00296 
00297 
00306 DxfObject *
00307 dxf_object_get_next
00308 (
00309         DxfObject *object
00311 )
00312 {
00313 #if DEBUG
00314         DXF_DEBUG_BEGIN
00315 #endif
00316         /* Do some basic checks. */
00317         if (object == NULL)
00318         {
00319                 fprintf (stderr,
00320                   (_("Error in %s () a NULL pointer was passed.\n")),
00321                   __FUNCTION__);
00322                 return (NULL);
00323         }
00324         if (object->next == NULL)
00325         {
00326                 fprintf (stderr,
00327                   (_("Error in %s () a NULL pointer was found.\n")),
00328                   __FUNCTION__);
00329                 return (NULL);
00330         }
00331 #if DEBUG
00332         DXF_DEBUG_END
00333 #endif
00334         return ((DxfObject *) object->next);
00335 }
00336 
00337 
00342 DxfObject *
00343 dxf_object_set_next
00344 (
00345         DxfObject *object,
00347         DxfObject *next
00349 )
00350 {
00351 #if DEBUG
00352         DXF_DEBUG_BEGIN
00353 #endif
00354         /* Do some basic checks. */
00355         if (object == NULL)
00356         {
00357                 fprintf (stderr,
00358                   (_("Error in %s () a NULL pointer was passed.\n")),
00359                   __FUNCTION__);
00360                 return (NULL);
00361         }
00362         if (next == NULL)
00363         {
00364                 fprintf (stderr,
00365                   (_("Error in %s () a NULL pointer was passed.\n")),
00366                   __FUNCTION__);
00367                 return (NULL);
00368         }
00369         object->next = (struct DxfObject *) next;
00370 #if DEBUG
00371         DXF_DEBUG_END
00372 #endif
00373         return (object);
00374 }
00375 
00376 
00385 DxfObject *
00386 dxf_object_get_last
00387 (
00388         DxfObject *object
00390 )
00391 {
00392 #if DEBUG
00393         DXF_DEBUG_BEGIN
00394 #endif
00395         /* Do some basic checks. */
00396         if (object == NULL)
00397         {
00398                 fprintf (stderr,
00399                   (_("Error in %s () a NULL pointer was passed.\n")),
00400                   __FUNCTION__);
00401                 return (NULL);
00402         }
00403         if (object->next == NULL)
00404         {
00405                 fprintf (stderr,
00406                   (_("Warning in %s () a NULL pointer was found.\n")),
00407                   __FUNCTION__);
00408                 return ((DxfObject *) object);
00409         }
00410         DxfObject *iter = (DxfObject *) object->next;
00411         while (iter->next != NULL)
00412         {
00413                 iter = (DxfObject *) iter->next;
00414         }
00415 #if DEBUG
00416         DXF_DEBUG_END
00417 #endif
00418         return ((DxfObject *) iter);
00419 }
00420 
00421 
00422 /* EOF */