Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 <stack>
00024 #include <vector>
00025 #include <string>
00026 
00027 namespace indri {
00028   namespace lang {
00029     class RawExtentNode;
00030     class ScoredExtentNode;
00031 
00032     class Packer {
00033     private:
00034       struct node_element {
00035         // be warned--there is no defined copy constructor
00036         // here and no destructor; memory management must be
00037         // done by the user
00038         node_element() : languageNode(0), xmlNode(0), flushed(false) {}
00039         node_element( class Node* langNode ) :
00040           languageNode( langNode ),
00041           xmlNode( new XMLNode( "node" ) ),
00042           flushed(false)
00043         {
00044         }
00045 
00046         class Node* languageNode;
00047         XMLNode* xmlNode;
00048         bool flushed;
00049       };
00050 
00051       std::map<class Node*, node_element*> _elements;
00052       std::stack<node_element*> _stack;
00053       XMLNode* _packedNodes;
00054 
00055       node_element* _getElement( class Node* node );
00056       XMLNode* _getNodeReference( class Node* node, const std::string& name );
00057 
00058     public:
00059       Packer();
00060 
00061       void before( class Node* someNode );
00062       void after( class Node* someNode );
00063       void put( const char* name, bool value );
00064       void put( const char* name, int value );
00065       void put( const char* name, unsigned int value );
00066       void put( const char* name, UINT64 value );
00067       void put( const char* name, double value );
00068       void put( const char* name, const std::string& value );
00069       void put( const char* name, const std::vector<int>& value );
00070       void put( const char* name, const std::vector<double>& value );
00071       void put( const char* name, const std::vector<RawExtentNode*>& value );
00072       void put( const char* name, const std::vector<ScoredExtentNode*>& value );
00073       void put( const char* name, Node* value );
00074       void pack( class indri::lang::Node* root );
00075       void pack( std::vector<class indri::lang::Node*>& roots );
00076       std::string toString();
00077       XMLNode* xml();
00078     };
00079   }
00080 }
00081 
00082 #endif // INDRI_PACKER_HPP

Generated on Wed Nov 3 12:59:01 2004 for Lemur Toolkit by doxygen1.2.18