1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * Fdt.h
|
---|
4 | * Copyright (C) 2003 UNESCO
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | ////////////////////////////////////////////////////////////////////////////////////
|
---|
27 | // Fdt.h
|
---|
28 |
|
---|
29 | #ifndef __FDT_H__
|
---|
30 | #define __FDT_H__
|
---|
31 |
|
---|
32 | #include <vector>
|
---|
33 | #include "mytchar.h"
|
---|
34 |
|
---|
35 | #define FDT_NAME_LENG 30 // maximum name length in FDT_FILE
|
---|
36 | #define FDT_SFLD_LENG 20 // maximum subfield length in FDT_FILE
|
---|
37 |
|
---|
38 | #ifndef __CFIELDDEF__
|
---|
39 | #define __CFIELDDEF__
|
---|
40 |
|
---|
41 | class CFieldDef
|
---|
42 | {
|
---|
43 | public:
|
---|
44 | enum FieldType {
|
---|
45 | charField = 'C',
|
---|
46 | dateField = 'D',
|
---|
47 | numericField = 'N',
|
---|
48 | logicalField = 'L',
|
---|
49 | memoField = 'M'
|
---|
50 | };
|
---|
51 |
|
---|
52 | char name[31]; // dbf field names are 10 chars long max.
|
---|
53 | // If this application is compiled with _UNICODE switch,
|
---|
54 | // the field name will be converted to wide chars
|
---|
55 | // when the column header is displayed in the grid.
|
---|
56 | char type;
|
---|
57 | short len;
|
---|
58 | short width;
|
---|
59 | short decimals;
|
---|
60 | int offset;
|
---|
61 | short display_width;
|
---|
62 | };
|
---|
63 | #endif // __CFIELDDEF__
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | class CFdtEntry
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | CFdtEntry() : tag(0), len(0), type(0), rep(0)
|
---|
71 | { name[0] = '\0'; subfields[0] = '\0'; }
|
---|
72 | void Clear()
|
---|
73 | {
|
---|
74 | tag = len = type = rep = 0;
|
---|
75 | name[0] = '\0'; subfields[0] = '\0';
|
---|
76 | }
|
---|
77 | char name[FDT_NAME_LENG+1];
|
---|
78 | char subfields[FDT_SFLD_LENG+1];
|
---|
79 | int tag;
|
---|
80 | int len;
|
---|
81 | int type; //X=0
|
---|
82 | int rep; //repeatable 1, non rep. 0
|
---|
83 | CFdtEntry& operator=(const CFdtEntry& rhs)
|
---|
84 | {
|
---|
85 | if (&name[0] != &rhs.name[0])
|
---|
86 | {
|
---|
87 | Copy(rhs);
|
---|
88 | }
|
---|
89 | return *this;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void Copy(const CFdtEntry &rhs)
|
---|
93 | {
|
---|
94 | strcpy(name, rhs.name);
|
---|
95 | strcpy(subfields, rhs.subfields);
|
---|
96 | tag = rhs.tag;
|
---|
97 | len = rhs.len;
|
---|
98 | type = rhs.type;
|
---|
99 | rep = rhs.rep;
|
---|
100 | }
|
---|
101 | };
|
---|
102 |
|
---|
103 |
|
---|
104 | void FormatFdtEntry(CFdtEntry &e, ustring &s);
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | class CFdt
|
---|
109 | {
|
---|
110 | protected:
|
---|
111 | std::vector<CFdtEntry> m_aFdt;
|
---|
112 | int m_nFieldCount; // Num. of fields
|
---|
113 | std::vector<CFieldDef*> m_fieldArray; // Array with fields
|
---|
114 |
|
---|
115 | long m_iCurrentRecord; // Current read record stored in
|
---|
116 | CFdtEntry m_fdtEntry;
|
---|
117 | bool m_bReadOnly;
|
---|
118 | bool m_bIsEmpty;
|
---|
119 | bool m_bDirty; // True if m_fdtEntry modified
|
---|
120 | bool m_bAppend;
|
---|
121 | public:
|
---|
122 | ustring m_sFileName; // Fdt full pathname
|
---|
123 | std::vector<std::string> m_asPrelude; // What is bef ***
|
---|
124 | public:
|
---|
125 | CFdt();
|
---|
126 | virtual ~CFdt();
|
---|
127 |
|
---|
128 | bool Load(const _TCHAR *fname);
|
---|
129 | int GetEntryCount() { return m_aFdt.size(); }
|
---|
130 |
|
---|
131 | CFdtEntry GetEntryAt(int i)
|
---|
132 | {
|
---|
133 | #ifdef _WIN32
|
---|
134 | return m_aFdt.at(i);
|
---|
135 | #else
|
---|
136 | return m_aFdt[i];
|
---|
137 | #endif
|
---|
138 | }
|
---|
139 |
|
---|
140 | int GetFieldCount() { return m_nFieldCount; }
|
---|
141 |
|
---|
142 | bool Open(const char* szFileName, bool readOnly=true);
|
---|
143 |
|
---|
144 | void InitData();
|
---|
145 |
|
---|
146 | void Close();
|
---|
147 |
|
---|
148 | void DeleteContents();
|
---|
149 |
|
---|
150 | void Store(const char* fileName);
|
---|
151 | int InitFields ();
|
---|
152 |
|
---|
153 | CFieldDef* GetField(int n) const;
|
---|
154 |
|
---|
155 | CFdtEntry GetAt(int i);
|
---|
156 |
|
---|
157 | const CFdtEntry GetAt(int i) const;
|
---|
158 |
|
---|
159 | int Append(CFdtEntry& e);
|
---|
160 |
|
---|
161 | void RemoveAt(int i);
|
---|
162 | void SetAt(int i, CFdtEntry& e);
|
---|
163 |
|
---|
164 | bool Seek(long iRecord);
|
---|
165 | void Flush();
|
---|
166 | bool GetValue(int n, std::string& result);
|
---|
167 | bool SetValue(int n, const char* pszValue);
|
---|
168 |
|
---|
169 | int GetRecordCount() { return m_aFdt.size(); }
|
---|
170 | };
|
---|
171 |
|
---|
172 | #endif
|
---|