00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __it_types_h
00026 #define __it_types_h
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <stdarg.h>
00031 #include <limits.h>
00032 #include <float.h>
00033
00034
00035
00036
00037
00038
00039
00040 #define LIBIT_VERSION(a,b,c) ((a << 16) + ((b) << 8) + (c))
00041 #define LIBIT_VERSION_CODE LIBIT_VERSION(0,2,3)
00042
00043
00044 #ifndef INT_MAX
00045 #define INT_MAX 2147483647
00046 #define INT_MIN (-INT_MAX - 1)
00047 #endif
00048
00049 #ifdef WIN32
00050 #define inline __inline
00051 #endif
00052
00053
00054 #define IT_EINVAL 1
00055 #define IT_ENOMEM 2
00056 #define IT_ENOENT 3
00057
00058
00059 typedef unsigned char byte;
00060
00061
00062 typedef unsigned char __it_u8;
00063 typedef unsigned short __it_u16;
00064 typedef unsigned int __it_u32;
00065 #define has_u64() (sizeof(unsigned long) == 8)
00066 typedef unsigned long __it_u64;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 typedef int idx_t;
00087
00088
00089 static const idx_t end = (idx_t) INT_MIN;
00090
00091 static const idx_t NULL_INDEX = (idx_t) INT_MIN + 1;
00092
00093
00094 static inline idx_t __vec_idx_warnoff__ (void) {
00095 return (end | NULL_INDEX);
00096 }
00097
00098
00099
00100
00101 typedef void *it_args_t;
00102
00103
00104 typedef double (*it_function_t) (double, it_args_t);
00105
00106
00107 typedef int (*it_ifunction_t) (int, it_args_t);
00108
00109
00110 typedef double (*it_vfunction_t) (double *, it_args_t);
00111
00112
00113 #define it_function(name) \
00114 it_function_args(name); \
00115 double __##name(double x, it_function_args(name) *it_this); \
00116 it_function_t name = IT_FUNCTION(__##name); \
00117 double __##name(double x, it_function_args(name) *it_this)
00118
00119 #define it_ifunction(name) \
00120 it_function_args(name); \
00121 int __##name(int x, it_function_args(name) *it_this); \
00122 it_ifunction_t name = IT_IFUNCTION(__##name); \
00123 int __##name(int x, it_function_args(name) *it_this)
00124
00125 #define it_vfunction(name) \
00126 it_function_args(name); \
00127 double __##name(vec v, it_function_args(name) *it_this); \
00128 it_vfunction_t name = IT_VFUNCTION(__##name); \
00129 double __##name(vec v, it_function_args(name) *it_this)
00130
00131
00132 #define it_function_args(f) struct _##f##_
00133
00134
00135 #define IT_FUNCTION(f) ((it_function_t) f)
00136 #define IT_IFUNCTION(f) ((it_ifunction_t) f)
00137 #define IT_VFUNCTION(f) ((it_vfunction_t) f)
00138
00139
00140
00141
00142
00143 typedef unsigned int it_magic_t;
00144
00145 #define IT_MAGIC_it_object_t 0x81e73650
00146 #define IT_MAGIC_it_quantizer_t 0x8807fc6c
00147 #define IT_MAGIC_it_scalar_quantizer_t 0x48f58421
00148 #define IT_MAGIC_it_uniform_quantizer_t 0x4a378552
00149 #define IT_MAGIC_it_trellis_coded_quantizer_t 0x0a1d2ed3
00150 #define IT_MAGIC_it_convolutional_code_t 0x93f58bf7
00151 #define IT_MAGIC_it_transform2D_t 0x46e2af32
00152 #define IT_MAGIC_it_wavelet2D_t 0xe5c8ef1a
00153 #define IT_MAGIC_it_transform_t 0xaa709ce4
00154 #define IT_MAGIC_it_wavelet_t 0x8ba63118
00155 #define IT_MAGIC_it_separable2D_t 0x299270ff
00156 #define IT_MAGIC_it_fourier_t 0xe0caafee
00157
00158
00159
00160
00161
00162
00163
00164
00165 typedef struct _it_object_ {
00166 it_magic_t type;
00167 it_magic_t magic;
00168 void (*destructor) (struct _it_object_ * it_this);
00169 } it_object_t;
00170
00171
00172
00173 #define it_set_magic(object, type_t) \
00174 do { object->magic = IT_MAGIC_##type_t; IT_OBJECT(object)->type = IT_MAGIC_##type_t; } while(0)
00175
00176 #define it_check_magic(object, type_t) \
00177 (object->magic == IT_MAGIC_##type_t)
00178
00179 #define it_check_type(object, type_t) \
00180 (IT_OBJECT(object)->type == IT_MAGIC_##type_t)
00181
00182 #if !defined(NDEBUG) && defined(__GNUC__)
00183 #define IT_CAST(type_t, x) \
00184 ({ \
00185 type_t *obj = (type_t *) x; \
00186 \
00187 if(obj->magic != IT_MAGIC_##type_t) { \
00188 fprintf(stderr, "*** fatal error ***:%s:%d: object %p is not of type %s\n", __FILE__, __LINE__, (void *) obj, #type_t); \
00189 abort(); \
00190 } \
00191 obj; \
00192 })
00193 #else
00194 #define IT_CAST(type_t, x) ((type_t *) (x))
00195 #endif
00196
00197
00198 #define IT_OBJECT(x) IT_CAST(it_object_t, x)
00199
00200
00201
00202
00203
00204
00205 #define it_extends(type_t) type_t super; it_magic_t magic
00206
00207
00208
00209
00210
00211 #define it_new(type_t) type_t##_instanciate((type_t *) malloc(sizeof(type_t)))
00212 #define it_new_va(type_t) type_t##_instanciate((type_t *) malloc(sizeof(type_t)),
00213 #define it_va void *)0
00214 #define it_instanciate(type_t) type_t * type_t##_instanciate(type_t *it_this, ...)
00215 #define it_construct(type_t) type_t##_instanciate((type_t *) it_this)
00216 #define it_construct_va(type_t) type_t##_instanciate((type_t *) it_this,
00217
00218
00219
00220 #define it_delete(object) IT_OBJECT(object)->destructor(IT_OBJECT(object))
00221
00222
00223 #define it_overloaded(method) super_##method
00224 #define it_overload(object, type, method, function) \
00225 do { \
00226 object->it_overloaded(method) = IT_CAST(type, it_this)->method; \
00227 IT_CAST(type, it_this)->method = function; \
00228 } while(0)
00229
00230
00231
00232
00233 static inline it_instanciate (it_object_t) {
00234
00235 do {
00236 it_this->magic = IT_MAGIC_it_object_t;
00237 IT_CAST (it_object_t, it_this)->type = IT_MAGIC_it_object_t;
00238 }
00239 while (0);
00240
00241
00242 it_this->destructor = (void (*)(it_object_t *)) free;
00243 return (it_this);
00244 }
00245
00246
00247 #define it_new_args_start() \
00248 va_list args; \
00249 va_start(args, it_this); \
00250 (void) va_arg(args, void *)
00251
00252
00253 #define it_new_args_stop() \
00254 va_end(args)
00255
00256
00257 #define it_new_args_next(type_t) \
00258 va_arg(args, type_t)
00259
00260
00261
00262 #endif