metadata_cell.h

Go to the documentation of this file.
00001 #ifndef __METADATA_CELL_H__
00002 #define __METADATA_CELL_H__
00003 
00004 /**
00005  * File Name  : metadata_cell.h
00006  *
00007  * Description: Data for single cell in a metadata table.
00008  *              This type is designed for easy compatibility with sqlite3.
00009  */
00010 
00011 /*
00012  * This file is part of libermetadb.
00013  *
00014  * libermetadb is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU General Public License as published by
00016  * the Free Software Foundation, either version 2 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * libermetadb is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 /**
00029  * Copyright (C) 2008 iRex Technologies B.V.
00030  * All rights reserved.
00031  */
00032 
00033 
00034 //----------------------------------------------------------------------------
00035 // Include Files
00036 //----------------------------------------------------------------------------
00037 
00038 #include <glib.h>
00039 
00040 G_BEGIN_DECLS
00041 
00042 //----------------------------------------------------------------------------
00043 // Type Declarations
00044 //----------------------------------------------------------------------------
00045 
00046 typedef enum
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;
00055 
00056 
00057 typedef struct
00058 {
00059     GString             *name;          // optional
00060     metadata_cell_type  type;
00061     union
00062     {
00063         gint64          v_int64;
00064         gdouble         v_double;
00065         GString         *v_text;
00066         struct
00067         {
00068             guint       len;
00069             gboolean    data_is_static; // TRUE  : leave data block as is
00070                                         // FALSE : g_free() data when no longer needed
00071             const gchar *data;
00072         }               v_blob;
00073     }                   value;
00074 } metadata_cell;
00075 
00076 
00077 //============================================================================
00078 // Public Functions
00079 //============================================================================
00080 
00081 /**---------------------------------------------------------------------------
00082  *
00083  * Name :  metadata_cell_clear
00084  *
00085  * @brief  Clear the content (name, value) of a metadata_cell
00086  *
00087  * @param  thiz - the metadata_cell
00088  *
00089  * @return --
00090  *
00091  *--------------------------------------------------------------------------*/
00092 void metadata_cell_clear (metadata_cell *thiz);
00093 
00094 
00095 /**---------------------------------------------------------------------------
00096  *
00097  * Name :  metadata_cell_clear_value
00098  *
00099  * @brief  Clear the value of a metadata_cell, leave its name as is
00100  *
00101  * @param  thiz - the metadata_cell
00102  *
00103  * @return ER_OK or error code
00104  *
00105  *--------------------------------------------------------------------------*/
00106 void metadata_cell_clear_value (metadata_cell *thiz);
00107 
00108 
00109 /**---------------------------------------------------------------------------
00110  *
00111  * Name :  metadata_cell_copy_value
00112  *
00113  * @brief  Copy the value of a metadata_cell, leave target name as is
00114  *
00115  * @param  [out] thiz - the metadata_cell to copy into
00116  * @param  [in]  src - the metadata_cell to copy from
00117  *
00118  * @return ER_OK or error code
00119  *
00120  *--------------------------------------------------------------------------*/
00121 int metadata_cell_copy_value (metadata_cell *thiz, const metadata_cell *src);
00122 
00123 
00124 /**---------------------------------------------------------------------------
00125  *
00126  * Name :  metadata_cell_set_name
00127  *
00128  * @brief  Set the name of a metadata_cell
00129  *
00130  * @param  thiz - the metadata_cell
00131  * @param  [in] name - the new cell-name, or NULL to clear name
00132  *
00133  * @return ER_OK or error code
00134  *
00135  *--------------------------------------------------------------------------*/
00136 int metadata_cell_set_name (metadata_cell *thiz, const char *name);
00137 
00138 
00139 /**---------------------------------------------------------------------------
00140  *
00141  * Name :  metadata_cell_set_null
00142  *
00143  * @brief  Assign a NULL value to a metadata_cell
00144  *
00145  * @param  thiz - the metadata_cell
00146  *
00147  * @return ER_OK or error code
00148  *
00149  *--------------------------------------------------------------------------*/
00150 #define metadata_cell_set_null(cell)     metadata_cell_clear_value(cell)
00151 
00152 /**---------------------------------------------------------------------------
00153  *
00154  * Name :  metadata_cell_set_int64
00155  *
00156  * @brief  Assign an integer value to a metadata_cell
00157  *
00158  * @param  thiz - the metadata_cell
00159  * @param  [in] value - integer value (gint64)
00160  *
00161  * @return ER_OK or error code
00162  *
00163  *--------------------------------------------------------------------------*/
00164 int metadata_cell_set_int64 (metadata_cell *thiz, const gint64 value);
00165 
00166 
00167 /**---------------------------------------------------------------------------
00168  *
00169  * Name :  metadata_cell_set_double
00170  *
00171  * @brief  Assign a floating point value to a metadata_cell
00172  *
00173  * @param  thiz - the metadata_cell
00174  * @param  [in] value - floating point value (double)
00175  *
00176  * @return ER_OK or error code
00177  *
00178  *--------------------------------------------------------------------------*/
00179 int metadata_cell_set_double (metadata_cell *thiz, const double value);
00180 
00181 
00182 /**---------------------------------------------------------------------------
00183  *
00184  * Name :  metadata_cell_set_text
00185  *
00186  * @brief  Assign a string value to a metadata_cell
00187  *
00188  * @param  thiz - the metadata_cell
00189  * @param  [in] value - string value
00190  *                      Note: The value is copied into metadata_cell
00191  *                            so caller keeps ownership and must eventually free it.
00192  *
00193  * @return ER_OK or error code
00194  *
00195  *--------------------------------------------------------------------------*/
00196 int metadata_cell_set_text (metadata_cell *thiz, const char *value);
00197 
00198 
00199 /**---------------------------------------------------------------------------
00200  *
00201  * Name :  metadata_cell_set_blob
00202  *
00203  * @brief  Assign a blob to a metadata_cell
00204  *         BLOB = Binary Large OBject
00205  *
00206  * @param  thiz - the metadata_cell
00207  * @param  [in] value - binary value
00208  *                      Note: The value is "swallowed" by the metadata_cell
00209  *                            so caller looses ownership and must drop all pointers to it.
00210  *                            The metadata_cell will eventually release it with g_free()
00211  *                            so caller must have allocated it with g_new() or g_malloc().
00212  * @param  [in] len - length of value in bytes
00213  *
00214  * @return ER_OK or error code
00215  *
00216  *--------------------------------------------------------------------------*/
00217 int metadata_cell_set_blob (metadata_cell *thiz, gchar *value, const guint len);
00218 
00219 
00220 /**---------------------------------------------------------------------------
00221  *
00222  * Name :  metadata_cell_set_blob_static
00223  *
00224  * @brief  Assign a blob to a metadata_cell, assuming blob is static data
00225  *         BLOB = Binary Large OBject
00226  *
00227  * @param  thiz - the metadata_cell
00228  * @param  [in] value - binary value
00229  *                      Note: The metadata_cell will NOT release this memory block
00230  *                            so caller must ensure the data stays available for
00231  *                            as long as 'thiz' metadata_cell exists
00232  *                            or until a new value is assigned to 'thiz' cell.
00233  * @param  [in] len - length of value in bytes
00234  *
00235  * @return ER_OK or error code
00236  *
00237  *--------------------------------------------------------------------------*/
00238 int metadata_cell_set_blob_static (metadata_cell *thiz, const gchar *value, const guint len);
00239 
00240 
00241 /**---------------------------------------------------------------------------
00242  *
00243  * Name :  metadata_cell_get_string
00244  *
00245  * @brief  Report the value of a metadata_cell converted to a UTF-8 text string
00246  *         Not possible for SQLCELL_BLOB types
00247  *
00248  * @param  thiz - the metadata_cell
00249  *
00250  * @return cell value as a zero-terminated GString, or NULL when error
00251  *         caller must release this GString using g_string_free(string, TRUE)
00252  *
00253  *--------------------------------------------------------------------------*/
00254 GString *metadata_cell_get_string (const metadata_cell *thiz);
00255 
00256 G_END_DECLS
00257 
00258 #endif // __METADATA_CELL_H__
00259 
Generated by  doxygen 1.6.2-20100208