source: main/trunk/greenstone2/build-src/packages/isis-gdl/IsisDb.cpp

Last change on this file was 34961, checked in by anupama, 3 years ago

Merging Dr Bainbridge's mg-long related updates for IsisGdl that got IsisGdl working on 64 bit linux, and on new Macs that were no longer backwards compatible with 32 bit. Tested only to compile and run (CDS-ISIS tutorial) on 64 bit linux. Merged version of code untested on Mac, though it was used to generate the static 64 bit Mac IsisGdl before. Also untested on 32 bit linux, but Dr Bainbridge had earlier indicated it was backwards. At present the release kit code is still grabbing the statically built IsisGdl (for 32 and nowadayas also 64 bit Mac/Linux) as before and including in binaries. This can be changed later. These code changes are for locally compiling up GS from SVN with an IsisGdl built on the local machine meant to work on that local machine.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/**********************************************************************
2 *
3 * IsisDb.cpp
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// ISISDB: Isis Master file methods
28////////////////////////////////////////////////////////////
29#include "stdafx.h"
30#include "IsisDb.h"
31#include "XRFFile.h"
32
33
34
35//--------------------------------------------------------------------------------
36// IsisDb::IsisDb()
37//
38// Constructor, Makes an ISIS Data Base object that isn't connected to a Master
39// file, Cross Reference file and Fdt.
40//-------------------------------------------------------------------------------
41IsisDb::IsisDb()
42{
43 bReadOnly_ = false;
44 try
45 {
46 mf_ = new MfFile;
47 xf_ = new XrfFile;
48 fdt_ = new CFdt;
49 }
50 catch(std::bad_alloc)
51 {
52 throw CIsisDbException(ISIS_BAD_ALLOC, __FILE__, __LINE__);
53 }
54}
55
56//////////////////////////////
57
58IsisDb::~IsisDb( )
59{
60 delete mf_; delete xf_; delete fdt_;
61}
62
63
64//////////////////////////////
65
66int IsisDb::CreateDb(const TCHAR *fname)
67{
68 name = fname;
69 MkNames();
70 int rc = ISIS_NO_ERROR;
71
72 // We should not try to create a mf_ which already exist!
73 if (CFileBase::Exists(mfname_))
74 {
75 throw CIsisDbException(ISIS_MF_ALREADY_EXIST_ERROR, __FILE__, __LINE__);
76 }
77 else
78 {
79 try
80 {
81 rc = mf_->CreateMf(mfname_, USERMST);
82 rc = xf_->CreateXrf(xrfname_);
83 rc = fdt_->Load(fdtname_);
84 }
85 catch(CIsisDbException)
86 {
87 throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
88 }
89 }
90
91 return rc;
92}
93
94
95//////////////////////////////
96
97void IsisDb::CloseDb()
98{
99 mf_->CloseMf();
100 xf_->Close();
101}
102
103//////////////////////////////
104
105void IsisDb::MkNames()
106// Make file names
107{
108 const _TCHAR *s = name.c_str();
109 _TCHAR *ps = new _TCHAR[_tcslen(s)+1];
110 _tcscpy(ps, s);
111 _TCHAR * tmp = _tcsrchr(ps, _T('.'));
112 assert(tmp != NULL);
113 // Terminate the string at the last dot
114 *tmp = _T('\0');
115
116 _tcscpy(mfname_,ps);
117 _tcscat(mfname_,_T(".mst"));
118 _tcscpy(xrfname_,ps);
119 _tcscat(xrfname_,_T(".xrf"));
120 _tcscpy(fdtname_,ps);
121 _tcscat(fdtname_,_T(".fdt"));
122 _tcscpy(idxname_,ps);
123 _tcscat(idxname_,_T(".idx"));
124 delete[] ps;
125}
126
127//////////////////////////////
128
129int IsisDb::OpenDb(const TCHAR *fname, FileSystem::AccessMode mode
130 /* = FileSystem::FILE_READWRITE */)
131{
132 name = fname;
133 MkNames();
134 int rc;
135 try
136 {
137 // if (FileSystem::IsReadOnly(mfname_))
138 // mode = FileSystem::FILE_READONLY;
139 rc = mf_->OpenMf(mfname_, mode);
140 rc = xf_->OpenXrf(xrfname_, mode);
141 rc = fdt_->Load(fdtname_);
142 }
143 catch(CIsisDbException)
144 {
145 throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
146 }
147
148 return rc;
149}
150
151//----------------------------------------------------------------------------------
152// int IsisDb::ReadDbRecord(mg_s_long mfn, MfRecord &m)
153//
154// This function reads Master File record with MFN "mfn" into m
155//
156// Returns the status of the record:
157// Active=0, LogicalyDeleted=1, PhysicalyDeleted=2, EndOfFile=-1, NewRecord = 3
158//----------------------------------------------------------------------------------
159int IsisDb::ReadDbRecord(mg_s_long mfn, MfRecord &m)
160{
161 mg_s_long mfb;
162 int mfp;
163 int status;
164 bool rc;
165
166 try
167 {
168 status = xf_->GetMfp(mfn, mfb, mfp);
169 if (status == Active || status == LogicalyDeleted)
170 if (!mf_->ReadMfRecord(mfb, mfp, m))
171 status = -1; // Error in reading the record!
172 }
173 catch(CIsisDbException)
174 {
175 throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
176 }
177 return status;
178}
179
180//--------------------------------------------------------------------------------
181// void CreateDbRecord(MfRecord &m)
182//
183// Create a new record at the end of the master file. The Master file address is
184// set into the pair mfb/mfp and the XRF file is updated.
185//---------------------------------------------------------------------------------
186 void IsisDb::CreateDbRecord(MfRecord &m)
187{
188
189}
190
191//--------------------------------------------------------------------------------
192// void CreateDbRecordWithMfn(MfRecord &m)
193//
194// Create a new record at the end of the master file. The Master file address is
195// set into the pair mfb/mfp and the XRF file is updated.
196//---------------------------------------------------------------------------------
197 void IsisDb::CreateDbRecordWithMfn(MfRecord &m)
198{
199
200}
201
202
203//----------------------------------------------------------------------------------
204// void UpdateDbRecord(MfRecord &m)
205//
206// Update of existing records. Whenever a record is updated, the system writes
207// the record back to the master file. Where it is written depends on the status
208// of the record when it was initially read.
209//
210//----------------------------------------------------------------------------------
211 void IsisDb::UpdateDbRecord(MfRecord &m)
212{
213}
214//----------------------------------------------------------------------------------
215// int IsisDb::DeleteRecord(mg_s_long mfn)
216//
217// This function logically deletes a Master File record with MFN "mfn".
218// On XRF, xrfmfb is negative and on MST, status is set to 1
219//
220// Returns true if successful
221//----------------------------------------------------------------------------------
222bool IsisDb::DeleteRecord(mg_s_long mfn)
223{
224
225 return false;
226}
227
228mg_s_long IsisDb::GetNextActiveMfn(mg_s_long mfn /* = -1 */)
229{
230 if (mfn == -1)
231 mfn = 1;
232 else
233 mfn++;
234 mg_s_long mfb;
235 int mfp;
236 int iRet = xf_->GetMfp(mfn, mfb, mfp);
237 while (iRet != Active && iRet != EndOfFile)
238 {
239 mfn++;
240 iRet = xf_->GetMfp(mfn, mfb, mfp);
241 }
242 if (iRet == EndOfFile)
243 return 0;
244 else
245 return mfn;
246}
247
248_TCHAR *IsisDb::GetIdxFileName()
249{
250 return idxname_;
251}
252
Note: See TracBrowser for help on using the repository browser.