5 // Created by 西田 耀 on 13/01/28.
\r
6 // Copyright (c) 2013年 Hikaru Nishida. All rights reserved.
\r
9 #ifndef AI003_chnlib_h
\r
10 #define AI003_chnlib_h
\r
13 //Set compile environment
\r
16 #define CHNLIB_MAKE_GCC_MAC
\r
17 //#define CHNLIB_MAKE_BCC_WIN
\r
19 #ifdef CHNLIB_MAKE_BCC_WIN
\r
21 #ifndef __FUNCTION__
\r
22 #define __FUNCTION__ "Unknown"
\r
26 #define CHNLIB_DEBUG_ARGUMENTS __FILE__, __LINE__, __FUNCTION__
\r
29 //#define DEBUG_MEMORY_ALLOCATION
\r
30 //#define DEBUG_MEMORY_REFERENCE_COUNT
\r
31 //#define DEBUG_STRING_STRICT
\r
38 typedef unsigned char uchar;
\r
39 typedef unsigned short ushort;
\r
40 typedef unsigned int uint;
\r
42 typedef struct CHNLIB_STRUCTURE_HEADER CHNLIB_StructureHeader;
\r
43 struct CHNLIB_STRUCTURE_HEADER {
\r
47 uint referenceCount;
\r
48 void (*destructor)(void **structrue);
\r
49 uint (*getHash)(const void *structure);
\r
53 typedef struct CHNLIB_UIPARRAY CHNLIB_UIPArray;
\r
55 typedef struct CHNLIB_STRING CHNLIB_String;
\r
57 typedef struct CHNLIB_RANDOM_GENERATOR_MT CHNLIB_RandomGeneratorMT;
\r
59 typedef struct CHNLIB_UniversallyUniqueIDentifier CHNLIB_UUID;
\r
62 //Define library values
\r
65 #define CHNLIB_STRUCTURE_SIGNATURE ((uint)0x4C4E4843) //"CHNL"(Little Endian)
\r
70 #define CHNLIB_STRUCT_ID_Null 0
\r
71 #define CHNLIB_STRUCT_ID_UIPArray 1
\r
72 #define CHNLIB_STRUCT_ID_String 2
\r
73 #define CHNLIB_STRUCT_ID_RandomGeneratorMT 3
\r
74 #define CHNLIB_STRUCT_ID_UUID 4
\r
76 #define CHNLIB_MAX_STRING_LENGTH 4096
\r
78 #define CHNLIB_UIPArray_INDEX_NOTFOUND -1
\r
80 #define retain(structure) CHNLIB_Retain((void **) &structure)
\r
81 #define release(structure) CHNLIB_Release((void **) &structure)
\r
82 #define autorelease(structure) CHNLIB_AutoRelease(structure)
\r
85 //Declare library functions
\r
88 void CHNLIB_Debug(const char format[], const char filename[], int line, const char funcname[], ...);
\r
89 void CHNLIB_Debug_PrintStructureData(void *structure, uint level);
\r
90 void CHNLIB_ReportError(const char format[], const char filename[], int line, const char funcname[], ...); //("", CHNLIB_DEBUG_ARGUMENTS);
\r
91 void CHNLIB_StructureHeader_Initialize(CHNLIB_StructureHeader *header, uint typeid);
\r
92 uint CHNLIB_StructureHeader_GetTypeID(const void *structure);
\r
93 uint CHNLIB_StructureHeader_GetHash(const void *structure);
\r
94 void *CHNLIB_System_AllocateMemory_Strict(int size, const char filename[], int line, const char funcname[]);
\r
95 void CHNLIB_System_FreeMemory(void *p, const char filename[], int line, const char funcname[]);
\r
96 void CHNLIB_Retain(void **structure);
\r
97 void CHNLIB_Release(void **structure);
\r
98 void *CHNLIB_AutoRelease(void *structure);
\r
101 CHNLIB_UIPArray *CHNLIB_UIPArray_Initialize(void);
\r
103 int CHNLIB_UIPArray_AppendLast(CHNLIB_UIPArray **array, uint data32, void *pointer);
\r
104 int CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(CHNLIB_UIPArray **array, uint data32, void *pointer, int (*IsDuplicated)(const void *listtag, const void *newtag));
\r
106 int CHNLIB_UIPArray_RemoveByIndex(CHNLIB_UIPArray **array, int index);
\r
108 void CHNLIB_UIPArray_FreeOnlyArray(CHNLIB_UIPArray **array);
\r
109 void CHNLIB_UIPArray_FreeOnlyAllPointer(CHNLIB_UIPArray *array);
\r
110 void CHNLIB_UIPArray_FreeOnlySelectedPointer(CHNLIB_UIPArray *array);
\r
111 void CHNLIB_UIPArray_FreeAll(CHNLIB_UIPArray **array);
\r
112 void CHNLIB_UIPArray_FreeSelectedAll(CHNLIB_UIPArray **array);
\r
114 int CHNLIB_UIPArray_GetNumberOfDatas(const CHNLIB_UIPArray *array);
\r
116 uint CHNLIB_UIPArray_GetData32ByIndex(const CHNLIB_UIPArray *array, int index);
\r
117 uint CHNLIB_UIPArray_SetData32ByIndex(CHNLIB_UIPArray *array, int index, uint data32);
\r
119 void *CHNLIB_UIPArray_GetPointerByIndex(const CHNLIB_UIPArray *array, int index);
\r
120 void *CHNLIB_UIPArray_GetPointerByData32(const CHNLIB_UIPArray *array, uint data32);
\r
122 int CHNLIB_UIPArray_GetIndexByData32(const CHNLIB_UIPArray *array, uint data32);
\r
124 CHNLIB_UIPArray *CHNLIB_UIPArray_CopyArray(const CHNLIB_UIPArray *source);
\r
125 //----配列のソートしたものを新たに取得
\r
126 CHNLIB_UIPArray *CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(const CHNLIB_UIPArray *array);
\r
130 CHNLIB_String *CHNLIB_String_Initialize(const char str[]);
\r
131 CHNLIB_String *CHNLIB_String_InitializeWithFormat(const char format[], ...);
\r
133 void CHNLIB_String_Free(CHNLIB_String *strtag);
\r
135 int CHNLIB_String_SetStringFromCString(CHNLIB_String *strtag, const char s[]);
\r
137 int CHNLIB_String_Print(CHNLIB_String *strtag);
\r
139 const char *CHNLIB_String_GetReferencePointerOfCString(const CHNLIB_String *strtag);
\r
141 CHNLIB_String *CHNLIB_String_ExtractByLength(const CHNLIB_String *strtag, int start, int len);
\r
143 CHNLIB_String *CHNLIB_String_Concatenate(const CHNLIB_String *s1, const CHNLIB_String *s2);
\r
145 int CHNLIB_String_GetLength(const CHNLIB_String *strtag);
\r
147 void CHNLIB_String_DeleteLastCRLF(CHNLIB_String *strtag);
\r
149 int CHNLIB_String_CompareStringWithCString(const CHNLIB_String *s, const char search[]);
\r
150 int CHNLIB_String_CompareString_Strict(const CHNLIB_String *s, const CHNLIB_String *search);
\r
152 uint CHNLIB_String_GetCountOfContain(const CHNLIB_String *s, const CHNLIB_String *search);
\r
154 CHNLIB_String *CHNLIB_String_Copy(const CHNLIB_String *s);
\r
155 //----低レベルCString関数
\r
156 int CHNLIB_CString_GetByteLength(const char s[]);
\r
157 void CHNLIB_CString_DeleteLastCRLF(char s[]);
\r
158 char *CHNLIB_CString_ExtractByLength(const char s[], int start, int len);
\r
159 int CHNLIB_CString_CompareString(const char s[], const char search[]);
\r
160 int CHNLIB_CString_CompareString_Strict(const char s[], const char search[]);
\r
161 int CHNLIB_CString_CompareString_LeftHand(const char s[], const char search[]);
\r
162 char *CHNLIB_CString_Copy(const char s[]);
\r
163 char *CHNLIB_CString_Concatenate(const char s1[], const char s2[]);
\r
165 int CHNLIB_String_Search_UIPArrayStringLocation(const CHNLIB_String *s, int s_start, const CHNLIB_UIPArray *list, int *location);
\r
166 int CHNLIB_UIPArray_GetSeparatedStringByUIPArray(CHNLIB_UIPArray **separated, const CHNLIB_UIPArray *list, const CHNLIB_String *s);
\r
167 int CHNLIB_UIPArray_GetSeparatedUTF8Character(CHNLIB_UIPArray **separated, const CHNLIB_String *s);
\r
168 CHNLIB_String *CHNLIB_ReadLine(FILE *fp);
\r
169 CHNLIB_UUID *CHNLIB_GenerateUUIDVersion4WithRandomGeneratorMT(CHNLIB_RandomGeneratorMT *mt);
\r
172 void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[]);
\r
173 const char *CHNLIB_Environment_GetFilenameFromPath(const char path[]);
\r
176 int CHNLIB_UTF8_GetCharacterType(char c);
\r
177 int CHNLIB_UTF8_GetStringLengthByCharacter(const char s[]);
\r
178 uint CHNLIB_UTF8_GetNextUnicodeOfCharacter(const char s[], const char **next);
\r
179 int CHNLIB_UTF8_CompareString(const char s[], const char search[]);
\r
180 int CHNLIB_UTF8_CompareString_LeftHand(const char s[], const char search[]);
\r
181 int CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(const char s[], int start, int end);
\r
182 uint CHNLIB_UTF8_GetCountOfContain(const char s[], const char search[]);
\r
185 CHNLIB_RandomGeneratorMT *CHNLIB_RandomGeneratorMT_Initialise(void);
\r
186 void CHNLIB_RandomGeneratorMT_Free(CHNLIB_RandomGeneratorMT *env);
\r
187 void CHNLIB_RandomGeneratorMT_SetSeed(CHNLIB_RandomGeneratorMT *env, unsigned long s);
\r
188 void CHNLIB_RandomGeneratorMT_SetSeedFromArray(CHNLIB_RandomGeneratorMT *env, unsigned long init_key[], int key_length);
\r
189 uint CHNLIB_RandomGeneratorMT_GetRandomUnsignedInteger32(CHNLIB_RandomGeneratorMT *env);
\r
192 CHNLIB_UUID *CHNLIB_UUID_Initialise(void);
\r
193 void CHNLIB_UUID_Free(CHNLIB_UUID *uuid);
\r
194 void CHNLIB_UUID_Print(const CHNLIB_UUID *uuid);
\r
195 int CHNLIB_UUID_IsEqualToUUID(const CHNLIB_UUID *uuid1, const CHNLIB_UUID *uuid2);
\r
196 void CHNLIB_UUID_SetValueAsUUIDVersion4CompatibleWithRFC4122(CHNLIB_UUID *uuid, uint random1, uint random2, uint random3, uint random4);
\r
197 void CHNLIB_UUID_SetNullUUID(CHNLIB_UUID *uuid);
\r
198 CHNLIB_UUID *CHNLIB_UUID_Copy(const CHNLIB_UUID *uuidBase);
\r