// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- //----------------------------------------------------------------------------- // eoOpSelMason.h // (c) GeNeura Team, 1999 //----------------------------------------------------------------------------- #ifndef _EOOPSELMASON_H #define _EOOPSELMASON_H //----------------------------------------------------------------------------- #include #include // for eoFactory and eoOpFactory #include //----------------------------------------------------------------------------- /** EO Mason, or builder, for operator selectors. A builder must allocate memory to the objects it builds, and then deallocate it when it gets out of scope*/ template class eoOpSelMason: public eoFactory > { public: typedef vector* > vOpP; typedef map*, vOpP > MEV; /// @name ctors and dtors //{@ /// constructor eoOpSelMason( eoOpFactory& _opFact): operatorFactory( _opFact ) {}; /// destructor virtual ~eoOpSelMason() {}; //@} /** Factory methods: creates an object from an istream, reading from it whatever is needed to create the object. The format is opSelClassName\\ rate 1 operator1\\ rate 2 operator2\\ ...\\ Stores all operators built in a database (#allocMap#), so that somebody can destroy them later. The Mason is in charge or destroying the operators, since the built object canīt do it itself. The objects built must be destroyed from outside, using the #destroy# method */ virtual eoOpSelector* make(istream& _is) { string opSelName; _is >> opSelName; eoOpSelector* opSelectorP; // Build the operator selector if ( opSelName == "eoProportionalOpSel" ) { opSelectorP = new eoProportionalOpSel(); } // Temp vector for storing pointers vOpP tmpPVec; // read operator rate and name while ( _is ) { float rate; _is >> rate; if ( _is ) { eoOp* op = operatorFactory.make( _is ); // This reads the rest of the line // Add the operators to the selector, donīt pay attention to the IDs opSelectorP->addOp( *op, rate ); // Keep it in the store, to destroy later tmpPVec.push_back( op ); } // if } // while // Put it in the map allocMap.insert( MEV::value_type( opSelectorP, tmpPVec ) ); return opSelectorP; }; ///@name eoObject methods //@{ /** Return the class id */ virtual string className() const { return "eoOpSelMason"; } //@} private: map*,vector* > > allocMap; eoOpFactory& operatorFactory; }; #endif _EOOPSELMASON_H