# eoOpSelMason.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // eoOpSelMason.h
    00005 // (c) GeNeura Team, 1999
    00006 /*
    00007     This library is free software; you can redistribute it and/or
    00008     modify it under the terms of the GNU Lesser General Public
    00009     License as published by the Free Software Foundation; either
    00010     version 2 of the License, or (at your option) any later version.
    00011
    00012     This library is distributed in the hope that it will be useful,
    00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015     Lesser General Public License for more details.
    00016
    00017     You should have received a copy of the GNU Lesser General Public
    00018     License along with this library; if not, write to the Free Software
    00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00020
    00021     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00022  */
    00023 //-----------------------------------------------------------------------------
    00024
    00025 #ifndef _EOOPSELMASON_H
    00026 #define _EOOPSELMASON_H
    00027
    00028 //-----------------------------------------------------------------------------
    00029 #include <eoProportionalOpSel.h>
    00030 #include <eoOpFactory.h>        // for eoFactory and eoOpFactory
    00031
    00032 #include <map>
    00033
    00034 //-----------------------------------------------------------------------------
    00035
    00038 template<class eoClass>
    00039 class eoOpSelMason: public eoFactory<eoOpSelector<eoClass> > {
    00040
    00041 public:
    00042         typedef std::vector<eoOp<eoClass>* > vOpP;
    00043         typedef map<eoOpSelector<eoClass>*, vOpP > MEV;
    00044
    00046         //{@
    00048         eoOpSelMason( eoOpFactory<eoClass>& _opFact): operatorFactory( _opFact ) {};
    00049
    00051         virtual ~eoOpSelMason() {};
    00053
    00065         virtual eoOpSelector<eoClass>* make(std::istream& _is) {
    00066
    00067                 std::string opSelName;
    00068                 _is >> opSelName;
    00069                 eoOpSelector<eoClass>* opSelectorP;
    00070                 // Build the operator selector
    00071                 if ( opSelName == "eoProportionalOpSel" ) {
    00072                         opSelectorP = new eoProportionalOpSel<eoClass>();
    00073                 }
    00074
    00075                 // Temp std::vector for storing pointers
    00076                 vOpP tmpPVec;
    00077                 // read operator rate and name
    00078                 while ( _is ) {
    00079                         float rate;
    00080                         _is >> rate;
    00081                         if ( _is ) {
    00082                                 eoOp<eoClass>* op = operatorFactory.make( _is );        // This reads the rest of the line
    00083                                 // Add the operators to the selector, donīt pay attention to the IDs
    00084                                 opSelectorP->addOp( *op, rate );
    00085                                 // Keep it in the store, to destroy later
    00086                                 tmpPVec.push_back( op );
    00087                         } // if
    00088                 } // while
    00089
    00090                 // Put it in the map
    00091                 allocMap.insert( MEV::value_type( opSelectorP, tmpPVec ) );
    00092
    00093                 return opSelectorP;
    00094         };
    00095
    00097
    00098
    00099         virtual std::string className() const { return "eoOpSelMason"; }
    00100
    00102
    00103 private:
    00104         map<eoOpSelector<eoClass>*,std::vector<eoOp<eoClass>* > > allocMap;
    00105         eoOpFactory<eoClass>& operatorFactory;
    00106 };
    00107
    00108
    00109 #endif