Changeset 196
- Timestamp:
- Mar 9, 2004, 5:19:15 PM (22 years ago)
- Location:
- trunk/archive/pslib/include
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/include/psArray.h
r181 r196 3 3 4 4 #include <stdlib.h> 5 /* 5 /** 6 6 * Declare TYPEArray 7 7 */ … … 19 19 20 20 /*****************************************************************************/ 21 /* 21 /** 22 22 * Generate the code TYPEArray's constructors/destructors 23 23 */ … … 78 78 79 79 /*****************************************************************************/ 80 /* 81 * Support for pointer types80 /** 81 * Declare array of pointers 82 82 */ 83 83 #define PS_DECLARE_ARRAY_PTR_TYPE(TYPE) \ … … 85 85 PS_DECLARE_ARRAY_TYPE(PS_CONCAT(TYPE, Ptr)) 86 86 87 /** 88 * Create constructors/destructors for array of pointers 89 */ 87 90 #define PS_CREATE_ARRAY_PTR_TYPE(TYPE); \ 88 91 P_PS_CREATE_ARRAY_TYPE(static, my_, P_PS_CONCAT(TYPE, Ptr)) \ … … 117 120 118 121 /*****************************************************************************/ 119 /* 120 * Declare some common types of arrays122 /** 123 * Array of pointers to void. 121 124 * 122 125 * psVoidPtrArray is special, as it needs to have a destructor that … … 125 128 */ 126 129 typedef struct { 127 int n, size; 128 void **arr; 130 int n; //!< Number of elements in use 131 int size; //!< Number of total elements 132 void **arr; //!< The elements 129 133 } psVoidPtrArray; 130 134 131 psVoidPtrArray *psVoidPtrArrayAlloc(int n, int s); 132 psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, int n); 133 void psVoidPtrArrayFree(psVoidPtrArray *arr, 134 void (*elemFree)(void *)); // destructor for array data 135 /** Constructor */ 136 psVoidPtrArray *psVoidPtrArrayAlloc(int n, //!< Number of elements to use 137 int s //!< Total number of elements 138 ); 139 /** Reallocate */ 140 psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, //!< Array to reallocate 141 int n //!< Number of elements 142 ); 143 /** Destructor */ 144 void psVoidPtrArrayFree(psVoidPtrArray *arr, //!< array to destroy 145 void (*elemFree)(void *) //!< destructor for array data 146 ); 135 147 136 148 -
trunk/archive/pslib/include/psDlist.h
r181 r196 4 4 * Support for doubly linked lists 5 5 */ 6 7 /** Doubly-linked list element */ 6 8 typedef struct psDlistElem { 7 struct psDlistElem *prev; // previous link in list8 struct psDlistElem *next; // next link in list9 void *data; // real data item9 struct psDlistElem *prev; //!< previous link in list 10 struct psDlistElem *next; //!< next link in list 11 void *data; //!< real data item 10 12 } psDlistElem; 11 13 14 /** Doubly-linked list */ 12 15 typedef struct { 13 int n; // number of elements on list14 psDlistElem *head; // first element on list (may be NULL)15 psDlistElem *tail; // last element on list (may be NULL)16 psDlistElem *iter; // iteration cursor16 int n; //!< number of elements on list 17 psDlistElem *head; //!< first element on list (may be NULL) 18 psDlistElem *tail; //!< last element on list (may be NULL) 19 psDlistElem *iter; //!< iteration cursor 17 20 } psDlist; 18 21 19 enum { // Special values of index into list 20 PS_DLIST_HEAD = 0, // at head 21 PS_DLIST_TAIL = -1, // at tail 22 PS_DLIST_UNKNOWN = -2, // unknown position 23 PS_DLIST_PREV = -3, // previous element 24 PS_DLIST_NEXT = -4 // next element 22 /** Special values of index into list */ 23 enum { 24 PS_DLIST_HEAD = 0, //!< at head 25 PS_DLIST_TAIL = -1, //!< at tail 26 PS_DLIST_UNKNOWN = -2, //!< unknown position 27 PS_DLIST_PREV = -3, //!< previous element 28 PS_DLIST_NEXT = -4 //!< next element 25 29 }; 26 30 27 31 /*****************************************************************************/ 28 /* 29 * Constructors and Destructors 30 */ 31 psDlist *psDlistAlloc(void *data); // initial data item; may be NULL 32 /** Constructor */ 33 psDlist *psDlistAlloc(void *data //!< initial data item; may be NULL 34 ); 32 35 33 void psDlistFree(psDlist *list, // list to destroy 34 void (*elemFree)(void *)); // destructor for data on list 36 /** Destructor */ 37 void psDlistFree(psDlist *list, //!< list to destroy 38 void (*elemFree)(void *) //!< destructor for data on list 39 ); 35 40 36 41 /* 37 42 * List maintainence functions 38 43 */ 39 psDlist *psDlistAdd(psDlist *list, // list to add to (may be NULL) 40 void *data, // data item to add 41 int where); // index, PS_DLIST_HEAD, or PS_DLIST_TAIL 42 psDlist *psDlistAppend(psDlist *list, // list to append to (may be NULL) 43 void *data); // data item to add 44 void *psDlistRemove(psDlist *list, // list to remove element from 45 void *data, // data item to remove 46 int which); // index of item, or PS_DLIST_UNKNOWN, 47 // or PS_DLIST_NEXT, or PS_DLIST_PREV 48 void *psDlistGet(const psDlist *list, // list to retrieve element from 49 int which); // index of item, or PS_DLIST_NEXT, 50 // or PS_DLIST_PREV 44 45 /** Add to list */ 46 psDlist *psDlistAdd(psDlist *list, //!< list to add to (may be NULL) 47 void *data, //!< data item to add 48 int where //!< index, PS_DLIST_HEAD, or PS_DLIST_TAIL 49 ); 50 51 /** Append to a list */ 52 psDlist *psDlistAppend(psDlist *list, //!< list to append to (may be NULL) 53 void *data //!< data item to add 54 ); 55 56 /** Remove from a list */ 57 void *psDlistRemove(psDlist *list, //!< list to remove element from 58 void *data, //!< data item to remove 59 int which //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or 60 //!< PS_DLIST_PREV 61 ); 62 63 /** Retrieve from a list */ 64 void *psDlistGet(const psDlist *list, //!< list to retrieve element from 65 int which //!< index of item, or PS_DLIST_NEXT, or PS_DLIST_PREV 66 ); 67 51 68 /* 52 69 * convenience functions to use psDlistGet as an iterator 53 70 */ 54 void psDlistSetIterator(psDlist *list, int where, int which); 55 void *psDlistGetNext(psDlist *list, int which); 56 void *psDlistGetPrev(psDlist *list, int which); 57 /* 58 * Conversions to/from arrays 59 */ 60 psVoidPtrArray *psDlistToArray(psDlist *dlist); 61 psDlist *psArrayToDlist(psVoidPtrArray *arr); 71 72 /** Set the iterator */ 73 void psDlistSetIterator(psDlist *list, //!< list to retrieve element from 74 int where, //!< index, PS_DLIST_HEAD, or PS_DLIST_TAIL 75 int which //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or 76 //!< PS_DLIST_PREV 77 ); 78 79 /** Get next element */ 80 void *psDlistGetNext(psDlist *list, //!< list to retrieve element from 81 int which //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or 82 //!< PS_DLIST_PREV 83 ); 84 85 /** Get previous element */ 86 void *psDlistGetPrev(psDlist *list, //!< list to retrieve element from 87 int which //!< index of item, or PS_DLIST_UNKNOWN, or PS_DLIST_NEXT, or 88 //!< PS_DLIST_PREV 89 ); 90 91 92 /** Convert doubly-linked list to an array */ 93 psVoidPtrArray *psDlistToArray(psDlist *dlist //!< List to convert 94 ); 95 96 /** Convert array to a doubly-linked list */ 97 psDlist *psArrayToDlist(psVoidPtrArray *arr //!< Array to convert 98 ); 99 100 62 101 #endif -
trunk/archive/pslib/include/psHash.h
r181 r196 2 2 #define PS_HASH_H 3 3 4 typedef struct HashTable psHash; 4 typedef struct HashTable psHash; //!< Opaque type for a hash table 5 5 6 psHash *psHashAlloc(int nbucket); // initial number of buckets 7 void psHashFree(psHash *table, // hash table to be freed 8 void (*itemFree)(void *item)); // how to free hashed data; 9 // or NULL 6 psHash *psHashAlloc(int nbucket //!< initial number of buckets 7 ); 8 void psHashFree(psHash *table, //!< hash table to be freed 9 void (*itemFree)(void *item) //!< how to free hashed data; or NULL 10 ); 10 11 11 void *psHashInsert(psHash *table, // table to insert in 12 const char *key, // key to use 13 void *data, // data to insert 14 void (*itemFree)(void *item)); // how to free hashed data; 15 // or NULL 16 void *psHashLookup(psHash *table, // table to lookup key in 17 const char *key); // key to lookup 12 void *psHashInsert(psHash *table, //!< table to insert in 13 const char *key, //!< key to use 14 void *data, //!< data to insert 15 void (*itemFree)(void *item) //!< how to free hashed data; or NULL 16 ); 17 void *psHashLookup(psHash *table, //!< table to lookup key in 18 const char *key //!< key to lookup 19 ); 18 20 19 void *psHashRemove(psHash *table, // table to lookup key in 20 const char *key); // key to lookup 21 void *psHashRemove(psHash *table, //!< table to lookup key in 22 const char *key //!< key to lookup 23 ); 24 25 21 26 #endif -
trunk/archive/pslib/include/psLogMsg.h
r181 r196 3 3 #include <stdarg.h> 4 4 5 enum { PS_LOG_ABORT = 0, PS_LOG_ERROR, PS_LOG_WARN, PS_LOG_INFO }; 5 enum { PS_LOG_ABORT = 0, PS_LOG_ERROR, PS_LOG_WARN, PS_LOG_INFO }; //!< Status codes for log messages 6 6 7 enum { PS_LOG_TO_STDERR, PS_LOG_TO_STDOUT }; 7 enum { PS_LOG_TO_STDERR, PS_LOG_TO_STDOUT }; //!< Destinations for log messages 8 8 9 int psSetLogDestination(int dest); 10 int psSetLogLevel(int level); 11 void psSetLogFormat(const char *fmt); 9 int psSetLogDestination(int dest); //!< Sets the log destination 10 int psSetLogLevel(int level); //!< Sets the log level 11 void psSetLogFormat(const char *fmt); //!< sets the log format 12 12 13 void psLogMsg(const char *name, int level, const char *fmt, ...); 14 void p_psVLogMsg(const char *name, int level, const char *fmt, va_list ap); 13 void psLogMsg(const char *name, int level, const char *fmt, ...); //!< Logs a message 14 void p_psVLogMsg(const char *name, int level, const char *fmt, va_list ap); //!< Logs a message from varargs 15 15 16 16 #endif -
trunk/archive/pslib/include/psMemory.h
r181 r196 2 2 #define PS_MEMORY_H 3 3 #include <stdio.h> 4 /* 5 * Book-keeping data for storage allocator 4 /** 5 * Book-keeping data for storage allocator. 6 6 * 7 7 * N.b. sizeof(psMemBlock) must be chosen such that if ptr is a pointer … … 10 10 */ 11 11 typedef struct { 12 const void *magic0; // initialised to p_psMEMMAGIC13 const unsigned long id; // a unique ID for this allocation14 const char *file; // set from __FILE__ in e.g. p_psAlloc15 const int lineno; // set from __LINE__ in e.g. p_psAlloc16 int refCounter; // how many times pointer is referenced17 const void *magic; // initialised to p_psMEMMAGIC12 const void *magic0; //!< initialised to p_psMEMMAGIC 13 const unsigned long id; //!< a unique ID for this allocation 14 const char *file; //!< set from __FILE__ in e.g. p_psAlloc 15 const int lineno; //!< set from __LINE__ in e.g. p_psAlloc 16 int refCounter; //!< how many times pointer is referenced 17 const void *magic; //!< initialised to p_psMEMMAGIC 18 18 } psMemBlock; 19 19 20 /** */ 20 21 typedef int (*psMemCallback)(const psMemBlock *ptr); 21 22 typedef void (*psMemProblemCallback)(const psMemBlock *ptr, … … 25 26 /*****************************************************************************/ 26 27 27 void *psAlloc(size_t size); 28 void *psRealloc(void *ptr, size_t size); 29 void psFree(void *ptr); 28 /** Fake for p_psAlloc */ 29 void *psAlloc(size_t size //!< Size required 30 ); 31 /** Fake for p_psRealloc */ 32 void *psRealloc(void *ptr, //!< Pointer to re-allocate 33 size_t size //!< Size required 34 ); 35 /** Fake for p_psFree */ 36 void psFree(void *ptr //!< Pointer to free 37 ); 30 38 31 void *p_psAlloc(size_t size, const char *file, int lineno); 32 void *p_psRealloc(void *ptr, size_t size, const char *file, int lineno); 33 void p_psFree(void *ptr, const char *file, int lineno); 39 /** Memory allocation */ 40 void *p_psAlloc(size_t size, //!< Size required 41 const char *file, //!< File of call 42 int lineno //!< Line number of call 43 ); 34 44 45 /** Memory re-allocation */ 46 void *p_psRealloc(void *ptr, //!< Pointer to re-allocate 47 size_t size, //!< Size required 48 const char *file, //!< File of call 49 int lineno //!< Line number of call 50 ); 51 52 /** Free memory */ 53 void p_psFree(void *ptr, //!< Pointer to free 54 const char *file, //!< File of call 55 int lineno //!< Line number of call 56 ); 57 58 /** psAlloc sends file and line number to p_psAlloc */ 35 59 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__) 60 /** psRealloc sends file and line number to p_psRealloc */ 36 61 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__) 62 /** psFree sends file and line number to p_psFree */ 37 63 #define psFree(size) p_psFree(size, __FILE__, __LINE__) 38 64 39 65 /*****************************************************************************/ 40 /* 41 * Checks of memory system 42 */ 43 int psMemCheckLeaks( 44 int id0, // don't list blocks with id < id045 psMemBlock ***arr, // pointer to array of pointers to 46 // leaked blocks, or NULL 47 FILE *fd); // print list of leaks to fd (or NULL) 48 int psMemCheckCorruption(int abort_on_error);66 /** Check for memory leaks */ 67 int psMemCheckLeaks(int id0, //!< don't list blocks with id < id0 68 psMemBlock ***arr, //!< pointer to array of pointers to leaked blocks, or NULL 69 FILE *fd //!< print list of leaks to fd (or NULL) 70 ); 71 72 /** Check for memory corruption */ 73 int psMemCheckCorruption(int abort_on_error //!< Abort on detecting corruption? 74 ); 49 75 50 76 /*****************************************************************************/ 51 /* 52 * Manipulate reference counter 53 */ 54 int psMemGetRefCounter(void *vptr); // return refCounter 55 void *psMemIncrRefCounter(void *vptr); // increment refCounter and return vptr 56 void *psMemDecrRefCounter(void *vptr); // decrement refCounter and return vptr 77 78 /** Return reference counter */ 79 int psMemGetRefCounter(void *vptr //!< Pointer to get refCounter for 80 ); 81 /** Increment reference counter and return the pointer */ 82 void *psMemIncrRefCounter(void *vptr //!< Pointer to increment refCounter, and return 83 ); 84 /** Decrement reference counter and return the pointer */ 85 void *psMemDecrRefCounter(void *vptr //!< Pointer to decrement refCounter, and return 86 ); 57 87 58 88 /*****************************************************************************/ … … 60 90 * Functions to set and control callbacks 61 91 */ 62 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func);63 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func);64 92 65 psMemCallback psMemAllocateSetCB(psMemCallback func); 66 psMemCallback psMemFreeSetCB(psMemCallback func); 93 /** Set callback for problems */ 94 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func //!< Function to run 95 ); 96 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func); //!< set call back for exhausted 97 //!< memory 67 98 68 int psMemGetId(void); // get next memory ID 69 long psMemSetAllocateID(long id); // set p_psMemAllocateID to id 70 long psMemSetFreeID(long id); // set p_psMemFreeID to id 99 psMemCallback psMemAllocateSetCB(psMemCallback func); //!< Set call back for when a particular memory block is 100 //!< allocated 101 psMemCallback psMemFreeSetCB(psMemCallback func); //!< set call back for when a particular memory block is 102 //!< freed 103 104 int psMemGetId(void); //!< get next memory ID 105 long psMemSetAllocateID(long id); //!< set p_psMemAllocateID to id 106 long psMemSetFreeID(long id); //!< set p_psMemFreeID to id 71 107 #endif -
trunk/archive/pslib/include/psMisc.h
r181 r196 1 1 #if !defined(PS_MISC_H) 2 2 #define PS_MISC_H 3 /* 3 /** 4 4 * Concatenate two macro arguments 5 5 */ 6 #define P_PS_CONCAT(A, B) A ## B // Expands to AB7 #define PS_CONCAT(A, B) A ## B // Also Expands to AB8 #define PS_CONCAT2(A, B) PS_CONCAT(A, B) // Also expands to AB9 #define PS_CONCAT3(A, B, C) A ## B ## C // Expands to ABC10 #define PS_CONCAT4(A, B, C, D) A ## B ## C ## D // Expands to ABCD6 #define P_PS_CONCAT(A, B) A ## B //!< Expands to AB 7 #define PS_CONCAT(A, B) A ## B //!< Also Expands to AB 8 #define PS_CONCAT2(A, B) PS_CONCAT(A, B) //!< Also expands to AB 9 #define PS_CONCAT3(A, B, C) A ## B ## C //!< Expands to ABC 10 #define PS_CONCAT4(A, B, C, D) A ## B ## C ## D //!< Expands to ABCD 11 11 12 #define PS_STRING(S) #S // converts argument to string12 #define PS_STRING(S) #S //!< converts argument to string 13 13 14 void psAbort(const char *name, const char *fmt, ...); 15 void psError(const char *name, const char *fmt, ...); 14 /** Prints an error message and aborts */ 15 void psAbort(const char *name, //!< Category of code that caused the abort 16 const char *fmt, //!< Format 17 ... //!< Extra arguments to use format 18 ); 19 /** Prints an error message and doesn't abort */ 20 void psError(const char *name, //!< Category of code that caused the abort 21 const char *fmt, //!< Format 22 ... //!< Extra arguments to use format 23 ); 16 24 17 char *psStringCopy(const char *str); 25 /** Allocates and returns a copy of a string */ 26 char *psStringCopy(const char *str //!< string to copy 27 ); 18 28 19 29 #endif -
trunk/archive/pslib/include/psTrace.h
r181 r196 2 2 #define PS_TRACE_H 1 3 3 4 //#define PS_NTRACE 1 / * to turn off all tracing */4 //#define PS_NTRACE 1 //!< to turn off all tracing 5 5 #if defined(PS_NTRACE) 6 # define psTrace(facil, level, ...) /* do nothing */6 # define psTrace(facil, level, ...) /* do nothing */ 7 7 #else 8 8 # define psTrace(facil, level, ...) \ … … 10 10 #endif 11 11 12 /** Send a trace message */ 12 13 void p_psTrace(const char *facil, int level, ...); 13 14 14 int psSetTraceLevel(const char *facil, // facilty of interest 15 int level); // desired trace level 16 int psGetTraceLevel(const char *name); // facilty of interest 15 /** Set trace level */ 16 int psSetTraceLevel(const char *facil, //!< facilty of interest 17 int level //!< desired trace level 18 ); 17 19 18 void psTraceReset(void); // turn off all tracing, and free trace's allocated memory 20 /** Get the trace level */ 21 int psGetTraceLevel(const char *name //!< facilty of interest 22 ); 19 23 20 void psPrintTraceLevels(void); // print trace levels 24 /** turn off all tracing, and free trace's allocated memory */ 25 void psTraceReset(void); 26 27 /** print trace levels */ 28 void psPrintTraceLevels(void); 21 29 22 30 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
