#pragma once #include #include #include #include #include #include #include "geomorph.h" #include "gwconfig.h" namespace geoworld { class GeoMorph; class SynthesisSession; class IGeoFactoryBase { public: virtual void configure (IConfigFactoryBase * pFactoryConfig) = 0; }; class GeoMorphFactory : public IGeoFactoryBase { private: IConfigGMFactory::Settings _settings; public: inline float getFrequency () const { return _settings.frequency; } virtual void configure (IConfigGMFactory * pFactoryConfig, const IConfigGMFactory::Settings & settings) = 0; void configure (IConfigFactoryBase * pFactoryConfig); }; class GeoTemplateFactory : public IGeoFactoryBase { public: IConfigGTFactory::Settings _settings; public: inline bool inPhase (const GeoTemplatePhase & enPhase) const { return _settings.phase == enPhase; } inline GeoTemplatePhase getPhase() const { return _settings.phase; } virtual void configure (IConfigGTFactory * pFactoryConfig, const IConfigGTFactory::Settings & settings) = 0; void configure (IConfigFactoryBase * pFactoryConfig); }; class IOpenGeoMorphFactory { public: virtual GeoMorph * createRandomInstance() const = 0; }; class IUniformGeoMorphFactory : public IOpenGeoMorphFactory {}; class IBoundedGeoMorphFactory { public: virtual GeoMorph * createRandomInstance(const GWCoords & position) const = 0; }; class ISurfaceBoundedGeoMorphFactory { public: virtual GeoMorph * createRandomInstance(const long x, const long y) const = 0; }; class IPersistentGeoMorphFactory { public: virtual void save (const GeoMorph * pGM, mars::ObjectStream & outs) const = 0; virtual const GeoMorph * restore (mars::ObjectStream & ins) const = 0; }; class GeoMorphRegistry { public: typedef std::set< GeoMorphFactory * > GMFactorySet; typedef std::set< GeoTemplateFactory * > GTFactorySet; GeoMorphRegistry(); void configure (IFactoryConfigReader & reader); void registerFactory (const std::string & name, IGeoFactoryBase * pFactory); IGeoFactoryBase * unregisterFactory (const std::string & name); const IGeoFactoryBase * getFactory (const std::string & name) const; GMFactorySet::const_iterator beginGM() const { return _gmfact.begin(); } GMFactorySet::const_iterator endGM() const { return _gmfact.end(); } GTFactorySet::const_iterator beginGT(const GeoTemplatePhase & engtpPhase) const { return _gtfact[engtpPhase].begin(); } GTFactorySet::const_iterator endGT(const GeoTemplatePhase & engtpPhase) const { return _gtfact[engtpPhase].end(); } void go(SynthesisSession & sess); ~GeoMorphRegistry(); private: typedef std::map< std::string, IGeoFactoryBase * > FactoryMap; FactoryMap _factories, _factconf; GMFactorySet _gmfact; GTFactorySet _gtfact[CountGTP]; }; }