00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INDRI_APPLIERS_HPP
00009 #define INDRI_APPLIERS_HPP
00010
00011 #include "indri/delete_range.hpp"
00012
00013 template<class T, class NodeType = indri::lang::Node>
00014 class ApplySingleCopier {
00015 private:
00016 std::vector<indri::lang::Node*> _roots;
00017 T* _copier;
00018
00019 public:
00020 ApplySingleCopier( std::vector<NodeType*>& previous, class Repository& repository ) {
00021 _copier = new T;
00022
00023 for( size_t i=0; i<previous.size(); i++ ) {
00024 indri::lang::Node* root = previous[i];
00025 indri::lang::Node* newRoot = root->copy( *_copier );
00026
00027 _roots.push_back(newRoot);
00028 }
00029 }
00030
00031 ~ApplySingleCopier() {
00032 delete _copier;
00033 }
00034
00035 std::vector<indri::lang::Node*>& roots() {
00036 return _roots;
00037 }
00038 };
00039
00040 template<class T, class NodeType = indri::lang::Node>
00041 class ApplyCopiers {
00042 private:
00043 std::vector<indri::lang::Node*> _roots;
00044 std::vector<T*> _copiers;
00045
00046 public:
00047 ApplyCopiers( std::vector<NodeType*>& previous ) {
00048 for( size_t i=0; i<previous.size(); i++ ) {
00049 indri::lang::Node* root = previous[i];
00050 T* copier = new T;
00051 indri::lang::Node* newRoot = root->copy( *copier );
00052
00053 _roots.push_back(newRoot);
00054 _copiers.push_back(copier);
00055 }
00056 }
00057
00058 ApplyCopiers( std::vector<NodeType*>& previous, class Repository& repository ) {
00059 for( size_t i=0; i<previous.size(); i++ ) {
00060 indri::lang::Node* root = previous[i];
00061 T* copier = new T( repository );
00062 indri::lang::Node* newRoot = root->copy( *copier );
00063
00064 _roots.push_back(newRoot);
00065 _copiers.push_back(copier);
00066 }
00067 }
00068
00069 ApplyCopiers( std::vector<NodeType*>& previous, class ListCache& listCache ) {
00070 for( size_t i=0; i<previous.size(); i++ ) {
00071 indri::lang::Node* root = previous[i];
00072 T* copier = new T( &listCache );
00073 indri::lang::Node* newRoot = root->copy( *copier );
00074
00075 _roots.push_back(newRoot);
00076 _copiers.push_back(copier);
00077 }
00078 }
00079
00080 ApplyCopiers( std::vector<NodeType*>& previous, class Repository& repository, class ListCache& listCache ) {
00081 for( size_t i=0; i<previous.size(); i++ ) {
00082 indri::lang::Node* root = previous[i];
00083 T* copier = new T( repository, listCache );
00084 indri::lang::Node* newRoot = root->copy( *copier );
00085
00086 _roots.push_back(newRoot);
00087 _copiers.push_back(copier);
00088 }
00089 }
00090
00091 ~ApplyCopiers() {
00092 delete_vector_contents( _copiers );
00093 }
00094
00095 std::vector<indri::lang::Node*>& roots() {
00096 return _roots;
00097 }
00098 };
00099
00100 template<class T, class NodeType=indri::lang::Node>
00101 class ApplyWalker {
00102 private:
00103 T* _walker;
00104
00105 public:
00106 ApplyWalker( std::vector<NodeType*>& roots, T* walker ) {
00107 _walker = walker;
00108 for( int i=0; i<roots.size(); i++ )
00109 roots[i]->walk(*_walker);
00110 }
00111
00112 T& get() {
00113 return _walker;
00114 }
00115 };
00116
00117 #endif // INDRI_APPLIERS_HPP
00118