Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/MD_package/MDUtility.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations) (download) (as text)
Sun Oct 1 03:33:45 2017 UTC (6 years, 6 months ago) by toshinagata1964
File MIME type: text/x-chdr
File size: 6852 byte(s)
Sizes of the integer types are reconsidered.
1 /*
2 * MDUtility.h
3 *
4 * Created by Toshi Nagata on Sun Jun 17 2001.
5
6 Copyright (c) 2000-2016 Toshi Nagata. All rights reserved.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 */
17
18 #ifndef __MDUtility__
19 #define __MDUtility__
20
21 typedef struct MDArray MDArray;
22
23 #ifndef __MDCommon__
24 #include "MDCommon.h"
25 #endif
26
27 struct MDArray {
28 int32_t refCount; /* the reference count */
29 int32_t num; /* the number of elements */
30 int32_t maxIndex; /* the number of allocated elements */
31 int32_t elemSize; /* the size of the element */
32 int32_t pageSize; /* the page size */
33 void * data; /* data */
34 char allocated; /* non-zero if data is allocated by malloc() */
35 void (*destructor)(void *); /* element destructor */
36 };
37
38 #define kMDArrayDefaultPageSize 16
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* -------------------------------------------------------------------
45 MDUtility functions
46 ------------------------------------------------------------------- */
47
48 /* ������������������������������������������ANSI-C ��� scanf ���������������������������������������������������
49 Perl ��� pack/unpack ��������������������������������������������������������������������������� [������������]���
50 ��������������������������������������������������������������������������������� a, A, c, C, n, N, w ���
51 ������������������������������������������������������������������������������������������������������������������
52 a, A ��������������������������� "*" ������������������������������������ int32_t ���������������������������������
53 ��������������������������������������������������������������������������������������������������������������� */
54 int32_t MDReadStreamFormat(STREAM stream, const char *format, ...);
55
56 /* ������������������������������������������������������������ MDReadStreamFormat() ������������ */
57 int32_t MDWriteStreamFormat(STREAM stream, const char *format, ...);
58
59 /* ������������������������������������������������ fopen() ��������������������������������������� STREAM ������
60 ��������������������������������� PUTC, GETC,... ��������������������������������������������� */
61 STREAM MDStreamOpenFile(const char *fname, const char *mode);
62
63 /* ������������������������������������ptr ��� NULL ������malloc() ���������������������������������������������������
64 ���������������size ���������������������������ptr == NULL ������������ 0 ������������������
65 ���������FCLOSE(stream) ��� ptr ���������������������stream ���������������������������������������������
66 FCLOSE ��������� MDStreamGetData() ������������������������������������������������������������������������������������ */
67 STREAM MDStreamOpenData(void *ptr, size_t size);
68
69 /* ���������������������������������������������������������������������������������������������������������������������������������������
70 ��������������� -1 ������������ */
71 int MDStreamGetData(STREAM stream, void **ptr, size_t *size);
72
73 /* -------------------------------------------------------------------
74 Debug print functions
75 ------------------------------------------------------------------- */
76 #if DEBUG
77 /* Control output of debugging messages */
78 extern int gMDVerbose;
79 int _dprintf(const char *fname, int lineno, int level, const char *fmt, ...);
80 #endif
81
82 #if DEBUG
83 /* Usage: dprintf(int level, const char *fmt, ...) */
84 #define dprintf(level, fmt...) (gMDVerbose >= (level) ? _dprintf(__FILE__, __LINE__, (level), fmt) : 0)
85 #else
86 #define dprintf(level, fmt...) ((void)0)
87 #endif
88
89 /* -------------------------------------------------------------------
90 MDArray functions
91 ------------------------------------------------------------------- */
92
93 /* ��������� MDArray ������������������������������������������������������ NULL ������������
94 elementSize ���������������������������������pageSize ������������������������������������������������ */
95 MDArray * MDArrayNew(int32_t elementSize);
96 MDArray * MDArrayNewWithPageSize(int32_t elementSize, int32_t pageSize);
97
98 MDArray * MDArrayNewWithDestructor(int32_t elementSize, void (*destruct)(void *));
99
100 /* ��������������������������������������������������� MDArray ��������������������� */
101 MDArray * MDArrayInit(MDArray *arrayRef, int32_t elementSize);
102 MDArray * MDArrayInitWithPageSize(MDArray *arrayRef, int32_t elementSize, int32_t pageSize);
103
104 /* MDArray ��� retain/release��� */
105 void MDArrayRetain(MDArray *arrayRef);
106 void MDArrayRelease(MDArray *arrayRef);
107
108 /* MDArray ������������������������ */
109 void MDArrayEmpty(MDArray *arrayRef);
110
111 /* ��������������������� */
112 int32_t MDArrayCount(const MDArray *arrayRef);
113
114 /* MDArray ������������������������������inCount ������������������������������������������������������������������������������������������inCount ������������������������������������������������������������������������������������������������ */
115 MDStatus MDArraySetCount(MDArray *arrayRef, int32_t inCount);
116
117 /* inIndex ������������������������������ inLength ������������������������������������������������������
118 ��������������������������������������������������������������������������������� */
119 MDStatus MDArrayInsert(MDArray *arrayRef, int32_t inIndex, int32_t inLength, const void *inData);
120
121 /* inIndex ������������������������������ inLength ��������������������������� */
122 MDStatus MDArrayDelete(MDArray *arrayRef, int32_t inIndex, int32_t inLength);
123
124 /* inIndex ������������������������������ inLength ��������������� inData ���������������������������������
125 ��������������������������������������������������������������������������������������������� */
126 MDStatus MDArrayReplace(MDArray *arrayRef, int32_t inIndex, int32_t inLength, const void *inData);
127
128 /* inIndex ������������������������������ inLength ��������������� outData ������������������
129 ��������������������������������������������������� */
130 int32_t MDArrayFetch(const MDArray *arrayRef, int32_t inIndex, int32_t inLength, void *outData);
131
132 void * MDArrayFetchPtr(const MDArray *arrayRef, int32_t inIndex);
133
134 /* Simpler Array implementation */
135 void *AssignArray(void *base, int *count, int item_size, int idx, const void *value);
136 void *NewArray(void *base, int *count, int item_size, int nitems);
137 void *InsertArray(void *base, int *count, int item_size, int idx, int nitems, const void *value);
138 void *DeleteArray(void *base, int *count, int item_size, int idx, int nitems, void *outValue);
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif /* __MDUtility__ */

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26