00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00036
00037
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