OSDN Git Service

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@294 47198e57-cb75-475f-84c4-a814cd...
[mimic/MiMicSDK.git] / lib / src / NyLPC_cPtrTbl.c
1 /*********************************************************************************\r
2  * PROJECT: MiMic\r
3  * --------------------------------------------------------------------------------\r
4  *\r
5  * This file is part of MiMic\r
6  * Copyright (C)2011 Ryo Iizuka\r
7  *\r
8  * MiMic is free software: you can redistribute it and/or modify\r
9  * it under the terms of the GNU Lesser General Public License as published\r
10  * by the Free Software Foundation, either version 3 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU Lesser General Public License\r
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
20  *\r
21  * For further information please contact.\r
22  *      http://nyatla.jp/\r
23  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
24  *\r
25  *********************************************************************************/\r
26 #include "NyLPC_cPtrTbl.h"\r
27 \r
28 void NyLPC_cPtrTbl_initialize(NyLPC_TcPtrTbl_t* i_inst,void** i_buf,NyLPC_TUInt16 i_size)\r
29 {\r
30         i_inst->size=i_size;\r
31         i_inst->len=0;\r
32         i_inst->buf=i_buf;\r
33         memset(i_inst->buf,0,i_size*sizeof(void*));\r
34 }\r
35 void* NyLPC_cPtrTbl_get(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index)\r
36 {\r
37         return i_inst->buf[i_index];\r
38 }\r
39 \r
40 void NyLPC_cPtrTbl_set(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index,void* i_val)\r
41 {\r
42         void** p=(i_inst->buf+i_index);\r
43         if(*p==NULL){\r
44                 if(i_val!=NULL){\r
45                         //投入\r
46                         i_inst->len++;\r
47                 }\r
48         }else{\r
49                 if(i_val==NULL){\r
50                         //消去\r
51                         i_inst->len--;\r
52                 }\r
53         }\r
54         //値を反映\r
55         *p=i_val;\r
56         return;\r
57 }\r
58 \r
59 NyLPC_TInt16 NyLPC_cPtrTbl_add(NyLPC_TcPtrTbl_t* i_inst,void* i_val)\r
60 {\r
61         int i;\r
62         void** p=i_inst->buf;\r
63 \r
64         for(i=i_inst->size-1;i>=0;i--){\r
65                 if(*(p+i)==NULL){\r
66                         NyLPC_cPtrTbl_set(i_inst,i,i_val);\r
67                         return i;\r
68                 }\r
69         }\r
70         return -1;\r
71 }\r
72 \r
73 /**\r
74  * i_indexの要素に、NULLをセットして削除します。\r
75  */\r
76 void NyLPC_cPtrTbl_remove(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index)\r
77 {\r
78         NyLPC_cPtrTbl_set(i_inst,i_index,NULL);\r
79         return;\r
80 }\r
81 \r
82 NyLPC_TInt16 NyLPC_cPtrTbl_getIndex(NyLPC_TcPtrTbl_t* i_inst,void* i_val)\r
83 {\r
84         int i;\r
85         void** p=i_inst->buf;\r
86 \r
87         for(i=i_inst->size-1;i>=0;i--){\r
88                 if(*(p+i)==i_val){\r
89                         return i;\r
90                 }\r
91         }\r
92         return -1;\r
93 }\r
94 \r
95 /**\r
96  * 現在の要素数を返します。\r
97  * この数は、テーブルに存在する有効なポインタの数です。\r
98  */\r
99 NyLPC_TInt16 NyLPC_cPtrTbl_getLength(NyLPC_TcPtrTbl_t* i_inst)\r
100 {\r
101         return i_inst->len;\r
102 }\r
103 \r
104 NyLPC_TBool NyLPC_cPtrTbl_hasEmpty(NyLPC_TcPtrTbl_t* i_inst)\r
105 {\r
106         return i_inst->len<i_inst->size;\r
107 }\r