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

Appliers.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 // Appliers
00014 //
00015 // 16 September 2004 
00016 //
00017 
00018 #ifndef INDRI_APPLIERS_HPP
00019 #define INDRI_APPLIERS_HPP
00020 
00021 #include "indri/delete_range.hpp"
00022 namespace indri
00023 {
00025   namespace lang
00026   {
00027     
00028     template<class T, class NodeType = indri::lang::Node>
00029     class ApplySingleCopier {
00030     private:
00031       std::vector<indri::lang::Node*> _roots;
00032       T* _copier;
00033 
00034     public:
00035       ApplySingleCopier( std::vector<NodeType*>& previous, class indri::collection::Repository& repository ) {
00036         _copier = new T;
00037 
00038         for( size_t i=0; i<previous.size(); i++ ) {
00039           indri::lang::Node* root = previous[i];
00040           indri::lang::Node* newRoot = root->copy( *_copier );
00041 
00042           _roots.push_back(newRoot);
00043         }
00044       }
00045 
00046       ~ApplySingleCopier() {
00047         delete _copier;
00048       }
00049 
00050       std::vector<indri::lang::Node*>& roots() {
00051         return _roots;
00052       }
00053     };
00054 
00055     template<class T, class NodeType = indri::lang::Node>
00056     class ApplyCopiers {
00057     private:
00058       std::vector<indri::lang::Node*> _roots;
00059       std::vector<T*> _copiers;
00060 
00061     public:
00062       ApplyCopiers( std::vector<NodeType*>& previous ) {
00063         for( size_t i=0; i<previous.size(); i++ ) {
00064           indri::lang::Node* root = previous[i];
00065           T* copier = new T;
00066           indri::lang::Node* newRoot = root->copy( *copier );
00067 
00068           _roots.push_back(newRoot);
00069           _copiers.push_back(copier);
00070         }
00071       }
00072 
00073       ApplyCopiers( std::vector<NodeType*>& previous, class indri::collection::Repository& repository ) {
00074         for( size_t i=0; i<previous.size(); i++ ) {
00075           indri::lang::Node* root = previous[i];
00076           T* copier = new T( repository );
00077           indri::lang::Node* newRoot = root->copy( *copier );
00078 
00079           _roots.push_back(newRoot);
00080           _copiers.push_back(copier);
00081         }
00082       }
00083 
00084       ApplyCopiers( std::vector<NodeType*>& previous, class ListCache& listCache ) {
00085         for( size_t i=0; i<previous.size(); i++ ) {
00086           indri::lang::Node* root = previous[i];
00087           T* copier = new T( &listCache );
00088           indri::lang::Node* newRoot = root->copy( *copier );
00089 
00090           _roots.push_back(newRoot);
00091           _copiers.push_back(copier);
00092         }
00093       }
00094 
00095       ApplyCopiers( std::vector<NodeType*>& previous, class indri::collection::Repository& repository, class ListCache& listCache ) {
00096         for( size_t i=0; i<previous.size(); i++ ) {
00097           indri::lang::Node* root = previous[i];
00098           T* copier = new T( repository, listCache );
00099           indri::lang::Node* newRoot = root->copy( *copier );
00100 
00101           _roots.push_back(newRoot);
00102           _copiers.push_back(copier);
00103         }
00104       }
00105 
00106       ~ApplyCopiers() {
00107         indri::utility::delete_vector_contents( _copiers );
00108       }
00109 
00110       std::vector<indri::lang::Node*>& roots() {
00111         return _roots;
00112       }
00113     };
00114 
00115     template<class T, class NodeType=indri::lang::Node>
00116     class ApplyWalker {
00117     private:
00118       T* _walker;
00119 
00120     public:
00121       ApplyWalker( std::vector<NodeType*>& roots, T* walker ) {
00122         _walker = walker;
00123         for( size_t i=0; i<roots.size(); i++ )
00124           roots[i]->walk(*_walker);
00125       }
00126 
00127       T& get() {
00128         return _walker;
00129       }
00130     };
00131   }
00132 }
00133 
00134 #endif // INDRI_APPLIERS_HPP
00135 

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