// // WordReference.h // // NAME // inverted index occurrence. // // SYNOPSIS // // #include // // WordReference wordRef("word"); // WordReference wordRef(); // WordReference wordRef(WordKey("key 1 2"), WordRecord()); // // WordKey& key = wordRef.Key(); // WordKey& record = wordRef.Record(); // // wordRef.Clear(); // // DESCRIPTION // // A WordReference object is an agregate of a WordKey object // and a WordRecord object. // // ASCII FORMAT // // The ASCII description is a string with fields separated by tabs or // white space. It is made of the ASCII description of a // WordKey object immediately followed by the ASCII // description of a WordRecord object. See the corresponding // manual pages for more information. // // END // // Part of the ht://Dig package // Copyright (c) 1999-2004 The ht://Dig Group // For copyright details, see the file COPYING in your distribution // or the GNU Library General Public License (LGPL) version 2 or later // // // $Id: WordReference.h,v 1.7 2004/05/28 13:15:28 lha Exp $ // #ifndef _WordReference_h_ #define _WordReference_h_ #ifndef SWIG #include "htString.h" #include "WordRecord.h" #include "WordKey.h" #endif /* SWIG */ // // Describe the WordKey/WordRecord pair // class WordReference : public Object { public: // // Construction/Destruction //- // Constructor. Build an object with empty key and empty record. // WordReference() {} #ifndef SWIG //- // Constructor. Build an object from disk representation of key // and record. // WordReference(const String& key0, const String& record0) { Unpack(key0, record0); } //- // Constructor. Build an object with key word set to word // and otherwise empty and empty record. // WordReference(const String& word) { Clear(); key.SetWord(word); } #endif /* SWIG */ ~WordReference() {} //- // Reset to empty key and record // void Clear() { key.Clear(); record.Clear(); } // // Accessors //- // Return the key object. // WordKey& Key() { return key; } #ifndef SWIG //- // Return the key object as const. // const WordKey& Key() const { return key; } #endif /* SWIG */ //- // Return the record object. // WordRecord& Record() { return record; } #ifndef SWIG //- // Return the record object as const. // const WordRecord& Record() const { return record; } #endif /* SWIG */ // // Conversion // #ifdef SWIG %name(SetKey) #endif /* SWIG */ //- // Copy arg in the key part of the object. // void Key(const WordKey& arg) { key = arg; } #ifndef SWIG //- // Set key structure from disk storage format as found in // packed string. // Return OK if successfull, NOTOK otherwise. // int KeyUnpack(const String& packed) { return key.Unpack(packed); } // //- // Convert key object into disk storage format as found in // return the resulting string. // String KeyPack() const { String tmp; key.Pack(tmp); return tmp; } //- // Convert key object into disk storage format as found in // and place the result in packed string. // Return OK if successfull, NOTOK otherwise. // int KeyPack(String& packed) const { return key.Pack(packed); } #endif /* SWIG */ #ifdef SWIG %name(SetRecord) #endif /* SWIG */ //- // Copy arg in the record part of the object. // void Record(const WordRecord& arg) { record = arg; } #ifndef SWIG //- // Set record structure from disk storage format as found in // packed string. // Return OK if successfull, NOTOK otherwise. // int RecordUnpack(const String& packed) { return record.Unpack(packed); } //- // Convert record object into disk storage format as found in // return the resulting string. // String RecordPack() const { String tmp; record.Pack(tmp); return tmp; } //- // Convert record object into disk storage format as found in // and place the result in packed string. // Return OK if successfull, NOTOK otherwise. // int RecordPack(String& packed) const { return record.Pack(packed); } //- // Short hand for KeyPack(ckey) RecordPack(crecord). // inline int Pack(String& ckey, String& crecord) const { if(key.Pack(ckey) == NOTOK) return NOTOK; if(record.Pack(crecord) == NOTOK) return NOTOK; return OK; } //- // Short hand for KeyUnpack(ckey) RecordUnpack(crecord). // int Unpack(const String& ckey, const String& crecord) { if(key.Unpack(ckey) == NOTOK) return NOTOK; if(record.Unpack(crecord) == NOTOK) return NOTOK; return OK; } #endif /* SWIG */ // // Transformations // //- // Merge key with other.Key() using the WordKey::Merge method: // key.Merge(other.Key()). // See the corresponding manual page for details. Copy other.record // into the record part of the object. // int Merge(const WordReference& other); #ifndef SWIG //- // Copy master before merging with master.Merge(slave) // and return the copy. Prevents alteration of master. // static WordReference Merge(const WordReference& master, const WordReference& slave) { WordReference tmp(master); tmp.Merge(slave); return tmp; } #endif /* SWIG */ #ifndef SWIG int compare(Object *to) { String word(((WordReference *) to)->key.GetWord()); return key.GetWord().nocase_compare(word); } #endif /* SWIG */ #ifndef SWIG // // Set the whole structure from ASCII string description // //- // Set the whole structure from ASCII string in bufferin. // See ASCII FORMAT section. // Return OK if successfull, NOTOK otherwise. // int Set(const String& bufferin); int SetList(StringList& fields); //- // Convert the whole structure to an ASCII string description // in bufferout. // See ASCII FORMAT section. // Return OK if successfull, NOTOK otherwise. // int Get(String& bufferout) const; //- // Convert the whole structure to an ASCII string description // and return it. // See ASCII FORMAT section. // String Get() const; #endif /* SWIG */ // // Debuging // #ifndef SWIG //- // Print object in ASCII form on f (uses Get method). // See ASCII FORMAT section. // int Write(FILE* f) const; #endif /* SWIG */ //- // Print object in ASCII form on stdout (uses Get method). // See ASCII FORMAT section. // void Print() const; protected: #ifndef SWIG WordKey key; WordRecord record; #endif /* SWIG */ }; #endif /* _WordReference_h */