[855] | 1 | /**************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * FIvfLevelInfo.cpp -- File functions for document levels
|
---|
| 4 | * Copyright (C) 1999 Rodger McNab
|
---|
| 5 | *
|
---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
---|
| 7 | * it under the terms of the GNU General Public License as published by
|
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | * (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This program is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | * GNU General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU General Public License
|
---|
| 17 | * along with this program; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | *
|
---|
| 20 | * $Id: FIvfLevelInfo.cpp 855 2000-01-14 02:17:52Z sjboddie $
|
---|
| 21 | *
|
---|
| 22 | **************************************************************************/
|
---|
| 23 |
|
---|
| 24 | #include "FIvfLevelInfo.h"
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | IvfLevelInfo::IvfLevelInfo () {
|
---|
| 28 | Clear();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | void IvfLevelInfo::Clear () {
|
---|
| 32 | levelTag.erase (levelTag.begin(), levelTag.end());
|
---|
| 33 | numEntries = 0;
|
---|
| 34 | approxWeightsDiskPtr = 0;
|
---|
| 35 | exactWeightsDiskPtr = 0;
|
---|
| 36 | workInLevel = false;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | bool IvfLevelInfo::Read (FILE *f) {
|
---|
| 40 | workInLevel = false;
|
---|
| 41 | return (ReadUCArray (f, levelTag) &&
|
---|
| 42 | ReadUL (f, numEntries) &&
|
---|
| 43 | ReadUL (f, approxWeightsDiskPtr) &&
|
---|
| 44 | ReadUL (f, exactWeightsDiskPtr));
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | bool IvfLevelInfo::Write (FILE *f) const {
|
---|
| 48 | return (WriteUCArray (f, levelTag) &&
|
---|
| 49 | WriteUL (f, numEntries) &&
|
---|
| 50 | WriteUL (f, approxWeightsDiskPtr) &&
|
---|
| 51 | WriteUL (f, exactWeightsDiskPtr));
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // stream output for debugging purposes
|
---|
| 55 | ostream &operator<<(ostream &s, const IvfLevelInfo &l) {
|
---|
| 56 | s << " Tag: \"" << l.levelTag << "\"\n"
|
---|
| 57 | << " numEntries: " << l.numEntries << "\n"
|
---|
| 58 | << " approxWeightsDiskPtr: " << l.approxWeightsDiskPtr << "\n"
|
---|
| 59 | << " exactWeightsDiskPtr: " << l.exactWeightsDiskPtr << "\n"
|
---|
| 60 | << " workInLevel: " << ((l.workInLevel) ? "true" : "false") << "\n\n";
|
---|
| 61 |
|
---|
| 62 | return s;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | FIvfLevel::FIvfLevel () {
|
---|
| 68 | Clear ();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void FIvfLevel::Clear () {
|
---|
| 72 | docTag.erase (docTag.begin(), docTag.end());
|
---|
| 73 | indexLevel.erase (indexLevel.begin(), indexLevel.end());
|
---|
| 74 | levelInfo.erase (levelInfo.begin(), levelInfo.end());
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | bool FIvfLevel::Read (FILE *f) {
|
---|
| 78 | if (!ReadUCArray (f, docTag) ||
|
---|
| 79 | !ReadUCArray (f, indexLevel))
|
---|
| 80 | return false;
|
---|
| 81 |
|
---|
| 82 | // read in the array size
|
---|
| 83 | unsigned long arrSize = 0;
|
---|
| 84 | if (!ReadVarLenUL (f, arrSize)) return false;
|
---|
| 85 |
|
---|
| 86 | IvfLevelInfo thisLevel;
|
---|
| 87 | while (arrSize > 0) {
|
---|
| 88 | // read and insert the next level information
|
---|
| 89 | if (!thisLevel.Read (f)) return false;
|
---|
| 90 | levelInfo[thisLevel.levelTag] = thisLevel;
|
---|
| 91 |
|
---|
| 92 | arrSize--;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | return true;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | bool FIvfLevel::Write (FILE *f) const {
|
---|
| 99 | if (!WriteUCArray (f, docTag) ||
|
---|
| 100 | !WriteUCArray (f, indexLevel))
|
---|
| 101 | return false;
|
---|
| 102 |
|
---|
| 103 | // write out the array size
|
---|
| 104 | if (!WriteVarLenUL (f, levelInfo.size())) return false;
|
---|
| 105 |
|
---|
| 106 | // write out each level info
|
---|
| 107 | IvfLevelInfoMap::const_iterator here = levelInfo.begin();
|
---|
| 108 | IvfLevelInfoMap::const_iterator end = levelInfo.end();
|
---|
| 109 | while (here != end) {
|
---|
| 110 | if (!(*here).second.Write (f)) return false;
|
---|
| 111 |
|
---|
| 112 | here++;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | return true;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | // stream output for debugging purposes
|
---|
| 119 | ostream &operator<<(ostream &s, const FIvfLevel &l) {
|
---|
| 120 | s << "docTag: \"" << l.docTag << "\"\n"
|
---|
| 121 | << "indexLevel: \"" << l.indexLevel << "\"\n";
|
---|
| 122 |
|
---|
| 123 | IvfLevelInfoMap::const_iterator here = l.levelInfo.begin ();
|
---|
| 124 | IvfLevelInfoMap::const_iterator end = l.levelInfo.end ();
|
---|
| 125 | while (here != end) {
|
---|
| 126 | s << (*here).second;
|
---|
| 127 | here++;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | return s;
|
---|
| 131 | }
|
---|