Open Chinese Convert  0.4.3
A project for conversion between Traditional and Simplified Chinese
 All Data Structures Files Functions Variables Groups Pages
dict_chain.c
1 /*
2  * Open Chinese Convert
3  *
4  * Copyright 2010-2013 BYVoid <byvoid@byvoid.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include "dict_group.h"
20 #include "dict_chain.h"
21 
22 DictChain* dict_chain_new(Config* config) {
23  DictChain* dict_chain = (DictChain*)malloc(sizeof(DictChain));
24  dict_chain->count = 0;
25  dict_chain->config = config;
26  return dict_chain;
27 }
28 
29 void dict_chain_delete(DictChain* dict_chain) {
30  size_t i;
31  for (i = 0; i < dict_chain->count; i++) {
32  dict_group_delete(dict_chain->groups[i]);
33  }
34  free(dict_chain);
35 }
36 
37 DictGroup* dict_chain_add_group(DictChain* dict_chain) {
38  if (dict_chain->count + 1 == DICTIONARY_GROUP_MAX_COUNT) {
39  return (DictGroup*)-1;
40  }
41  DictGroup* group = dict_group_new(dict_chain);
42  dict_chain->groups[dict_chain->count++] = group;
43  return group;
44 }
45 
46 DictGroup* dict_chain_get_group(DictChain* dict_chain, size_t index) {
47  if (index >= dict_chain->count) {
48  return (DictGroup*)-1;
49  }
50  return dict_chain->groups[index];
51 }