Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

RmVectorT.h

00001 //=================================================================================================//
00002 // filename: RmVectorT.h                                                                           //
00003 //                                                                                                 //
00004 //           ATI Research, Inc.                                                                    //
00005 //           3D Application Research Group                                                         //
00006 //                                                                                                 //
00007 // Description:  Old implementation of STL-like vector container                                   //
00008 //                                                                                                 //
00009 //=================================================================================================//
00010 //   (C) 2004 ATI Research, Inc.  All rights reserved.                                             //
00011 //=================================================================================================//
00012 
00013 #ifndef _RM_CORE_VECTOR_T_H_
00014 #define _RM_CORE_VECTOR_T_H_
00015 
00016 // INCLUDES ===================================================================
00017 #include <stdlib.h>
00018 #include <memory.h>
00019 #include <string.h>
00020 #include "RmTypes.h"
00021 
00022 // RETURN CODES================================================================
00023 #define VECTOR_OK                0
00024 #define VECTOR_REALLOCATE        -1
00025 #define VECTOR_MEMORY_ERROR      -2
00026 #define VECTOR_OUT_OF_RANGE      -3
00027 #define VECTOR_NOT_FOUND         -4
00028 
00029 #ifndef TRUE
00030    #define TRUE                  1
00031 #endif
00032 #ifndef FALSE
00033    #define FALSE                 0
00034 #endif
00035 
00036 // DATA TYPE DEFINITIONS ======================================================
00037 typedef int (*SortFunc)(const void*, const void*);
00038 
00039 typedef struct vector_s
00040 {
00041    int         count;
00042    int         allocCount;
00043    int         elementSize;
00044    int         (*compare)(const void*, const void*);
00045    void        *data;
00046 } vector_t;
00047 
00048 // MACROS =====================================================================
00049 #define InitVector(name, compare)                                 \
00050    memset(&name##Vector, 0, sizeof(vector_t));                    \
00051    name##Size = sizeof(*name);                                    \
00052    name##Compare = compare;
00053 
00054 #define VectorType(type, name)                                    \
00055    union                                                          \
00056    {                                                              \
00057       vector_t   name##Vector;                                    \
00058       struct                                                      \
00059       {                                                           \
00060          int      name##Count;                                    \
00061          int      name##Alloc;                                    \
00062          int      name##Size;                                     \
00063          int      (*name##Compare)(const void*, const void*);     \
00064          type*    name;                                           \
00065       };                                                          \
00066    };
00067 
00068 #define VectorTypeWithAlias(type, name, alias)                    \
00069    union                                                          \
00070    {                                                              \
00071       vector_t   name##Vector;                                    \
00072       struct                                                      \
00073       {                                                           \
00074          int      name##Count;                                    \
00075          int      name##Alloc;                                    \
00076          int      name##Size;                                     \
00077          int      (*name##Compare)(const void*, const void*);     \
00078          type*    name;                                           \
00079       };                                                          \
00080       struct                                                      \
00081       {                                                           \
00082          int      name##Filler[4];                                \
00083          type*    alias;                                          \
00084       };                                                          \
00085    };
00086 
00087 #define VectorObject(type, name)                            \
00088    union                                                    \
00089    {                                                        \
00090       vector_t   vec;                                       \
00091       struct                                                \
00092       {                                                     \
00093          int      count;                                    \
00094          int      alloc;                                    \
00095          int      size;                                     \
00096          int      (*compare)(const void*, const void*);     \
00097          type*    data;                                     \
00098       };                                                    \
00099    } name;
00100 
00101 #define VectorTypedef(type, name, data)                  \
00102    typedef struct                                        \
00103    {                                                     \
00104       int      count;                                    \
00105       int      alloc;                                    \
00106       int      size;                                     \
00107       int      (*compare)(const void*, const void*);     \
00108       type*    data;                                     \
00109    } name;
00110 
00111 // FUNCTION PROTOTYPES ========================================================
00112 int RM_API VectorAddElement(vector_t* v, void* element, int nIndex, char append);
00113 int RM_API VectorAppend(vector_t* v, void* element, int nIndex);
00114 int RM_API VectorAppendBack(vector_t* v, void* element);
00115 int RM_API VectorCheckAlloc(vector_t* v);
00116 int RM_API VectorFind(vector_t* v, void* element, int* result);
00117 void  RM_API VectorFree(vector_t* v);
00118 int RM_API VectorInsert(vector_t* v, void* element, int nIndex);
00119 int RM_API VectorRemoveIndex(vector_t* v, int nIndex);
00120 int RM_API VectorRemoveSortedElement(vector_t* v, void* element);
00121 void  RM_API VectorSort(vector_t* v);
00122 int RM_API VectorSortedInsert(vector_t* v, void* element);
00123 
00124 #endif

Generated on Fri Feb 25 16:08:43 2005 for RenderMonkey SDK by doxygen 1.3.6