metadata_cell.h File Reference

#include <glib.h>
Include dependency graph for metadata_cell.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  metadata_cell

Defines

#define metadata_cell_set_null(cell)   metadata_cell_clear_value(cell)
 Assign a NULL value to a metadata_cell.

Enumerations

enum  metadata_cell_type {
  METADATA_NULL = 0, METADATA_INT64, METADATA_DOUBLE, METADATA_TEXT,
  METADATA_BLOB, NUM_METADATA_TYPES
}

Functions

void metadata_cell_clear (metadata_cell *thiz)
 Clear the content (name, value) of a metadata_cell.
void metadata_cell_clear_value (metadata_cell *thiz)
 Clear the value of a metadata_cell, leave its name as is.
int metadata_cell_copy_value (metadata_cell *thiz, const metadata_cell *src)
 Copy the value of a metadata_cell, leave target name as is.
int metadata_cell_set_name (metadata_cell *thiz, const char *name)
 Set the name of a metadata_cell.
int metadata_cell_set_int64 (metadata_cell *thiz, const gint64 value)
 Assign an integer value to a metadata_cell.
int metadata_cell_set_double (metadata_cell *thiz, const double value)
 Assign a floating point value to a metadata_cell.
int metadata_cell_set_text (metadata_cell *thiz, const char *value)
 Assign a string value to a metadata_cell.
int metadata_cell_set_blob (metadata_cell *thiz, gchar *value, const guint len)
 Assign a blob to a metadata_cell BLOB = Binary Large OBject.
int metadata_cell_set_blob_static (metadata_cell *thiz, const gchar *value, const guint len)
 Assign a blob to a metadata_cell, assuming blob is static data BLOB = Binary Large OBject.
GString * metadata_cell_get_string (const metadata_cell *thiz)
 Report the value of a metadata_cell converted to a UTF-8 text string Not possible for SQLCELL_BLOB types.

Define Documentation

#define metadata_cell_set_null ( cell   )     metadata_cell_clear_value(cell)

Assign a NULL value to a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_set_null

Parameters:
thiz - the metadata_cell
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 150 of file metadata_cell.h.

Referenced by metadata_cell_copy_value(), and metadata_cell_set_value().


Enumeration Type Documentation

File Name : metadata_cell.h

Description: Data for single cell in a metadata table. This type is designed for easy compatibility with sqlite3. Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Enumerator:
METADATA_NULL 
METADATA_INT64 
METADATA_DOUBLE 
METADATA_TEXT 
METADATA_BLOB 
NUM_METADATA_TYPES 

Definition at line 46 of file metadata_cell.h.

00047 {
00048     METADATA_NULL = 0,          // SQLCELL_NULL must be zero for easy init
00049     METADATA_INT64,
00050     METADATA_DOUBLE,
00051     METADATA_TEXT,
00052     METADATA_BLOB,
00053     NUM_METADATA_TYPES
00054 } metadata_cell_type;


Function Documentation

void metadata_cell_clear ( metadata_cell thiz  ) 

Clear the content (name, value) of a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_clear

Parameters:
thiz - the metadata_cell
Returns:
--

--------------------------------------------------------------------------

Definition at line 49 of file metadata_cell.c.

References metadata_cell_clear_value(), and metadata_cell::name.

Referenced by metadata_cell_set_value(), and metadata_table_free_impl().

00050 {
00051     g_return_if_fail(thiz);
00052 
00053     if (thiz->name)
00054     {
00055         g_string_free(thiz->name, TRUE);
00056         thiz->name = NULL;
00057     }
00058 
00059     metadata_cell_clear_value(thiz);
00060 }

Here is the call graph for this function:

Here is the caller graph for this function:

void metadata_cell_clear_value ( metadata_cell thiz  ) 

Clear the value of a metadata_cell, leave its name as is.

---------------------------------------------------------------------------

Name : metadata_cell_clear_value

Parameters:
thiz - the metadata_cell
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 63 of file metadata_cell.c.

References LOGPRINTF, METADATA_BLOB, METADATA_NULL, METADATA_TEXT, metadata_cell::type, metadata_cell::v_blob, metadata_cell::v_text, and metadata_cell::value.

Referenced by add_row_if_needed(), metadata_cell_clear(), metadata_cell_set_blob(), metadata_cell_set_blob_static(), metadata_cell_set_double(), metadata_cell_set_int64(), and metadata_cell_set_text().

00064 {
00065     LOGPRINTF("entry: thiz [%p]", thiz);
00066     g_return_if_fail(thiz);
00067 
00068     // release value
00069     switch (thiz->type)
00070     {
00071         case METADATA_TEXT:
00072             g_string_free(thiz->value.v_text, TRUE);
00073             break;
00074         case METADATA_BLOB:
00075             if ( thiz->value.v_blob.data_is_static == FALSE )
00076             {
00077                 g_free( (gchar*)(thiz->value.v_blob.data) );
00078             }
00079             thiz->value.v_blob.len = 0;
00080             break;
00081         default:
00082             ; //ignore
00083     }
00084 
00085     // set type to "empty"
00086     thiz->type = METADATA_NULL;
00087 }

Here is the caller graph for this function:

int metadata_cell_copy_value ( metadata_cell thiz,
const metadata_cell src 
)

Copy the value of a metadata_cell, leave target name as is.

---------------------------------------------------------------------------

Name : metadata_cell_copy_value

Parameters:
[out] thiz - the metadata_cell to copy into
[in] src - the metadata_cell to copy from
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 90 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, ERRORPRINTF, LOGPRINTF, METADATA_BLOB, metadata_cell_set_blob(), metadata_cell_set_double(), metadata_cell_set_int64(), metadata_cell_set_null, metadata_cell_set_text(), METADATA_DOUBLE, METADATA_INT64, METADATA_NULL, METADATA_TEXT, metadata_cell::type, metadata_cell::v_blob, metadata_cell::v_double, metadata_cell::v_int64, metadata_cell::v_text, and metadata_cell::value.

Referenced by metadata_table_set_cell().

00091 {
00092     int   ret = ER_OK; // return value
00093     int   len;
00094     gchar *blob;
00095 
00096     LOGPRINTF("entry: thiz [%p] src [%p]", thiz, src);
00097     g_return_val_if_fail(thiz, ER_INVALID_PARAMETER);
00098     g_return_val_if_fail(src,  ER_INVALID_PARAMETER);
00099 
00100     switch (src->type)
00101     {
00102         case METADATA_NULL:
00103             metadata_cell_set_null(thiz);
00104             break;
00105         case METADATA_INT64:
00106             metadata_cell_set_int64(thiz, src->value.v_int64);
00107             break;
00108         case METADATA_DOUBLE:
00109             metadata_cell_set_double(thiz, src->value.v_double);
00110             break;
00111         case METADATA_TEXT:
00112             metadata_cell_set_text(thiz, src->value.v_text->str);
00113             break;
00114         case METADATA_BLOB:
00115             // note: metadata_cell_set_blob takes ownership of blob,
00116             //       so we must pass it a copy of the blob data
00117             len  = src->value.v_blob.len;
00118             blob = g_malloc(len);
00119             g_assert(blob);
00120             memcpy(blob, src->value.v_blob.data, len);
00121             metadata_cell_set_blob(thiz, blob, len);
00122             break;
00123         default:
00124             ERRORPRINTF("unknown cell type [%d]", src->type);
00125             metadata_cell_set_null(thiz);
00126             ret = ER_INVALID_PARAMETER;
00127     }
00128 
00129     return ret;
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:

GString* metadata_cell_get_string ( const metadata_cell thiz  ) 

Report the value of a metadata_cell converted to a UTF-8 text string Not possible for SQLCELL_BLOB types.

---------------------------------------------------------------------------

Name : metadata_cell_get_string

Parameters:
thiz - the metadata_cell
Returns:
cell value as a zero-terminated GString, or NULL when error caller must release this GString using g_string_free(string, TRUE)

--------------------------------------------------------------------------

Definition at line 299 of file metadata_cell.c.

References ERRORPRINTF, LOGPRINTF, METADATA_DOUBLE, METADATA_INT64, METADATA_NULL, METADATA_TEXT, metadata_cell::type, metadata_cell::v_double, metadata_cell::v_int64, metadata_cell::v_text, and metadata_cell::value.

Referenced by metadata_table_get_string().

00300 {
00301     LOGPRINTF("entry: thiz [%p]", thiz);
00302     g_return_val_if_fail(thiz, NULL);
00303 
00304     // get cell value and convert
00305     GString *string = g_string_new("");
00306     switch (thiz->type)
00307     {
00308         case METADATA_INT64:
00309             g_string_printf(string, "%lld", thiz->value.v_int64);
00310             break;
00311         case METADATA_DOUBLE:
00312             g_string_printf(string, "%f", thiz->value.v_double);
00313             break;
00314         case METADATA_TEXT:
00315             g_string_assign(string, thiz->value.v_text->str);
00316             break;
00317         default:
00318             if (thiz->type != METADATA_NULL)
00319             {
00320                 ERRORPRINTF("pid [%lld] cannot convert type [%d] to string", (gint64)getpid(), thiz->type); 
00321             }
00322             g_string_free(string, TRUE);
00323             string = NULL;
00324     }
00325 
00326     return string;
00327 }

Here is the caller graph for this function:

int metadata_cell_set_blob ( metadata_cell thiz,
gchar *  value,
const guint  len 
)

Assign a blob to a metadata_cell BLOB = Binary Large OBject.

---------------------------------------------------------------------------

Name : metadata_cell_set_blob

Parameters:
thiz - the metadata_cell
[in] value - binary value Note: The value is "swallowed" by the metadata_cell so caller looses ownership and must drop all pointers to it. The metadata_cell will eventually release it with g_free() so caller must have allocated it with g_new() or g_malloc().
[in] len - length of value in bytes
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 260 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, METADATA_BLOB, metadata_cell_clear_value(), metadata_cell::type, metadata_cell::v_blob, and metadata_cell::value.

Referenced by metadata_cell_copy_value(), metadata_cell_set_value(), and metadata_table_set_blob().

00261 {
00262     LOGPRINTF("entry: thiz [%p] value [%p]", thiz, value);
00263     g_return_val_if_fail(thiz,  ER_INVALID_PARAMETER);
00264     g_return_val_if_fail(value, ER_INVALID_PARAMETER);
00265 
00266     metadata_cell_clear_value(thiz);
00267 
00268     // store pointer to blob value
00269     thiz->type = METADATA_BLOB;
00270     thiz->value.v_blob.data = value;
00271     thiz->value.v_blob.len  = len;
00272 
00273     // remember to release this data
00274     thiz->value.v_blob.data_is_static = FALSE;;
00275 
00276     return ER_OK;
00277 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_cell_set_blob_static ( metadata_cell thiz,
const gchar *  value,
const guint  len 
)

Assign a blob to a metadata_cell, assuming blob is static data BLOB = Binary Large OBject.

---------------------------------------------------------------------------

Name : metadata_cell_set_blob_static

Parameters:
thiz - the metadata_cell
[in] value - binary value Note: The metadata_cell will NOT release this memory block so caller must ensure the data stays available for as long as 'thiz' metadata_cell exists or until a new value is assigned to 'thiz' cell.
[in] len - length of value in bytes
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 280 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, METADATA_BLOB, metadata_cell_clear_value(), metadata_cell::type, metadata_cell::v_blob, and metadata_cell::value.

Referenced by metadata_table_set_blob_static().

00281 {
00282     LOGPRINTF("entry: thiz [%p] value [%p]", thiz, value);
00283     g_return_val_if_fail(thiz,  ER_INVALID_PARAMETER);
00284     g_return_val_if_fail(value, ER_INVALID_PARAMETER);
00285 
00286     metadata_cell_clear_value(thiz);
00287 
00288     // store pointer to blob value
00289     thiz->type = METADATA_BLOB;
00290     thiz->value.v_blob.data = value;
00291     thiz->value.v_blob.len  = len;
00292 
00293     // remember to leave this data as is, so NEVER release it
00294     thiz->value.v_blob.data_is_static = TRUE;
00295     return ER_OK;
00296 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_cell_set_double ( metadata_cell thiz,
const double  value 
)

Assign a floating point value to a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_set_double

Parameters:
thiz - the metadata_cell
[in] value - floating point value (double)
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 221 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, metadata_cell_clear_value(), METADATA_DOUBLE, metadata_cell::type, metadata_cell::v_double, and metadata_cell::value.

Referenced by metadata_cell_copy_value(), metadata_cell_set_value(), and metadata_table_set_double().

00222 {
00223     LOGPRINTF("entry: thiz [%p] value [%f]", thiz, value);
00224     g_return_val_if_fail(thiz, ER_INVALID_PARAMETER);
00225 
00226     metadata_cell_clear_value(thiz);
00227     thiz->type           = METADATA_DOUBLE;
00228     thiz->value.v_double = value;
00229 
00230     return ER_OK;
00231 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_cell_set_int64 ( metadata_cell thiz,
const gint64  value 
)

Assign an integer value to a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_set_int64

Parameters:
thiz - the metadata_cell
[in] value - integer value (gint64)
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 209 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, metadata_cell_clear_value(), METADATA_INT64, metadata_cell::type, metadata_cell::v_int64, and metadata_cell::value.

Referenced by metadata_cell_copy_value(), metadata_cell_set_value(), and metadata_table_set_int64().

00210 {
00211     LOGPRINTF("entry: thiz [%p] value [%lld]", thiz, value);
00212     g_return_val_if_fail(thiz, ER_INVALID_PARAMETER);
00213 
00214     metadata_cell_clear_value(thiz);
00215     thiz->type          = METADATA_INT64;
00216     thiz->value.v_int64 = value;
00217     return ER_OK;
00218 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_cell_set_name ( metadata_cell thiz,
const char *  name 
)

Set the name of a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_set_name

Parameters:
thiz - the metadata_cell
[in] name - the new cell-name, or NULL to clear name
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 133 of file metadata_cell.c.

References ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, and metadata_cell::name.

Referenced by metadata_table_add_column().

00134 {
00135     LOGPRINTF("entry: thiz [%p] name [%s]", thiz, name);
00136     g_return_val_if_fail(thiz, ER_INVALID_PARAMETER);
00137 
00138     if (thiz->name)
00139     {
00140         g_string_free(thiz->name, TRUE);
00141         thiz->name = NULL;
00142     }
00143 
00144     if (name)
00145     {
00146         thiz->name = g_string_new(name);
00147     }
00148 
00149     return ER_OK;
00150 }

Here is the caller graph for this function:

int metadata_cell_set_text ( metadata_cell thiz,
const char *  value 
)

Assign a string value to a metadata_cell.

---------------------------------------------------------------------------

Name : metadata_cell_set_text

Parameters:
thiz - the metadata_cell
[in] value - string value Note: The value is copied into metadata_cell so caller keeps ownership and must eventually free it.
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 234 of file metadata_cell.c.

References ER_FAIL, ER_INVALID_PARAMETER, ER_OK, ERRORPRINTF, LOGPRINTF, metadata_cell_clear_value(), METADATA_TEXT, metadata_cell::type, metadata_cell::v_text, and metadata_cell::value.

Referenced by metadata_cell_copy_value(), metadata_cell_set_value(), and metadata_table_set_text().

00235 {
00236     int ret = ER_OK;
00237 
00238     LOGPRINTF("entry: thiz [%p] value [%s]", thiz, value);
00239     g_return_val_if_fail(thiz,  ER_INVALID_PARAMETER);
00240     g_return_val_if_fail(value, ER_INVALID_PARAMETER);
00241 
00242     metadata_cell_clear_value(thiz);
00243 
00244     thiz->value.v_text = g_string_new(value);
00245     if (thiz->value.v_text == NULL)
00246     {
00247         ERRORPRINTF("cannot create GString");
00248         ret = ER_FAIL;
00249     }
00250     else
00251     {
00252         // string assignment ok
00253         thiz->type = METADATA_TEXT;
00254     }
00255 
00256     return ret;
00257 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208