/////////////////////////////////////////////////////////////////////////////// // // // This file is part of ModelBlocks. Copyright 2009, ModelBlocks developers. // // // // ModelBlocks is free software: you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation, either version 3 of the License, or // // (at your option) any later version. // // // // ModelBlocks is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with ModelBlocks. If not, see . // // // // ModelBlocks developers designate this particular file as subject to // // the "Moses" exception as provided by ModelBlocks developers in // // the LICENSE file that accompanies this code. // // // /////////////////////////////////////////////////////////////////////////////// template class Tree : public T { private: // Data members... SimpleHash*> apt; static const Tree tDummy; public: // Constructor / destructor methods... ~Tree ( ) { for(typename SimpleHash*>::iterator i=apt.begin(); i!=apt.end(); i++) delete i->second; } Tree ( ) { } // Tree ( const Tree& t ) { ptL = (t.ptL) ? new Tree(*t.ptL) : NULL; // ptR = (t.ptR) ? new Tree(*t.ptR) : NULL; } // Extraction methods... const bool isTerm ( ) const { return (apt.empty()); } const Tree& getBranch ( const B& b ) const { return (apt.find(b)!=apt.end()) ? *apt.find(b)->second : tDummy; } // Specification methods... Tree& setBranch ( const B& b ) { if (apt.find(b)==apt.end()) apt[b]=new Tree(); return *apt[b]; } }; template const Tree Tree::tDummy;// = Tree();