EvolvingObjects
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 #ifndef _EOOPSELMASON_H
00025 #define _EOOPSELMASON_H
00026 
00027 #include <eoOpFactory.h>        // for eoFactory and eoOpFactory
00028 
00029 #include <map>
00030 
00031 
00037 template<class eoClass>
00038 class eoOpSelMason: public eoFactory<eoOpSelector<eoClass> > {
00039 
00040 public:
00041         typedef std::vector<eoOp<eoClass>* > vOpP;
00042         typedef map<eoOpSelector<eoClass>*, vOpP > MEV;
00043 
00045         //{@
00047         eoOpSelMason( eoOpFactory<eoClass>& _opFact): operatorFactory( _opFact ) {};
00048 
00050         virtual ~eoOpSelMason() {};
00052 
00064         virtual eoOpSelector<eoClass>* make(std::istream& _is) {
00065 
00066                 std::string opSelName;
00067                 _is >> opSelName;
00068                 eoOpSelector<eoClass>* opSelectorP;
00069                 // Build the operator selector
00070                 if ( opSelName == "eoProportionalOpSel" ) {
00071                         opSelectorP = new eoProportionalOpSel<eoClass>();
00072                 }
00073 
00074                 // Temp std::vector for storing pointers
00075                 vOpP tmpPVec;
00076                 // read operator rate and name
00077                 while ( _is ) {
00078                         float rate;
00079                         _is >> rate;
00080                         if ( _is ) {
00081                                 eoOp<eoClass>* op = operatorFactory.make( _is );        // This reads the rest of the line
00082                                 // Add the operators to the selector, donīt pay attention to the IDs
00083                                 opSelectorP->addOp( *op, rate );
00084                                 // Keep it in the store, to destroy later
00085                                 tmpPVec.push_back( op );
00086                         } // if
00087                 } // while
00088 
00089                 // Put it in the map
00090                 allocMap.insert( MEV::value_type( opSelectorP, tmpPVec ) );
00091 
00092                 return opSelectorP;
00093         };
00094 
00096 
00097 
00098         virtual std::string className() const { return "eoOpSelMason"; }
00099 
00101 
00102 private:
00103         map<eoOpSelector<eoClass>*,std::vector<eoOp<eoClass>* > > allocMap;
00104         eoOpFactory<eoClass>& operatorFactory;
00105 };
00106 
00107 
00108 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends