funkalicious 0.1

binary_data_common.h

Go to the documentation of this file.
00001 /*
00002 ** binary_data_common.h
00003 ** 
00004 
00005     Copyright (C) 2009 Joseph Pingenot
00006 
00007     This program is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU Affero General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Affero General Public License for more details.
00016 
00017     You should have received a copy of the GNU Affero General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020 ** Made by Johnny Q. Hacker
00021 ** Login   <solarion@nathan>
00022 ** 
00023 ** Started on  Tue Nov 24 21:39:16 2009 Johnny Q. Hacker
00024 ** Last update Tue Nov 24 21:39:16 2009 Johnny Q. Hacker
00025 */
00026 
00027 #ifndef     BINARY_DATA_COMMON_H_
00028 # define    BINARY_DATA_COMMON_H_
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 #include <glib-2.0/glib.h>
00035 
00036 #define DOTCODE_INT_SIZE 4
00037 #define DOTCODE_FLOAT4_SIZE 4
00038 #define DOTCODE_FLOAT8_SIZE 8
00039 
00040 enum dotcode_type {
00041   DOTCODE_INVALID_TYPE = -1,
00042   DOTCODE_FLOAT8,
00043   DOTCODE_FLOAT4,
00044   DOTCODE_INT,
00045   DOTCODE_SSTRING,
00046   DOTCODE_VECTOR,
00047   DOTCODE_ARRAY,
00048   DOTCODE_TENSOR,
00049   DOTCODE_GRID
00050 };
00051 
00052 struct dotcode_data {
00053   enum dotcode_type t;
00054   void* storage;
00055 };
00056 
00057 struct dotcode_array {
00058   enum dotcode_type t;
00059   int imin;
00060   int imax;
00061   void* storage;
00062 };
00063 
00064 struct dotcode_vector {
00065   enum dotcode_type t;
00066   /*Pointer to an array of 3 t's; cast the pointer to index properly.*/
00067   void* data;
00068 };
00069 
00070 struct dotcode_tensor {
00071   enum dotcode_type t;
00072   char* metadata;
00073   /*Number of dimensions*/
00074   int Nd;
00075   /*The min, max indices for each direction. Allocation:
00076     m + 2*d
00077     m = min (0) or max (1)
00078     d = dimension (0<=d<Nd)
00079    */
00080   int* indices;
00081   void* data;
00082 };
00083 
00084 /**The *new* grid, not grid1*/
00085 struct dotcode_grid {
00086   /*X, Y, Z*/
00087   struct dotcode_array* gridsites[3];
00088   /*Informational; Ng{x,y,z}_*/
00089   int Ng[3];
00090   struct dotcode_tensor* data;
00091 };
00092 
00093 enum dotcode_type dotcode_type_from_string(const char* s);
00094 char* dotcode_string_from_type(enum dotcode_type t);
00095 /**This one is nice for using for one-off situations, e.g. error strings*/
00096 const char* dotcode_string_from_type2(enum dotcode_type t);
00097 void flip_endian(char* buffer, int bytes);
00098 int dotcode_get_tensor_index(const struct dotcode_tensor, unsigned int* index);
00099 void dotcode_free_type(enum dotcode_type t, void* ptr, long unsigned int count, 
00100            GError **err, gboolean free_struct);
00101 /**Appends the type containers in str into a GList of 
00102  *\param str string containing type template.
00103  *\param tlist a pointer to a NULL-initialized GList pointer.
00104  *\param err pointer to a NULL-initialized error pointer.
00105  */
00106 void dotcode_determine_templated_type(const char* str, GList** tlist, GError **err);
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 
00112 #endif      /* !BINARY_DATA_COMMON_H_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines