sequence.h

00001 /*
00002 Copyright Remco Bras 2007,2008
00003 This file is part of RPGE.
00004 
00005 RPGE is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 RPGE is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program.  If not, see <http://www.gnu.org/licenses/>
00017 */
00018 
00019 /*prototype sequence header*/
00020 #ifndef SEQ_H
00021 #define SEQ_H
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <stdio.h>
00025 #include <SDL/SDL.h>
00026 #include "xalloc.h"
00027 
00028 #define TYPE_IMAGE 0  
00029 #define TYPE_MOB 1
00030 #define TYPE_EVENT 2
00031 #define TYPE_WINDOW 3
00032 #define TYPE_INT 4
00033 #define TYPE_UINT32 5
00034 #define TYPE_ARGV 6
00035 #define TYPE_FONT 7
00036 #define TYPE_STRING 8
00037 #define TYPE_TEXT 9
00038 #define TYPE_DISPATCH_PAIR 10
00039 #define TYPE_MOVE_DESCRIPTOR 11
00040 #define TYPE_THREAD_ARGV 12
00041 #define TYPE_DIRECTIVE_T 13
00042 #define TYPE_TILELAYER 14
00043 #define TYPE_IMAGECOUNTER 15
00044 #define TYPE_USER 16
00045 
00046 /*
00047   A prototype macro to replace the ugliness using convertors.sh and .cgen files.
00048   The extra argument capitalized_name is used until I can find something that
00049   sucks less.
00050 */
00051 #define CONVERTORS(type,namestr,capitalized_name) inline object make_##namestr##_obj(type foo) \
00052    { \
00053      object o;\
00054      o.data = xmalloc(sizeof(type));\
00055      o.typeinfo = TYPE_##capitalized_name;\
00056      *((type*)o.data) = foo;\
00057      return o;\
00058    }\
00059    inline type \
00060    get_obj_##namestr(object o)\
00061    {\
00062      return *((type*)o.data);\
00063    }
00064 
00065 /*
00066   Convenience edition of previous macro.
00067   Unfortunately, I haven't found a way to upper-case things in the C preprocessor yet.
00068   (The S stands for 'Simple')
00069 */
00070 #define S_CONVERTORS(type,capitalized_name) CONVERTORS(type,type,capitalized_name)
00071 
00072 
00073 
00074   
00075 typedef struct
00076 {
00077   void *data;                   
00078   unsigned long typeinfo;       
00079 } object;
00080 
00081 typedef struct
00082 {
00083   unsigned long objcount;
00084   object *data;
00085 } sequence;
00086 
00087 sequence sequence_init(void);
00088 int sequence_append (sequence *seq, object data);
00089 int sequence_position (sequence seq, object data, char (* eqproc) (object, object));
00090 object sequence_find (sequence seq, object data, char (* eqproc) (object, object));
00091 void sequence_remove_at(sequence *seq, int index);
00092 void sequence_remove (sequence *seq, object data, char (* eqproc) (object, object));
00093 sequence sequence_map (sequence seq, object (*proc) (object));
00094 sequence sequence_map_destructive (sequence seq, object (*proc) (object));
00095 void sequence_foreach (sequence seq, void (*proc) (object));
00096 void sequence_free (sequence seq);
00097 object sequence_reduce(sequence seq, object (* proc)(object, object));
00098 object make_int_obj(int i);
00099 int get_obj_int(object o);
00100 object make_Uint32_obj (Uint32 u);
00101 Uint32 get_obj_Uint32(object o);
00102 object make_string_obj(char*);
00103 char* get_obj_string(object);
00104 void free_obj(object o);
00105 
00106 #endif
 All Classes

Generated on Tue Feb 15 21:31:40 2011 by  doxygen 1.6.1