WordReference.cc

Go to the documentation of this file.
00001 //
00002 // WordReference.cc
00003 //
00004 // Part of the ht://Dig package   <http://www.htdig.org/>
00005 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00006 // For copyright details, see the file COPYING in your distribution
00007 // or the GNU General Public License version 2 or later
00008 // <http://www.gnu.org/copyleft/gpl.html>
00009 //
00010 // $Id: WordReference_8cc-source.html,v 1.1 2008/06/08 10:13:22 sebdiaz Exp $
00011 //
00012 
00013 #ifdef HAVE_CONFIG_H
00014 #include "config.h"
00015 #endif /* HAVE_CONFIG_H */
00016 
00017 #include "WordReference.h"
00018 
00019 int WordReference::Merge(const WordReference& other)
00020 {
00021   int ret = key.Merge(other.Key());
00022   record = other.record;
00023 
00024   return ret;
00025 }
00026 
00027 //
00028 // Set the structure from an ascii representation
00029 //
00030 int
00031 WordReference::Set(const String& buffer)
00032 {
00033   StringList fields(buffer, "\t ");
00034   return SetList(fields);
00035 }
00036 
00037 //
00038 // Set the structure from list of fields
00039 //
00040 int
00041 WordReference::SetList(StringList& fields)
00042 {
00043   Clear();
00044   if(key.SetList(fields) != OK ||
00045      record.SetList(fields) != OK)
00046     return NOTOK;
00047   else
00048     return OK;
00049 }      
00050 
00051 //
00052 // Convert the whole structure to an ascii string description
00053 //
00054 int
00055 WordReference::Get(String& buffer) const
00056 {
00057   String tmp;
00058   buffer.trunc();
00059 
00060   if(key.Get(tmp) != OK) return NOTOK;
00061   //
00062   // If a readable word is available, print it instead of the numerical
00063   // serial number.
00064   //
00065   if(word.empty()) {
00066     buffer.append(tmp);
00067   } else {
00068     buffer.append(word);
00069     buffer.append(tmp.sub(tmp.indexOf('\t')));
00070   }
00071 
00072   if(record.Get(tmp) != OK) return NOTOK;
00073   buffer.append(tmp);
00074 
00075   return OK;
00076 }
00077 
00078 String
00079 WordReference::Get() const
00080 {
00081   String tmp;
00082   Get(tmp);
00083   return tmp;
00084 }
00085 
00086 int WordReference::Write(FILE* f) const
00087 {
00088   String tmp;
00089   Get(tmp);
00090   fprintf(f, "%s", (char*)tmp);
00091   return 0;
00092 }
00093 
00094 void WordReference::Print() const
00095 {
00096   Write(stderr);
00097 }

Generated on Sun Jun 8 10:56:40 2008 for GNUmifluz by  doxygen 1.5.5