scbpoints.c

Go to the documentation of this file.
00001 /*
00002  * File Name: scbpoints.c
00003  */
00004 
00005 /*
00006  * This file is part of liberscribble.
00007  *
00008  * liberscribble is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * liberscribble is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 
00028 #define _GNU_SOURCE
00029 
00030 //----------------------------------------------------------------------------
00031 // Include Files
00032 //----------------------------------------------------------------------------
00033 
00034 // system include files, between < >
00035 
00036 // ereader include files, between < >
00037 
00038 // local include files, between " "
00039 #include "scbpoints.h"
00040 #include "scbtype.h"
00041 #include "scblog.h"
00042 #include "scbconfig.h"
00043 
00044 
00045 //----------------------------------------------------------------------------
00046 // Type Declarations
00047 //----------------------------------------------------------------------------
00048 
00049 
00050 //----------------------------------------------------------------------------
00051 // Global Constants
00052 //----------------------------------------------------------------------------
00053 
00054 
00055 //----------------------------------------------------------------------------
00056 // Static Variables
00057 //----------------------------------------------------------------------------
00058 
00059 
00060 //============================================================================
00061 // Local Function Definitions
00062 //============================================================================
00063 
00064 
00065 //============================================================================
00066 // Functions Implementation
00067 //============================================================================
00068 
00069 gboolean erscribble_points_new(ScbPointsPtr ptr, const int initSize)
00070 {
00071     ERSCRIBBLE_RET_FALSE_IF(NULL == ptr, "Invalid pointer!");
00072     ERSCRIBBLE_RET_FALSE_IF(initSize <= 0, "Invalid initial size!");
00073         
00074     ptr->points = g_array_sized_new(FALSE, TRUE, sizeof(ScbPoint), initSize);
00075 
00076     ERSCRIBBLE_RET_FALSE_IF(NULL == ptr->points, "Could not allocate enough memory!");
00077     ptr->pressures = g_array_sized_new(FALSE, TRUE, sizeof(int), initSize);
00078     
00079     if (NULL == ptr->pressures)
00080     {
00081         g_free(ptr->points); ptr->points = NULL;
00082         return FALSE;
00083     }
00084     return TRUE;
00085 }
00086 
00087 
00088 void erscribble_points_free(ScbPointsPtr ptr)
00089 {
00090     ERSCRIBBLE_RET_IF(NULL == ptr, "Try to release NULL pointer!");
00091 
00092     if (ptr->points != NULL)
00093     {
00094         g_array_free(ptr->points, TRUE);
00095         ptr->points = NULL;
00096     }
00097 
00098     if (ptr->pressures != NULL)
00099     {
00100         g_array_free(ptr->pressures, TRUE);
00101         ptr->pressures = NULL;
00102     }
00103 }
00104 
00105 
00106 void erscribble_points_append(ScbPointsPtr points, ScbDevPointPtr point)
00107 {
00108     ERSCRIBBLE_RET_IF(NULL == points || NULL == point, "Invalid pointer(s)!");
00109         
00110     // by value. they are binary compatible
00111     g_array_append_val(points->points, *((ScbPointPtr)point));
00112     g_array_append_val(points->pressures, point->pressure);
00113 }
00114 
00115 
00116 int erscribble_points_get_count(ScbPointsPtr ptr)
00117 {
00118     ERSCRIBBLE_RET_INT_IF(NULL == ptr, ERSCRIBBLE_INVALID_COUNT, "Attempt to access NULL pointer!");
00119     ERSCRIBBLE_RET_INT_IF(NULL == ptr->points, ERSCRIBBLE_INVALID_COUNT, "Point array is not allocated!");
00120     
00121     // lengths are equal
00122     return ptr->points->len;
00123 }
00124 
00125 
00126 ScbPointPtr erscribble_points_get_data(ScbPointsPtr ptr)
00127 {
00128     ERSCRIBBLE_RET_NULL_IF(NULL == ptr || NULL == ptr->points, "NULL pointer(s)");
00129     return (ScbPointPtr)ptr->points->data;
00130 }
00131 
00132 
00133 void erscribble_points_dump(ScbPointsPtr ptr)
00134 {
00135     ScbPointPtr point = erscribble_points_get_data(ptr);
00136     ERSCRIBBLE_RET_IF(NULL == point, "");
00137     
00138     int len = erscribble_points_get_count(ptr);
00139     DUMPPRINTF("points count %d. data:", len);
00140     while (len > 0)
00141     {
00142         DUMPPRINTF("(%d, %d)", point->x, point->y);
00143         ++point; --len;
00144     }
00145 }
Generated by  doxygen 1.6.2-20100208