Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / BookCaseDB.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: BookCaseDB.C /main/4 1996/10/26 18:17:13 cde-hal $ */
24
25 #include "BookCaseDB.h"
26
27 #include <assert.h>
28
29 /*--------------------------------------------------------------------
30  *
31  * The BookCase is represented as a database (a directory) containing
32  * several tables (files).
33  *
34  * As the tables are shared by many tasks within the bookcase task,
35  * they are accessed through the bookcase, and created here...
36  *
37  *--------------------------------------------------------------------*/
38
39 /* This will be placed in a global .h file eventually */
40 #define LINK_CODE 1333
41
42
43 BookCaseDB::BookCaseDB(const char *dir)
44      : DB(dir)
45 {
46   for(int i = 0; i < TableQty; i++){
47     f_tables[i] = NULL;
48   }
49 }
50
51
52 //--------------------------------------------------------------------
53
54 struct Schema{
55   int         id;
56   const char *name;
57   int         code;
58   int         cols;
59 };
60
61 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
62
63 //--------------------------------------------------------------------
64 DBTable*
65 BookCaseDB::table(int tid, int a)
66 {
67   static Schema schema[] = {
68     { BookMeta,  "BookMeta",     DOC_CODE,           6 },
69     { NodeMeta,  "NodeMeta",     NODE_CODE,          8 },
70     { NodeSGML,  "NodeSGML",     SGML_CONTENT_CODE,  3 },
71     { Link,      "Link",         LINK_CODE,          3 },
72     { Locator,   "Locator",      LOCATOR_CODE,       5 },
73     { TOCTree,   "ContentsTree", TOC_CODE,           5 },
74     { TOCPath,   "ContentsPath", DLP_CODE,           4 },
75     { Graphics,  "Graphics",     GRAPHIC_CODE,       7 },
76     { StyleSheet,  "StyleSheet", NODE_CODE,          3 },
77     { XRef,      "XRef",         XREF_CODE,          4 },
78  };
79
80   assert(tid >= 0 && tid < TableQty);
81   assert(schema[tid].id == tid); /* just be sure the code doesn't get out
82                                  * of sync.
83                                  */
84   if(!f_tables[tid]){
85     f_tables[tid] = DB::table(schema[tid].name,
86                               schema[tid].code,
87                               schema[tid].cols,
88                               a);
89   }
90
91   return f_tables[tid];
92 }
93
94 BookCaseDB::~BookCaseDB()
95 {
96   for( int i = 0; i < TableQty; i++ ) {
97     if ( f_tables[i] ) {
98       delete f_tables[i]; f_tables[i] = 0;
99     }
100   }
101 }
102
103