1 | #pragma once
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <map>
|
---|
5 | #include <list>
|
---|
6 | #include <exception>
|
---|
7 |
|
---|
8 | #include <mars_util.h>
|
---|
9 | #include <mars_streams.h>
|
---|
10 |
|
---|
11 | #include "geomorph.h"
|
---|
12 | #include "gwconfig.h"
|
---|
13 |
|
---|
14 | namespace geoworld
|
---|
15 | {
|
---|
16 | class GeoMorph;
|
---|
17 | class SynthesisSession;
|
---|
18 |
|
---|
19 | class IGeoFactoryBase {
|
---|
20 | public:
|
---|
21 | virtual void configure (IConfigFactoryBase * pFactoryConfig) = 0;
|
---|
22 | };
|
---|
23 |
|
---|
24 | class GeoMorphFactory : public IGeoFactoryBase
|
---|
25 | {
|
---|
26 | private:
|
---|
27 | IConfigGMFactory::Settings _settings;
|
---|
28 |
|
---|
29 | public:
|
---|
30 | inline float getFrequency () const { return _settings.frequency; }
|
---|
31 |
|
---|
32 | virtual void configure (IConfigGMFactory * pFactoryConfig, const IConfigGMFactory::Settings & settings) = 0;
|
---|
33 | void configure (IConfigFactoryBase * pFactoryConfig);
|
---|
34 | };
|
---|
35 |
|
---|
36 | class GeoTemplateFactory : public IGeoFactoryBase
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | IConfigGTFactory::Settings _settings;
|
---|
40 |
|
---|
41 | public:
|
---|
42 | inline bool inPhase (const GeoTemplatePhase & enPhase) const { return _settings.phase == enPhase; }
|
---|
43 | inline GeoTemplatePhase getPhase() const { return _settings.phase; }
|
---|
44 |
|
---|
45 | virtual void configure (IConfigGTFactory * pFactoryConfig, const IConfigGTFactory::Settings & settings) = 0;
|
---|
46 | void configure (IConfigFactoryBase * pFactoryConfig);
|
---|
47 | };
|
---|
48 |
|
---|
49 | class IOpenGeoMorphFactory
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | virtual GeoMorph * createRandomInstance() const = 0;
|
---|
53 | };
|
---|
54 |
|
---|
55 | class IUniformGeoMorphFactory : public IOpenGeoMorphFactory {};
|
---|
56 |
|
---|
57 | class IBoundedGeoMorphFactory
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | virtual GeoMorph * createRandomInstance(const GWCoords & position) const = 0;
|
---|
61 | };
|
---|
62 |
|
---|
63 | class ISurfaceBoundedGeoMorphFactory
|
---|
64 | {
|
---|
65 | public:
|
---|
66 | virtual GeoMorph * createRandomInstance(const long x, const long y) const = 0;
|
---|
67 | };
|
---|
68 |
|
---|
69 | class IPersistentGeoMorphFactory
|
---|
70 | {
|
---|
71 | public:
|
---|
72 | virtual void save (const GeoMorph * pGM, mars::ObjectStream & outs) const = 0;
|
---|
73 | virtual const GeoMorph * restore (mars::ObjectStream & ins) const = 0;
|
---|
74 | };
|
---|
75 |
|
---|
76 | class GeoMorphRegistry
|
---|
77 | {
|
---|
78 | public:
|
---|
79 | typedef std::set< GeoMorphFactory * > GMFactorySet;
|
---|
80 | typedef std::set< GeoTemplateFactory * > GTFactorySet;
|
---|
81 |
|
---|
82 | GeoMorphRegistry();
|
---|
83 |
|
---|
84 | void configure (IFactoryConfigReader & reader);
|
---|
85 | void registerFactory (const std::string & name, IGeoFactoryBase * pFactory);
|
---|
86 | IGeoFactoryBase * unregisterFactory (const std::string & name);
|
---|
87 | const IGeoFactoryBase * getFactory (const std::string & name) const;
|
---|
88 |
|
---|
89 | GMFactorySet::const_iterator beginGM() const { return _gmfact.begin(); }
|
---|
90 | GMFactorySet::const_iterator endGM() const { return _gmfact.end(); }
|
---|
91 |
|
---|
92 | GTFactorySet::const_iterator beginGT(const GeoTemplatePhase & engtpPhase) const { return _gtfact[engtpPhase].begin(); }
|
---|
93 | GTFactorySet::const_iterator endGT(const GeoTemplatePhase & engtpPhase) const { return _gtfact[engtpPhase].end(); }
|
---|
94 |
|
---|
95 | void go(SynthesisSession & sess);
|
---|
96 |
|
---|
97 | ~GeoMorphRegistry();
|
---|
98 |
|
---|
99 | private:
|
---|
100 | typedef std::map< std::string, IGeoFactoryBase * > FactoryMap;
|
---|
101 |
|
---|
102 | FactoryMap _factories, _factconf;
|
---|
103 | GMFactorySet _gmfact;
|
---|
104 | GTFactorySet _gtfact[CountGTP];
|
---|
105 | };
|
---|
106 | } |
---|