2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: DataBase.h /main/6 1996/10/26 18:17:26 cde-hal $ -*- c++ -*- */
28 #include "Exceptions.hh"
29 #include "object/c_codes.h" /* mmdb codes */
30 #include "oliasdb/olias_consts.h"
35 class PosixError : public Exception{
39 enum { MAXMSG = 200 };
41 PosixError(int error_no, const char *msg)
43 *((char *) memcpy(f_msg, msg, MAXMSG+1) + MAXMSG+1) = '\0'; };
45 const char *msg(void) const { return f_msg; };
46 int error_no(void) const { return f_errno; };
48 DECLARE_EXCEPTION(PosixError, Exception);
56 #define DATABASE_DIRECTORY_MODE 0775
58 #define DATABASE_STDIO "-"
65 * USE: const char *dir = "/some/dir/for/all/the/tables";
67 * assert(strcmp(db->path(), dir) == 0);
69 DB(const char *name); /* a directory, for now */
70 ~DB() { if ( f_name ) delete f_name; }
71 const char *path(void) { return f_name; };
74 typedef enum { READ, CREATE
81 * USE: DBTable *t = db->table("NodeMeta", NODE_CODE, 4, CREATE);
82 * where NODE_CODE is an MMDB object code, and 4
83 * is the number of "columns" in the table, i.e. the
84 * number of items you're going to pass to each call to
87 * CREATE creates a file named "NodeMeta" in db's directory.
88 * READ opens a file named "NodeMeta" in db's directory.
90 DBTable *table(const char *name,
91 int schema_code, int cols,
92 int a = READ); /* throw PosixError */
100 #define BT_NUM_DOC_FIELDS 6
101 #define BT_NUM_LOCATOR_FIELDS 3
102 #define BT_NUM_GRAPHIC_FIELDS 6
103 #define BT_NUM_STYLESHEET_FIELDS 3
104 #define BT_NUM_OLIAS_NODE_FIELDS 7
108 friend class DBCursor;
115 * USE: int intlist = 4;
116 * table->insert(INTEGER_CODE, 4,
117 * STRING_CODE, "xyz",
118 * -STRING_CODE, "abcd", 4,
119 * SHORT_LIST_CODE, 1, INTEGER_CODE, &intlist,
122 void insert(int typecode, ...);
124 void insert_untagged(int typecode, ...);
126 const char *name() { return f_name; };
132 DBTable(DB* database, int schema_code, int cols, const char *name);
134 FILE *file(DB::Access);
142 int f_start; /* at start of linked list */
148 DBCursor(DBTable &t);
152 * USE: DBTable t(...);
157 * while(c.next(STRING_CODE, &f1,
163 int next(int code, ...);
165 void undoNext(); /* seek back to the beginning of the last record read
166 * throw(PosixError) on unseekable device
168 void local_rewind(); /* restart at the beginning of the table file */
169 int tell(); /* current position of the file */
170 void seekToRec( int pos ); /* seek directly to pos */
173 void string_field(FILE *, char **, int *);
174 void int_field(FILE *, int *);
175 void short_list(FILE *, int *, int, void*);
179 class StringList *f_fields;
180 class StringList *f_list;
185 #endif /* __DataBase_h */