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

object_id.c

Go to the documentation of this file.
00001 
00035 #include "object_id.h"
00036 
00037 
00043 DxfObjectId *
00044 dxf_object_id_new ()
00045 {
00046 #if DEBUG
00047         DXF_DEBUG_BEGIN
00048 #endif
00049         DxfObjectId *object_id = NULL;
00050         size_t size;
00051 
00052         size = sizeof (DxfObjectId);
00053         /* avoid malloc of 0 bytes */
00054         if (size == 0) size = 1;
00055         if ((object_id = malloc (size)) == NULL)
00056         {
00057                 fprintf (stderr,
00058                   (_("Error in %s () could not allocate memory for a DxfObjectId struct.\n")),
00059                   __FUNCTION__);
00060                 object_id = NULL;
00061         }
00062         else
00063         {
00064                 memset (object_id, 0, size);
00065         }
00066 #if DEBUG
00067         DXF_DEBUG_END
00068 #endif
00069         return (object_id);
00070 }
00071 
00072 
00080 DxfObjectId *
00081 dxf_object_id_init
00082 (
00083         DxfObjectId *object_id
00085 )
00086 {
00087 #if DEBUG
00088         DXF_DEBUG_BEGIN
00089 #endif
00090         /* Do some basic checks. */
00091         if (object_id == NULL)
00092         {
00093                 fprintf (stderr,
00094                   (_("Warning in %s () a NULL pointer was passed.\n")),
00095                   __FUNCTION__);
00096                 object_id = dxf_object_id_new ();
00097         }
00098         if (object_id == NULL)
00099         {
00100               fprintf (stderr,
00101                 (_("Error in %s () could not allocate memory for a DxfObjectId struct.\n")),
00102                 __FUNCTION__);
00103               return (NULL);
00104         }
00105         object_id->data = strdup ("");
00106         object_id->next = NULL;
00107 #if DEBUG
00108         DXF_DEBUG_END
00109 #endif
00110         return (object_id);
00111 }
00112 
00113 
00121 int
00122 dxf_object_id_free
00123 (
00124         DxfObjectId *object_id
00127 )
00128 {
00129 #if DEBUG
00130         DXF_DEBUG_BEGIN
00131 #endif
00132         /* Do some basic checks. */
00133         if (object_id == NULL)
00134         {
00135                 fprintf (stderr,
00136                   (_("Error in %s () a NULL pointer was passed.\n")),
00137                   __FUNCTION__);
00138                 return (EXIT_FAILURE);
00139         }
00140         if (object_id->next != NULL)
00141         {
00142                 fprintf (stderr,
00143                   (_("Error in %s () pointer to next was not NULL.\n")),
00144                   __FUNCTION__);
00145                 return (EXIT_FAILURE);
00146         }
00147         free (object_id->data);
00148         free (object_id);
00149         object_id = NULL;
00150 #if DEBUG
00151         DXF_DEBUG_END
00152 #endif
00153         return (EXIT_SUCCESS);
00154 }
00155 
00156 
00161 void
00162 dxf_object_id_free_chain
00163 (
00164         DxfObjectId *object_ids
00166 )
00167 {
00168 #ifdef DEBUG
00169         DXF_DEBUG_BEGIN
00170 #endif
00171         if (object_ids == NULL)
00172         {
00173                 fprintf (stderr,
00174                   (_("Warning in %s () a NULL pointer was passed.\n")),
00175                   __FUNCTION__);
00176         }
00177         while (object_ids != NULL)
00178         {
00179                 struct DxfObjectId *iter = object_ids->next;
00180                 dxf_object_id_free (object_ids);
00181                 object_ids = (DxfObjectId *) iter;
00182         }
00183 #if DEBUG
00184         DXF_DEBUG_END
00185 #endif
00186 }
00187 
00188 
00194 int
00195 dxf_object_id_get_group_code
00196 (
00197         DxfObjectId *object_id
00199 )
00200 {
00201 #if DEBUG
00202         DXF_DEBUG_BEGIN
00203 #endif
00204         /* Do some basic checks. */
00205         if (object_id == NULL)
00206         {
00207                 fprintf (stderr,
00208                   (_("Error in %s () a NULL pointer was passed.\n")),
00209                   __FUNCTION__);
00210                 return (EXIT_FAILURE);
00211         }
00212         if ((object_id->group_code != 330)
00213           && (object_id->group_code != 340)
00214           && (object_id->group_code != 350)
00215           && (object_id->group_code != 360))
00216         {
00217                 fprintf (stderr,
00218                   (_("Error in %s () an invalid value was found in the group_code member.\n")),
00219                   __FUNCTION__);
00220                 return (EXIT_FAILURE);
00221         }
00222 #if DEBUG
00223         DXF_DEBUG_END
00224 #endif
00225         return (object_id->group_code);
00226 }
00227 
00228 
00235 DxfObjectId *
00236 dxf_object_id_set_group_code
00237 (
00238         DxfObjectId *object_id,
00240         int group_code
00242 )
00243 {
00244 #if DEBUG
00245         DXF_DEBUG_BEGIN
00246 #endif
00247         /* Do some basic checks. */
00248         if (object_id == NULL)
00249         {
00250                 fprintf (stderr,
00251                   (_("Error in %s () a NULL pointer was passed.\n")),
00252                   __FUNCTION__);
00253                 return (NULL);
00254         }
00255         if ((group_code != 330)
00256           && (group_code != 340)
00257           && (group_code != 350)
00258           && (group_code != 360))
00259         {
00260                 fprintf (stderr,
00261                   (_("Error in %s () an invalid group_code value was passed.\n")),
00262                   __FUNCTION__);
00263                 return (NULL);
00264         }
00265         object_id->group_code = group_code;
00266 #if DEBUG
00267         DXF_DEBUG_END
00268 #endif
00269         return (object_id);
00270 }
00271 
00272 
00278 char *
00279 dxf_object_id_get_data
00280 (
00281         DxfObjectId *object_id
00283 )
00284 {
00285 #if DEBUG
00286         DXF_DEBUG_BEGIN
00287 #endif
00288         /* Do some basic checks. */
00289         if (object_id == NULL)
00290         {
00291                 fprintf (stderr,
00292                   (_("Error in %s () a NULL pointer was passed.\n")),
00293                   __FUNCTION__);
00294                 return (NULL);
00295         }
00296         if (object_id->data ==  NULL)
00297         {
00298                 fprintf (stderr,
00299                   (_("Error in %s () a NULL pointer was found in the data member.\n")),
00300                   __FUNCTION__);
00301                 return (NULL);
00302         }
00303 #if DEBUG
00304         DXF_DEBUG_END
00305 #endif
00306         return (strdup (object_id->data));
00307 }
00308 
00309 
00313 DxfObjectId *
00314 dxf_object_id_set_data
00315 (
00316         DxfObjectId *object_id,
00318         char *data
00320 )
00321 {
00322 #if DEBUG
00323         DXF_DEBUG_BEGIN
00324 #endif
00325         /* Do some basic checks. */
00326         if (object_id == NULL)
00327         {
00328                 fprintf (stderr,
00329                   (_("Error in %s () a NULL pointer was passed.\n")),
00330                   __FUNCTION__);
00331                 return (NULL);
00332         }
00333         if (data == NULL)
00334         {
00335                 fprintf (stderr,
00336                   (_("Error in %s () a NULL pointer was passed.\n")),
00337                   __FUNCTION__);
00338                 return (NULL);
00339         }
00340         object_id->data = strdup (data);
00341 #if DEBUG
00342         DXF_DEBUG_END
00343 #endif
00344         return (object_id);
00345 }
00346 
00347 
00353 int
00354 dxf_object_id_get_length
00355 (
00356         DxfObjectId *object_id
00358 )
00359 {
00360 #if DEBUG
00361         DXF_DEBUG_BEGIN
00362 #endif
00363         /* Do some basic checks. */
00364         if (object_id == NULL)
00365         {
00366                 fprintf (stderr,
00367                   (_("Error in %s () a NULL pointer was passed.\n")),
00368                   __FUNCTION__);
00369                 return (EXIT_FAILURE);
00370         }
00371         if (object_id->length < 0)
00372         {
00373                 fprintf (stderr,
00374                   (_("Error in %s () a negative value was found in the length member.\n")),
00375                   __FUNCTION__);
00376                 return (EXIT_FAILURE);
00377         }
00378 #if DEBUG
00379         DXF_DEBUG_END
00380 #endif
00381         return (object_id->length);
00382 }
00383 
00384 
00391 DxfObjectId *
00392 dxf_object_id_set_length
00393 (
00394         DxfObjectId *object_id,
00396         int length
00398 )
00399 {
00400 #if DEBUG
00401         DXF_DEBUG_BEGIN
00402 #endif
00403         /* Do some basic checks. */
00404         if (object_id == NULL)
00405         {
00406                 fprintf (stderr,
00407                   (_("Error in %s () a NULL pointer was passed.\n")),
00408                   __FUNCTION__);
00409                 return (NULL);
00410         }
00411         if (length < 0)
00412         {
00413                 fprintf (stderr,
00414                   (_("Error in %s () a negative length value was passed.\n")),
00415                   __FUNCTION__);
00416                 return (NULL);
00417         }
00418         object_id->length = length;
00419 #if DEBUG
00420         DXF_DEBUG_END
00421 #endif
00422         return (object_id);
00423 }
00424 
00425 
00434 DxfObjectId *
00435 dxf_object_id_get_next
00436 (
00437         DxfObjectId *object_id
00439 )
00440 {
00441 #if DEBUG
00442         DXF_DEBUG_BEGIN
00443 #endif
00444         /* Do some basic checks. */
00445         if (object_id == NULL)
00446         {
00447                 fprintf (stderr,
00448                   (_("Error in %s () a NULL pointer was passed.\n")),
00449                   __FUNCTION__);
00450                 return (NULL);
00451         }
00452         if (object_id->next == NULL)
00453         {
00454                 fprintf (stderr,
00455                   (_("Error in %s () a NULL pointer was found in the next member.\n")),
00456                   __FUNCTION__);
00457                 return (NULL);
00458         }
00459 #if DEBUG
00460         DXF_DEBUG_END
00461 #endif
00462         return ((DxfObjectId *) object_id->next);
00463 }
00464 
00465 
00470 DxfObjectId *
00471 dxf_object_id_set_next
00472 (
00473         DxfObjectId *object_id,
00475         DxfObjectId *next
00478 )
00479 {
00480 #if DEBUG
00481         DXF_DEBUG_BEGIN
00482 #endif
00483         /* Do some basic checks. */
00484         if (object_id == NULL)
00485         {
00486                 fprintf (stderr,
00487                   (_("Error in %s () a NULL pointer was passed.\n")),
00488                   __FUNCTION__);
00489                 return (NULL);
00490         }
00491         if (next == NULL)
00492         {
00493                 fprintf (stderr,
00494                   (_("Error in %s () a NULL pointer was passed.\n")),
00495                   __FUNCTION__);
00496                 return (NULL);
00497         }
00498         object_id->next = (struct DxfObjectId *) next;
00499 #if DEBUG
00500         DXF_DEBUG_END
00501 #endif
00502         return (object_id);
00503 }
00504 
00505 
00514 DxfObjectId *
00515 dxf_object_id_get_last
00516 (
00517         DxfObjectId *object_id
00519 )
00520 {
00521 #if DEBUG
00522         DXF_DEBUG_BEGIN
00523 #endif
00524         /* Do some basic checks. */
00525         if (object_id == NULL)
00526         {
00527                 fprintf (stderr,
00528                   (_("Error in %s () a NULL pointer was passed.\n")),
00529                   __FUNCTION__);
00530                 return (NULL);
00531         }
00532         if (object_id->next == NULL)
00533         {
00534                 fprintf (stderr,
00535                   (_("Warning in %s () a NULL pointer was found in the next member.\n")),
00536                   __FUNCTION__);
00537                 return ((DxfObjectId *) object_id);
00538         }
00539         DxfObjectId *iter = (DxfObjectId *) object_id->next;
00540         while (iter->next != NULL)
00541         {
00542                 iter = (DxfObjectId *) iter->next;
00543         }
00544 #if DEBUG
00545         DXF_DEBUG_END
00546 #endif
00547         return ((DxfObjectId *) iter);
00548 }
00549 
00550 
00551 /* EOF */