WordReference.h

Go to the documentation of this file.
00001 //
00002 // WordReference.h
00003 //
00004 // NAME
00005 // inverted index occurrence.
00006 //
00007 // SYNOPSIS
00008 // 
00009 // #include <WordReference.h>
00010 //
00011 // WordContext* context;
00012 // WordReference* word = context->Word("word");
00013 // WordReference* word = context->Word();
00014 // WordReference* word = context->Word(WordKey("key 1 2"), WordRecord());
00015 //
00016 // WordKey& key = word->Key();
00017 // WordKey& record = word->Record();
00018 // 
00019 // word->Clear();
00020 //
00021 // delete word;
00022 //
00023 // DESCRIPTION
00024 //
00025 // A <i>WordReference</i> object is an agregate of a <i>WordKey</i> object
00026 // and a <i>WordRecord</i> object.
00027 //
00028 // Although constructors may be used, the prefered way to create a 
00029 // WordReference object is by using the <b>WordContext::Word</b> method.
00030 // 
00031 // ASCII FORMAT
00032 //
00033 // The ASCII description is a string with fields separated by tabs or
00034 // white space. It is made of the ASCII description of a
00035 // <i>WordKey</i> object immediately followed by the ASCII
00036 // description of a <i>WordRecord</i> object.  See the corresponding
00037 // manual pages for more information.
00038 //
00039 // END
00040 //
00041 // Part of the ht://Dig package   <http://www.htdig.org/>
00042 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00043 // For copyright details, see the file COPYING in your distribution
00044 // or the GNU General Public License version 2 or later
00045 // <http://www.gnu.org/copyleft/gpl.html>
00046 //
00047 // $Id: WordReference_8h-source.html,v 1.1 2008/06/08 10:13:22 sebdiaz Exp $
00048 //
00049 #ifndef _WordReference_h_
00050 #define _WordReference_h_
00051 
00052 #ifndef SWIG
00053 #include "htString.h"
00054 #include "WordContext.h"
00055 #include "WordRecord.h"
00056 #include "WordKey.h"
00057 #endif /* SWIG */
00058 
00059 //
00060 // Describe the WordKey/WordRecord pair
00061 //
00062 class WordReference : public Object
00063 {
00064  public:
00065   //
00066   // Construction/Destruction
00067   //-
00068   // Constructor. Build an object with empty key and empty record.
00069   // The <b>ncontext</b> argument must be a pointer to a valid
00070   // WordContext object.
00071   // 
00072   WordReference(WordContext* ncontext) :
00073     key(ncontext),
00074     record(ncontext)
00075     { context = ncontext; }
00076 #ifndef SWIG
00077   //-
00078   // Constructor. Build an object from disk representation of <b>key</b>
00079   // and <b>record</b>.
00080   // The <b>ncontext</b> argument must be a pointer to a valid
00081   // WordContext object.
00082   // 
00083   WordReference(WordContext* ncontext, const String& key0, const String& record0) :
00084     key(ncontext),
00085     record(ncontext)
00086     {
00087       context = ncontext;
00088       Unpack(key0, record0);
00089     }
00090   //-
00091   // Constructor. Build an object with key word set to <b>word</b>
00092   // and otherwise empty and empty record.
00093   // The <b>ncontext</b> argument must be a pointer to a valid
00094   // WordContext object.
00095   // 
00096   WordReference(WordContext* ncontext, const String& word) :
00097     key(ncontext),
00098     record(ncontext)
00099     {
00100       context = ncontext;
00101       Clear();
00102       SetWord(word);
00103     }
00104 #endif /* SWIG */
00105   ~WordReference()      {}
00106 
00107   //-
00108   // Reset to empty key and record
00109   //
00110   void                  Clear() { key.Clear(); record.Clear(); word.trunc(); word_prefix = 0; }
00111 
00112   //
00113   // Accessors
00114   //
00115   //-
00116   // Return a pointer to the WordContext object used to create
00117   // this instance.
00118   //
00119   inline WordContext* GetContext() { return context; }
00120 #ifndef SWIG
00121   //-
00122   // Return a pointer to the WordContext object used to create
00123   // this instance as a const.
00124   //
00125   inline const WordContext* GetContext() const { return context; }
00126 #endif /* SWIG */
00127   //-
00128   // Return the <b>word</b> data member.
00129   //
00130   inline String& GetWord() { return word; }
00131 #ifndef SWIG
00132   //-
00133   // Return the <b>word</b> data member as a const.
00134   //
00135   inline const String& GetWord() const { return word; }
00136 #endif /* SWIG */
00137   //-
00138   // Set the <b>word</b> data member from the <b>nword</b> argument.
00139   //
00140   inline void SetWord(const String& nword) { word = nword; }
00141 
00142   //-
00143   // Return the key object.
00144   //
00145   WordKey&              Key() { return key; }
00146 #ifndef SWIG
00147   //-
00148   // Return the key object as const.
00149   //
00150   const WordKey&        Key() const { return key; }
00151 #endif /* SWIG */
00152   //-
00153   // Return the record object.
00154   //
00155   WordRecord&           Record() { return record; }
00156 #ifndef SWIG
00157   //-
00158   // Return the record object as const.
00159   //
00160   const WordRecord&     Record() const { return record; }
00161 #endif /* SWIG */
00162 
00163   //
00164   // Conversion
00165   //
00166 #ifdef SWIG
00167 %name(SetKey)
00168 #endif /* SWIG */
00169    //-
00170    // Copy <b>arg</b> in the key part of the object.
00171    //
00172   void                  Key(const WordKey& arg) { key = arg; }
00173 #ifndef SWIG
00174   //-
00175   // Set key structure from disk storage format as found in 
00176   // <b>packed</b> string.
00177   // Return OK if successfull, NOTOK otherwise.
00178   //
00179   int                   KeyUnpack(const String& packed) { return key.Unpack(packed); }
00180   //
00181   //-
00182   // Convert key object into disk storage format as found in 
00183   // return the resulting string.
00184   //
00185   String                KeyPack() const { String tmp; key.Pack(tmp); return tmp; }
00186   //-
00187   // Convert key object into disk storage format as found in 
00188   // and place the result in <b>packed</b> string.
00189   // Return OK if successfull, NOTOK otherwise.
00190   //
00191   int                   KeyPack(String& packed) const { return key.Pack(packed); }
00192 #endif /* SWIG */
00193 
00194 #ifdef SWIG
00195 %name(SetRecord)
00196 #endif /* SWIG */
00197    //-
00198    // Copy <b>arg</b> in the record part of the object.
00199    //
00200   void                  Record(const WordRecord& arg) { record = arg; }
00201 #ifndef SWIG
00202   //-
00203   // Set record structure from disk storage format as found in 
00204   // <b>packed</b> string.
00205   // Return OK if successfull, NOTOK otherwise.
00206   //
00207   int                   RecordUnpack(const String& packed) { return record.Unpack(packed); }
00208   //-
00209   // Convert record object into disk storage format as found in 
00210   // return the resulting string.
00211   //
00212   String                RecordPack() const { String tmp; record.Pack(tmp); return tmp; }
00213   //-
00214   // Convert record object into disk storage format as found in 
00215   // and place the result in <b>packed</b> string.
00216   // Return OK if successfull, NOTOK otherwise.
00217   //
00218   int                   RecordPack(String& packed) const { return record.Pack(packed); }
00219 
00220   //-
00221   // Short hand for KeyPack(<b>ckey</b>) RecordPack(<b>crecord</b>).
00222   //
00223   inline int            Pack(String& ckey, String& crecord) const {
00224     if(key.Pack(ckey) == NOTOK) return NOTOK;
00225     if(record.Pack(crecord) == NOTOK) return NOTOK;
00226     return OK;
00227   }
00228   //-
00229   // Short hand for KeyUnpack(<b>ckey</b>) RecordUnpack(<b>crecord</b>).
00230   //
00231   int                   Unpack(const String& ckey, const String& crecord) {
00232     if(key.Unpack(ckey) == NOTOK) return NOTOK;
00233     if(record.Unpack(crecord) == NOTOK) return NOTOK;
00234     return OK;
00235   }
00236 #endif /* SWIG */
00237 
00238   //
00239   // Transformations
00240   //
00241   //-
00242   // Merge key with other.Key() using the <i>WordKey::Merge</i> method:
00243   // key.Merge(other.Key()).
00244   // See the corresponding manual page for details. Copy other.record
00245   // into the record part of the object.
00246   //
00247   int                   Merge(const WordReference& other);
00248 #ifndef SWIG
00249   //-
00250   // Copy <b>master</b> before merging with <b>master.</b>Merge(<b>slave</b>)
00251   // and return the copy. Prevents alteration of <b>master</b>.
00252   //
00253   static WordReference  Merge(const WordReference& master, const WordReference& slave) {
00254     WordReference tmp(master);
00255     tmp.Merge(slave);
00256     return tmp;
00257   }
00258 #endif /* SWIG */
00259 
00260 #ifndef SWIG
00261   //
00262   // Set the whole structure from ASCII string description
00263   //
00264   //-
00265   // Set the whole structure from ASCII string in <b>bufferin</b>.
00266   // See <i>ASCII FORMAT</i> section.
00267   // Return OK if successfull, NOTOK otherwise.
00268   //
00269   int Set(const String& bufferin);
00270   int SetList(StringList& fields);
00271   //-
00272   // Convert the whole structure to an ASCII string description 
00273   // in <b>bufferout.</b>
00274   // See <i>ASCII FORMAT</i> section.
00275   // Return OK if successfull, NOTOK otherwise.
00276   //
00277   int Get(String& bufferout) const;
00278   //-
00279   // Convert the whole structure to an ASCII string description 
00280   // and return it.
00281   // See <i>ASCII FORMAT</i> section.
00282   // 
00283   String Get() const;
00284 #endif /* SWIG */
00285 
00286   //
00287   // Debuging
00288   //
00289 #ifndef SWIG
00290   //-
00291   // Print object in ASCII form on <b>f</b> (uses <i>Get</i> method).
00292   // See <i>ASCII FORMAT</i> section.
00293   //
00294   int Write(FILE* f) const;
00295 #endif /* SWIG */
00296   //-
00297   // Print object in ASCII form on <b>stdout</b> (uses <i>Get</i> method).
00298   // See <i>ASCII FORMAT</i> section.
00299   //
00300   void Print() const;
00301 
00302  protected:
00303 
00304 #ifndef SWIG
00305   WordKey               key;
00306   WordRecord            record;
00307   String                word;
00308   int                   word_prefix;
00309   WordContext*          context;
00310 #endif /* SWIG */
00311 };
00312 
00313 #endif /* _WordReference_h */
00314 

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