source: gsdl/trunk/packages/isis-gdl/XRFFile.h@ 14171

Last change on this file since 14171 was 6127, checked in by mdewsnip, 20 years ago

IsisGdl package for reading CDS/ISIS databases. Provided by Jean-Claude Dauphin at UNESCO, and modified slightly to compile and run under Linux.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/**********************************************************************
2 *
3 * XRFFile.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// XRFFILE.H : Cross Ref File object
28//
29////////////////////////////////////////////////////////////
30
31#ifndef _XRFFILE_H_
32#define _XRFFILE_H_
33#ifndef _BLKFILE_H_
34#include "blkfile.h"
35#endif
36#include <assert.h>
37#include "IErrors.h"
38
39const int MAXTIV = 127; // # of XRF entries per block
40const int XRFBLKSIZE = 512; //
41const int MAXMFB = 1048576;
42
43
44
45/////////////////////////////////////////
46// Cross reference file data structures
47//
48
49
50struct MSTA_ENTRY // Unpacked MST address
51{
52 long xrfmfb_; // Master file block
53 short int xrfmfp_; // Offset
54} ;
55
56struct XRFA // To strore unpacked addresses
57{
58 long xrfpos_; // Block number on xrf_ file or -1 if empty
59 short int xrfeof_; // 1 if last block of xrf_ file
60 MSTA_ENTRY xrftiv_[MAXTIV]; // MAXTIV unpacked MST addresses
61
62 XRFA() { Init(); }
63
64 void Init()
65 {
66 xrfeof_ = 0; // Not eof
67 xrfpos_ = -1; // empty
68 for (int i=0; i<MAXTIV; i++)
69 {
70 xrftiv_[i].xrfmfb_ = -1;
71 xrftiv_[i].xrfmfp_ = 0;
72 }
73 }
74
75
76} ;
77
78struct XRF // To store packed addresses
79{ // for reading and wrting
80 long xrfpos_; // block number on xrf_ file
81 long xrftiv_[MAXTIV]; // MAXTIV packed MST addresses
82} ;
83
84///////////////////
85// XrfFile class
86//
87
88
89class XrfFile : public BlkFile
90{
91private:
92 XRF* xrf_; // Buffer to store packed addresses
93 XRFA* xrfa_; // Buffer to store unpacked addresses
94 long last_block_; // Should always contain the last allocated block
95
96 void ReadXrf(long b);
97 void WriteXrf(long b);
98 void UnPack();
99 void Pack();
100 void Grow(long from_lastb, long to_lastb);
101public:
102 XrfFile();
103 IsisError OpenXrf(const _TCHAR *fname,
104 FileSystem::AccessMode mode = FileSystem::FILE_READWRITE);
105 IsisError CreateXrf(const _TCHAR *fname);
106 IsisError CreateXrf(const _TCHAR *fname, long nextMfn);
107 ~XrfFile();
108 int GetMfp(long mfn, long& mfb, int& mfp);
109 void PutMfp(long mfn, long mfb, int mfp, int status);
110};
111
112//////////////////////////////
113
114inline XrfFile::XrfFile() :
115// Makes a XrfFile object that isn't connected to a file
116 xrf_(new XRF),
117 xrfa_(new XRFA)
118{
119 last_block_ = -1; // Not yet initialize
120 // Nothing more to do
121}
122
123//////////////////////////////
124
125
126inline XrfFile::~XrfFile()
127{
128 if (xrf_) delete xrf_;
129 if (xrfa_) delete xrfa_;
130}
131
132//////////////////////////////
133
134inline void XrfFile::ReadXrf(long b)
135// Reads block # b into xrf_ buffer
136{
137 assert(b>0);
138 ReadBlk(xrf_, b);
139 UnPack();
140}
141
142//////////////////////////////
143
144inline void XrfFile::WriteXrf(long b)
145// Writes the content of xrf_ buffer as block number b
146{
147 assert(b>0);
148 Pack();
149 WriteBlk(xrf_, b);
150}
151#endif
Note: See TracBrowser for help on using the repository browser.