| 1 |
/* |
| 2 |
* AikSaurus - An open source thesaurus library |
| 3 |
* Copyright (C) 2001 by Jared Davis |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 18 |
* 02111-1307, USA. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef INCLUDED_FILEARRAY_H |
| 23 |
#define INCLUDED_FILEARRAY_H |
| 24 |
|
| 25 |
// |
| 26 |
// FileArray Class |
| 27 |
// |
| 28 |
// Treats a file as an array using standard C-style FILE* pointers, |
| 29 |
// fseek, and so forth. Pretty basic, and does some basic error |
| 30 |
// handling stuff. |
| 31 |
// |
| 32 |
|
| 33 |
#include <cstdio> |
| 34 |
|
| 35 |
namespace AiksaurusImpl |
| 36 |
{ |
| 37 |
class FileArray |
| 38 |
{ |
| 39 |
private: |
| 40 |
|
| 41 |
// Prevent copying and assignment. |
| 42 |
FileArray(const FileArray& rhs); |
| 43 |
FileArray& operator=(const FileArray& rhs); |
| 44 |
|
| 45 |
// Pointer to an ANSI-C file structure |
| 46 |
mutable FILE* d_file; |
| 47 |
|
| 48 |
// Size of structures held by the file. |
| 49 |
const long d_structsize; |
| 50 |
|
| 51 |
// File size in bytes. |
| 52 |
mutable bool d_bytes_cached; |
| 53 |
mutable long d_bytes; |
| 54 |
|
| 55 |
public: |
| 56 |
|
| 57 |
// Creation/Destruction |
| 58 |
FileArray(const char* file, long structsize, bool& ok); |
| 59 |
~FileArray(); |
| 60 |
|
| 61 |
|
| 62 |
// Inspection - Bytes in file, structure size. |
| 63 |
long getBytes() const; |
| 64 |
long getStructSize() const; |
| 65 |
|
| 66 |
|
| 67 |
// This is the indexing of sorts. Retrieves element at |
| 68 |
// position, and stores it in buf. Buf must be big enough |
| 69 |
// to hold structsize bytes. |
| 70 |
bool at(long position, unsigned char* buf) const; |
| 71 |
}; |
| 72 |
} |
| 73 |
|
| 74 |
#endif // INCLUDED_FILEARRAY_H |
| 75 |
|