Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Packer.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010  */
00011 
00012 
00013 //
00014 // Packer
00015 //
00016 // 17 March 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_PACKER_HPP
00020 #define INDRI_PACKER_HPP
00021 
00022 #include "indri/XMLNode.hpp"
00023 #include "IndexTypes.hpp"
00024 #include <stack>
00025 #include <vector>
00026 #include <string>
00027 
00028 namespace indri {
00029   namespace lang {
00030     class RawExtentNode;
00031     class ScoredExtentNode;
00032 
00033     class Packer {
00034     private:
00035       struct node_element {
00036         // be warned--there is no defined copy constructor
00037         // here and no destructor; memory management must be
00038         // done by the user
00039         node_element() : languageNode(0), xmlNode(0), flushed(false) {}
00040         node_element( class Node* langNode ) :
00041           languageNode( langNode ),
00042           xmlNode( new indri::xml::XMLNode( "node" ) ),
00043           flushed(false)
00044         {
00045         }
00046 
00047         class Node* languageNode;
00048         indri::xml::XMLNode* xmlNode;
00049         bool flushed;
00050       };
00051 
00052       std::map<class Node*, node_element*> _elements;
00053       std::stack<node_element*> _stack;
00054       indri::xml::XMLNode* _packedNodes;
00055 
00056       node_element* _getElement( class Node* node );
00057       indri::xml::XMLNode* _getNodeReference( class Node* node, const std::string& name );
00058 
00059     public:
00060       Packer();
00061       ~Packer();
00062 
00063       void before( class Node* someNode );
00064       void after( class Node* someNode );
00065       void put( const char* name, bool value );
00066       void put( const char* name, int value );
00067       void put( const char* name, unsigned int value );
00068       void put( const char* name, UINT64 value );
00069       void put( const char* name, INT64 value );
00070       void put( const char* name, double value );
00071       void put( const char* name, const std::string& value );
00072       void put( const char* name, const std::vector<lemur::api::DOCID_T>& value );
00073       void put( const char* name, const std::vector<double>& value );
00074       void put( const char* name, const std::vector<std::string>& value );
00075       void put( const char* name, const std::vector<RawExtentNode*>& value );
00076       void put( const char* name, const std::vector<ScoredExtentNode*>& value );
00077       void put( const char* name, Node* value );
00078       void pack( class indri::lang::Node* root );
00079       void pack( std::vector<class indri::lang::Node*>& roots );
00080       std::string toString();
00081       indri::xml::XMLNode* xml();
00082     };
00083   }
00084 }
00085 
00086 #endif // INDRI_PACKER_HPP

Generated on Tue Jun 15 11:02:54 2010 for Lemur by doxygen 1.3.4