📄 tcutil.3
字号:
.TH "TCUTIL" 3 "2009-02-13" "Man Page" "Tokyo Cabinet".SH NAMEtcutil \- the utility API.SH DESCRIPTION.PPThe utility API is a set of routines to handle records on memory easily. Especially, extensible string, array list, hash map, and ordered tree are useful..PPTo use the utility API, include `\fBtcutil.h\fR' and related standard header files. Usually, write the following description near the front of a source file..PP.RS.br\fB#include <tcutil.h>\fR.br\fB#include <stdlib.h>\fR.br\fB#include <time.h>\fR.br\fB#include <stdbool.h>\fR.br\fB#include <stdint.h>\fR.RE.PPObjects whose type is pointer to `\fBTCXSTR\fR' are used for extensible string. An extensible string object is created with the function `\fBtcxstrnew\fR' and is deleted with the function `\fBtcxstrdel\fR'. Objects whose type is pointer to `\fBTCLIST\fR' are used for array list. A list object is created with the function `\fBtclistnew\fR' and is deleted with the function `\fBtclistdel\fR'. Objects whose type is pointer to `\fBTCMAP\fR' are used for hash map. A map object is created with the function `\fBtcmapnew\fR' and is deleted with the function `\fBtcmapdel\fR'. Objects whose type is pointer to `\fBTCTREE\fR' are used for ordered tree. A tree object is created with the function `\fBtctreenew\fR' and is deleted with the function `\fBtctreedel\fR'. To avoid memory leak, it is important to delete every object when it is no longer in use..SH API OF BASIC UTILITIES.PPThe constant `tcversion' is the string containing the version information..PP.RS.br\fBextern const char *tcversion;\fR.RE.PPThe variable `tcfatalfunc' is the pointer to the call back function for handling a fatal error..PP.RS.br\fBextern void (*tcfatalfunc)(const char *);\fR.RSThe argument specifies the error message..RE.RSThe initial value of this variable is `NULL'. If the value is `NULL', the default function is called when a fatal error occurs. A fatal error occurs when memory allocation is failed..RE.RE.PPThe function `tcmalloc' is used in order to allocate a region on memory..PP.RS.br\fBvoid *tcmalloc(size_t \fIsize\fB);\fR.RS`\fIsize\fR' specifies the size of the region..RE.RSThe return value is the pointer to the allocated region..RE.RSThis function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.PPThe function `tccalloc' is used in order to allocate a nullified region on memory..PP.RS.br\fBvoid *tccalloc(size_t \fInmemb\fB, size_t \fIsize\fB);\fR.RS`\fInmemb\fR' specifies the number of elements..RE.RS`\fIsize\fR' specifies the size of each element..RE.RSThe return value is the pointer to the allocated nullified region..RE.RSThis function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `calloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.PPThe function `tcrealloc' is used in order to re\-allocate a region on memory..PP.RS.br\fBvoid *tcrealloc(void *\fIptr\fB, size_t \fIsize\fB);\fR.RS`\fIptr\fR' specifies the pointer to the region..RE.RS`\fIsize\fR' specifies the size of the region..RE.RSThe return value is the pointer to the re\-allocated region..RE.RSThis function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `realloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.PPThe function `tcmemdup' is used in order to duplicate a region on memory..PP.RS.br\fBvoid *tcmemdup(const void *\fIptr\fB, size_t \fIsize\fB);\fR.RS`\fIptr\fR' specifies the pointer to the region..RE.RS`\fIsize\fR' specifies the size of the region..RE.RSThe return value is the pointer to the allocated region of the duplicate..RE.RSBecause an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.PPThe function `tcstrdup' is used in order to duplicate a string on memory..PP.RS.br\fBchar *tcstrdup(const void *\fIstr\fB);\fR.RS`\fIstr\fR' specifies the string..RE.RSThe return value is the allocated string equivalent to the specified string..RE.RSBecause the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.PPThe function `tcfree' is used in order to free a region on memory..PP.RS.br\fBvoid tcfree(void *\fIptr\fB);\fR.RS`\fIptr\fR' specifies the pointer to the region. If it is `NULL', this function has no effect..RE.RSAlthough this function is just a wrapper of `free' call, this is useful in applications using another package of the `malloc' series..RE.RE.SH API OF EXTENSIBLE STRING.PPThe function `tcxstrnew' is used in order to create an extensible string object..PP.RS.br\fBTCXSTR *tcxstrnew(void);\fR.RSThe return value is the new extensible string object..RE.RE.PPThe function `tcxstrnew2' is used in order to create an extensible string object from a character string..PP.RS.br\fBTCXSTR *tcxstrnew2(const char *\fIstr\fB);\fR.RS`\fIstr\fR' specifies the string of the initial content..RE.RSThe return value is the new extensible string object containing the specified string..RE.RE.PPThe function `tcxstrnew3' is used in order to create an extensible string object with the initial allocation size..PP.RS.br\fBTCXSTR *tcxstrnew3(int \fIasiz\fB);\fR.RS`\fIasiz\fR' specifies the initial allocation size..RE.RSThe return value is the new extensible string object..RE.RE.PPThe function `tcxstrdup' is used in order to copy an extensible string object..PP.RS.br\fBTCXSTR *tcxstrdup(const TCXSTR *\fIxstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RSThe return value is the new extensible string object equivalent to the specified object..RE.RE.PPThe function `tcxstrdel' is used in order to delete an extensible string object..PP.RS.br\fBvoid tcxstrdel(TCXSTR *\fIxstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RSNote that the deleted object and its derivatives can not be used anymore..RE.RE.PPThe function `tcxstrcat' is used in order to concatenate a region to the end of an extensible string object..PP.RS.br\fBvoid tcxstrcat(TCXSTR *\fIxstr\fB, const void *\fIptr\fB, int \fIsize\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RS`\fIptr\fR' specifies the pointer to the region to be appended..RE.RS`\fIsize\fR' specifies the size of the region..RE.RE.PPThe function `tcxstrcat2' is used in order to concatenate a character string to the end of an extensible string object..PP.RS.br\fBvoid tcxstrcat2(TCXSTR *\fIxstr\fB, const char *\fIstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RS`\fIstr\fR' specifies the string to be appended..RE.RE.PPThe function `tcxstrptr' is used in order to get the pointer of the region of an extensible string object..PP.RS.br\fBconst void *tcxstrptr(const TCXSTR *\fIxstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RSThe return value is the pointer of the region of the object..RE.RSBecause an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string..RE.RE.PPThe function `tcxstrsize' is used in order to get the size of the region of an extensible string object..PP.RS.br\fBint tcxstrsize(const TCXSTR *\fIxstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RSThe return value is the size of the region of the object..RE.RE.PPThe function `tcxstrclear' is used in order to clear an extensible string object..PP.RS.br\fBvoid tcxstrclear(TCXSTR *\fIxstr\fB);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RSThe internal buffer of the object is cleared and the size is set zero..RE.RE.PPThe function `tcxstrprintf' is used in order to perform formatted output into an extensible string object..PP.RS.br\fBvoid tcxstrprintf(TCXSTR *\fIxstr\fB, const char *\fIformat\fB, ...);\fR.RS`\fIxstr\fR' specifies the extensible string object..RE.RS`\fIformat\fR' specifies the printf\-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary numbers. The other conversion character work as with each original..RE.RSThe other arguments are used according to the format string..RE.RE.PPThe function `tcsprintf' is used in order to allocate a formatted string on memory..PP.RS.br\fBchar *tcsprintf(const char *\fIformat\fB, ...);\fR.RS`\fIformat\fR' specifies the printf\-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary numbers. The other conversion character work as with each original..RE.RSThe other arguments are used according to the format string..RE.RSThe return value is the pointer to the region of the result string..RE.RSBecause the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use..RE.RE.SH API OF ARRAY LIST.PPThe function `tclistnew' is used in order to create a list object..PP.RS.br\fBTCLIST *tclistnew(void);\fR.RSThe return value is the new list object..RE.RE.PPThe function `tclistnew2' is used in order to create a list object with expecting the number of elements..PP.RS.br\fBTCLIST *tclistnew2(int \fIanum\fB);\fR.RS`\fIanum\fR' specifies the number of elements expected to be stored in the list..RE.RSThe return value is the new list object..RE.RE.PPThe function `tclistnew3' is used in order to create a list object with initial string elements..PP.RS.br\fBTCLIST *tclistnew3(const char *\fIstr\fB, ...);\fR.RS`\fIstr\fR' specifies the string of the first element..RE.RSThe other arguments are other elements. They should be trailed by a `NULL' argument..RE.RSThe return value is the new list object..RE.RE.PPThe function `tclistdup' is used in order to copy a list object..PP.RS.br\fBTCLIST *tclistdup(const TCLIST *\fIlist\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RSThe return value is the new list object equivalent to the specified object..RE.RE.PPThe function `tclistdel' is used in order to delete a list object..PP.RS.br\fBvoid tclistdel(TCLIST *\fIlist\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RSNote that the deleted object and its derivatives can not be used anymore..RE.RE.PPThe function `tclistnum' is used in order to get the number of elements of a list object..PP.RS.br\fBint tclistnum(const TCLIST *\fIlist\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RSThe return value is the number of elements of the list..RE.RE.PPThe function `tclistval' is used in order to get the pointer to the region of an element of a list object..PP.RS.br\fBconst void *tclistval(const TCLIST *\fIlist\fB, int \fIindex\fB, int *\fIsp\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RS`\fIindex\fR' specifies the index of the element..RE.RS`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned..RE.RSThe return value is the pointer to the region of the value..RE.RSBecause an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. If `index' is equal to or more than the number of elements, the return value is `NULL'..RE.RE.PPThe function `tclistval2' is used in order to get the string of an element of a list object..PP.RS.br\fBconst char *tclistval2(const TCLIST *\fIlist\fB, int \fIindex\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RS`\fIindex\fR' specifies the index of the element..RE.RSThe return value is the string of the value..RE.RSIf `index' is equal to or more than the number of elements, the return value is `NULL'..RE.RE.PPThe function `tclistpush' is used in order to add an element at the end of a list object..PP.RS.br\fBvoid tclistpush(TCLIST *\fIlist\fB, const void *\fIptr\fB, int \fIsize\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RS`\fIptr\fR' specifies the pointer to the region of the new element..RE.RS`\fIsize\fR' specifies the size of the region..RE.RE.PPThe function `tclistpush2' is used in order to add a string element at the end of a list object..PP.RS.br\fBvoid tclistpush2(TCLIST *\fIlist\fB, const char *\fIstr\fB);\fR.RS`\fIlist\fR' specifies the list object..RE.RS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -