root/gsdl/trunk/trunk/mgpp/text/FIvfLevelInfo.cpp @ 16583

Revision 16583, 3.5 KB (checked in by davidb, 12 years ago)

Undoing change commited in r16582

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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 **************************************************************************/
21
22#include "FIvfLevelInfo.h"
23
24
25IvfLevelInfo::IvfLevelInfo () {
26  Clear();
27}
28
29void IvfLevelInfo::Clear () {
30  levelTag.erase (levelTag.begin(), levelTag.end());
31  numEntries = 0;
32  approxWeightsDiskPtr = 0;
33  exactWeightsDiskPtr = 0;
34  workInLevel = false;
35}
36
37bool IvfLevelInfo::Read (FILE *f) {
38  workInLevel = false;
39  return (ReadUCArray (f, levelTag) &&
40      ReadUL (f, numEntries) &&
41      ReadUL (f, approxWeightsDiskPtr) &&
42      ReadUL (f, exactWeightsDiskPtr));
43}
44
45bool IvfLevelInfo::Write (FILE *f) const {
46  return (WriteUCArray (f, levelTag) &&
47      WriteUL (f, numEntries) &&
48      WriteUL (f, approxWeightsDiskPtr) &&
49      WriteUL (f, exactWeightsDiskPtr));
50}
51
52// stream output for debugging purposes
53ostream &operator<<(ostream &s, const IvfLevelInfo &l) {
54  s << "  Tag: \"" << l.levelTag << "\"\n"
55    << "  numEntries: " << l.numEntries << "\n"
56    << "  approxWeightsDiskPtr: " << l.approxWeightsDiskPtr << "\n"
57    << "  exactWeightsDiskPtr: " << l.exactWeightsDiskPtr << "\n"
58    << "  workInLevel: " << ((l.workInLevel) ? "true" : "false") << "\n\n";
59 
60  return s;
61}
62
63
64
65FIvfLevel::FIvfLevel () {
66  Clear ();
67}
68
69void FIvfLevel::Clear () {
70  docTag.erase (docTag.begin(), docTag.end());
71  indexLevel.erase (indexLevel.begin(), indexLevel.end());
72  levelInfo.erase (levelInfo.begin(), levelInfo.end());
73}
74
75bool FIvfLevel::Read (FILE *f) {
76  if (!ReadUCArray (f, docTag) ||
77      !ReadUCArray (f, indexLevel))
78    return false;
79 
80  // read in the array size
81  unsigned long arrSize = 0;
82  if (!ReadVarLenUL (f, arrSize)) return false;
83 
84  IvfLevelInfo thisLevel;
85  while (arrSize > 0) {
86    // read and insert the next level information
87    if (!thisLevel.Read (f)) return false;
88    levelInfo[thisLevel.levelTag] = thisLevel;
89   
90    --arrSize;
91  }
92
93  return true;
94}
95
96bool FIvfLevel::Write (FILE *f) const {
97  if (!WriteUCArray (f, docTag) ||
98      !WriteUCArray (f, indexLevel))
99    return false;
100 
101  // write out the array size
102  if (!WriteVarLenUL (f, levelInfo.size())) return false;
103
104  // write out each level info
105  IvfLevelInfoMap::const_iterator here = levelInfo.begin();
106  IvfLevelInfoMap::const_iterator end = levelInfo.end();
107  while (here != end) {
108    if (!(*here).second.Write (f)) return false;
109   
110    ++here;
111  }
112
113  return true;
114}
115
116// stream output for debugging purposes
117ostream &operator<<(ostream &s, const FIvfLevel &l) {
118  s << "docTag: \"" << l.docTag << "\"\n"
119    << "indexLevel: \"" << l.indexLevel << "\"\n";
120 
121  IvfLevelInfoMap::const_iterator here = l.levelInfo.begin ();
122  IvfLevelInfoMap::const_iterator end = l.levelInfo.end ();
123  while (here != end) {
124    s << (*here).second;
125    ++here;
126  }
127 
128  return s;
129}
Note: See TracBrowser for help on using the browser.