pelib  2.0.0
include/pelib/structure.h
Go to the documentation of this file.
00001 /*
00002  * structure.h
00003  *
00004  *  Created on: 20 Feb 2012
00005  *  Copyright 2012 Nicolas Melot
00006  *
00007  * This file is part of pelib.
00008  * 
00009  *     pelib is free software: you can redistribute it and/or modify
00010  *     it under the terms of the GNU General Public License as published by
00011  *     the Free Software Foundation, either version 3 of the License, or
00012  *     (at your option) any later version.
00013  * 
00014  *     pelib is distributed in the hope that it will be useful,
00015  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *     GNU General Public License for more details.
00018  * 
00019  *     You should have received a copy of the GNU General Public License
00020  *     along with pelib. If not, see <http://www.gnu.org/licenses/>.
00021  * 
00022  */
00023 
00024 #include <stdio.h>
00025 #include <stddef.h>
00026 
00027 #include <pelib/template.h>
00028 
00029 // Prevents several code generation for the same data structure
00030 #if PELIB_CONCAT_2(DONE_, STRUCT_T) == 0
00031 
00032 #ifndef STRUCT_T
00033 #error Using generic structure without a type
00034 #endif
00035 
00036 #define pelib_alloc_buffer(elem) PELIB_CONCAT_3(pelib_,elem,_alloc_buffer)
00037 #define pelib_set_buffer(elem) PELIB_CONCAT_3(pelib_,elem,_set_buffer)
00038 #define pelib_alloc_struct(elem) PELIB_CONCAT_3(pelib_,elem,_alloc_struct)
00039 #define pelib_alloc(elem) PELIB_CONCAT_3(pelib_,elem,_alloc)
00040 #define pelib_alloc_collection(elem) PELIB_CONCAT_3(pelib_,elem,_alloc_collection)
00041 #define pelib_alloc_from(elem) PELIB_CONCAT_3(pelib_,elem,_alloc_from)
00042 #define pelib_init(elem) PELIB_CONCAT_3(pelib_,elem,_init)
00043 #define pelib_copy(elem) PELIB_CONCAT_3(pelib_,elem,_copy)
00044 #define pelib_free_buffer(elem) PELIB_CONCAT_3(pelib_,elem,_free_buffer)
00045 #define pelib_free_struct(elem) PELIB_CONCAT_3(pelib_,elem,_free_struct)
00046 #define pelib_free(elem) PELIB_CONCAT_3(pelib_,elem,_free)
00047 #define pelib_destroy(elem) PELIB_CONCAT_3(pelib_,elem,_destroy)
00048 #define pelib_compare(elem) PELIB_CONCAT_3(pelib_,elem,_compare)
00049 #define pelib_printf(elem) PELIB_CONCAT_3(pelib_,elem,_printf)
00050 #define pelib_printf_detail(elem) PELIB_CONCAT_3(pelib_,elem,_printf_detail)
00051 #define pelib_fwrite(elem) PELIB_CONCAT_3(pelib_,elem,_fwrite)
00052 #define pelib_fread(elem) PELIB_CONCAT_3(pelib_,elem,_fread)
00053 #define pelib_string(elem) PELIB_CONCAT_3(pelib_,elem,_string)
00054 #define pelib_string_detail(elem) PELIB_CONCAT_3(pelib_,elem,_string_detail)
00055 
00059 STRUCT_T *
00060 pelib_alloc_struct(STRUCT_T)();
00061 
00066 int
00067 pelib_alloc_buffer(STRUCT_T)(STRUCT_T* obj, size_t n);
00068 
00075 int
00076 pelib_set_buffer(STRUCT_T)(STRUCT_T* obj, void* buffer, size_t n);
00080 STRUCT_T *
00081 pelib_alloc(STRUCT_T)();
00082 
00087 STRUCT_T *
00088 pelib_alloc_collection(STRUCT_T)(size_t n);
00089 
00095 STRUCT_T *
00096 pelib_alloc_from(STRUCT_T)(void* buffer, size_t n);
00097 
00102 int
00103 pelib_init(STRUCT_T)(STRUCT_T *obj);
00104 
00109 int
00110 pelib_copy(STRUCT_T)(STRUCT_T src, STRUCT_T* dst);
00111 
00116 int
00117 pelib_free_struct(STRUCT_T)(STRUCT_T *obj);
00118 
00123 int
00124 pelib_free_buffer(STRUCT_T)(STRUCT_T *);
00125 
00129 int
00130 pelib_free(STRUCT_T)(STRUCT_T *);
00131 
00135 int
00136 pelib_destroy(STRUCT_T)(STRUCT_T);
00137 
00141 int
00142 pelib_compare(STRUCT_T)(STRUCT_T a, STRUCT_T b);
00143 
00149 FILE*
00150 pelib_printf(STRUCT_T)(FILE* str, STRUCT_T obj);
00151 
00158 FILE*
00159 pelib_printf_detail(STRUCT_T)(FILE* str, STRUCT_T obj, int lvl);
00160 
00166 size_t
00167 pelib_fwrite(STRUCT_T)(STRUCT_T obj, FILE* str);
00168 
00174 size_t
00175 pelib_fread(STRUCT_T)(STRUCT_T* obj, FILE* str);
00176 
00178 char*
00179 pelib_string(STRUCT_T)(STRUCT_T);
00180 
00185 char*
00186 pelib_string_detail(STRUCT_T)(STRUCT_T, int);
00187 
00188 #endif
00189 #undef STRUCT_T