00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include "scbpoints.h"
00024 #include "scbtype.h"
00025 #include "scblog.h"
00026 #include "scbconfig.h"
00027
00028
00029
00030
00031
00032 gboolean scb_points_new(ScbPointsPtr ptr, const int initSize)
00033 {
00034 SCB_RET_FALSE_IF(NULL == ptr, "Invalid pointer!");
00035 SCB_RET_FALSE_IF(initSize <= 0, "Invalid initial size!");
00036
00037 ptr->points = g_array_sized_new(FALSE, TRUE, sizeof(ScbPoint), initSize);
00038
00039 SCB_RET_FALSE_IF(NULL == ptr->points, "Could not allocate enough memory!");
00040 ptr->pressures = g_array_sized_new(FALSE, TRUE, sizeof(int), initSize);
00041
00042 if (NULL == ptr->pressures)
00043 {
00044 g_free(ptr->points); ptr->points = NULL;
00045 return FALSE;
00046 }
00047 return TRUE;
00048 }
00049
00050
00051
00052 void scb_points_free(ScbPointsPtr ptr)
00053 {
00054 SCB_RET_IF(NULL == ptr, "Try to release NULL pointer!");
00055
00056 g_array_free(ptr->points, TRUE);
00057 g_array_free(ptr->pressures, TRUE);
00058 ptr->points = NULL;
00059 ptr->pressures = NULL;
00060 }
00061
00062
00063
00064 void scb_points_append(ScbPointsPtr points, ScbDevPointPtr point)
00065 {
00066
00067 SCB_RET_IF(NULL == points || NULL == point, "Invalid pointer(s)!");
00068
00069
00070 g_array_append_val(points->points, *((ScbPointPtr)point));
00071 g_array_append_val(points->pressures, point->pressure);
00072 }
00073
00074
00075
00076 int scb_points_get_count(ScbPointsPtr ptr)
00077 {
00078 SCB_RET_INT_IF(NULL == ptr, SCB_INVALID_COUNT, "Attempt to access NULL pointer!");
00079 SCB_RET_INT_IF(NULL == ptr->points, SCB_INVALID_COUNT, "Point array is not allocated!");
00080
00081 return ptr->points->len;
00082 }
00083
00084
00085
00086 ScbPointPtr scb_points_get_data(ScbPointsPtr ptr)
00087 {
00088 SCB_RET_NULL_IF(NULL == ptr || NULL == ptr->points, "NULL pointer(s)");
00089 return (ScbPointPtr)ptr->points->data;
00090 }
00091
00092
00093 void scb_points_dump(ScbPointsPtr ptr)
00094 {
00095 ScbPointPtr point = scb_points_get_data(ptr);
00096 SCB_RET_IF(NULL == point, "");
00097
00098 int len = scb_points_get_count(ptr);
00099 SCB_DUMP("points count %d. data:", len);
00100 while (len > 0)
00101 {
00102 SCB_DUMP("(%d, %d)", point->x, point->y);
00103 ++point; --len;
00104 }
00105 }