[5] | 1 | // This file is a part of Framsticks GDK library. |
---|
| 2 | // Copyright (C) 2002-2006 Szymon Ulatowski. See LICENSE.txt for details. |
---|
| 3 | // Refer to http://www.frams.alife.pl/ for further information. |
---|
| 4 | |
---|
| 5 | #ifndef _GENCONV_H_ |
---|
| 6 | #define _GENCONV_H_ |
---|
| 7 | |
---|
| 8 | #include "geno.h" |
---|
| 9 | #include "param.h" |
---|
| 10 | #include "list.h" |
---|
| 11 | #include "sstring.h" |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | class GenoConvManager; |
---|
| 15 | |
---|
| 16 | class GenoConvParam: public Param |
---|
| 17 | { |
---|
| 18 | GenoConvManager *gcm; |
---|
| 19 | void freetab(); |
---|
| 20 | public: |
---|
| 21 | GenoConvParam(GenoConvManager *g); |
---|
| 22 | ~GenoConvParam(); |
---|
| 23 | void *getTarget(int); |
---|
| 24 | const char* id(int i); |
---|
| 25 | void updatetab(); |
---|
| 26 | }; |
---|
| 27 | |
---|
| 28 | class MultiMap; |
---|
| 29 | |
---|
| 30 | /// Base class for all Geno Converters. |
---|
| 31 | /// In constructor you have to set public fields |
---|
| 32 | /// indicating your identity and supported formats. |
---|
| 33 | /// Each converter serves one in-out format pair. |
---|
| 34 | /// Instance of your converter should be registered |
---|
| 35 | /// in GenoConvManager. |
---|
| 36 | class GenoConverter |
---|
| 37 | { |
---|
| 38 | public: |
---|
| 39 | const char *name; //< converter name (short) |
---|
| 40 | char in_format, //< input format, eg. '1' |
---|
| 41 | out_format; //< output format, eg. '0' |
---|
| 42 | const char *info; //< detailed info about converter, format or copyright |
---|
| 43 | long enabled; //< don't touch this! (used by configuration module) |
---|
| 44 | long mapsupport; //< set to 1 if your converter supports genotype mapping |
---|
| 45 | |
---|
| 46 | /// You have to reimplement this method. |
---|
| 47 | /// If your converter cannot do its job, return empty string |
---|
| 48 | /// (return SString();), any other return value is assumed |
---|
| 49 | /// to be output genotype. |
---|
| 50 | /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object |
---|
| 51 | virtual SString convert(SString &i,MultiMap *map) {return SString();} |
---|
| 52 | |
---|
| 53 | virtual ~GenoConverter() {} |
---|
| 54 | /// Don't forget to set public fields in your constructor |
---|
| 55 | GenoConverter():name(""),in_format(-1),out_format('0'),info(""),enabled(1),mapsupport(0) {} |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | /// This class gathers abilities of all converters and can |
---|
| 59 | /// convert a genotype to any other one, provided there is |
---|
| 60 | /// a path of GenoConverters between them. |
---|
| 61 | /// In most cases you don't use this class directly, |
---|
| 62 | /// Geno::getConverted(int) provides full converting functionality. |
---|
| 63 | /// Explicit GenoConvManager object is only needed for registering |
---|
| 64 | /// your GenoConverter. |
---|
| 65 | /// Use DefaultGenoConvManager to register the standard genotype converters automatically. |
---|
| 66 | class GenoConvManager |
---|
| 67 | { |
---|
| 68 | friend class GenoConvParam; |
---|
| 69 | SList converters; |
---|
| 70 | static GenoConvManager *globalobject; |
---|
| 71 | public: |
---|
| 72 | GenoConvManager(); |
---|
| 73 | ~GenoConvManager(); |
---|
| 74 | class GenoConvParam param; |
---|
| 75 | /// select an object for use as global GenoConvManager |
---|
| 76 | void useManager(GenoConvManager *m) {globalobject=m;} |
---|
| 77 | /// get global converter |
---|
| 78 | static GenoConvManager *getGlobalObject() {return globalobject;} |
---|
| 79 | /// make a genotype in other format. genotype will be invalid |
---|
| 80 | /// if GenoConvManager cannot convert it. |
---|
| 81 | Geno convert(Geno &in,char format,MultiMap *map=0); |
---|
| 82 | /// static conversion function (uses global GenoConvManager) |
---|
| 83 | static Geno globalConvert(Geno &in,char format,MultiMap *map=0); |
---|
| 84 | /// register GenoConverter |
---|
| 85 | void addConverter(GenoConverter *conv); |
---|
| 86 | /// unregister GenoConverter |
---|
| 87 | void removeConverter(GenoConverter *conv); |
---|
| 88 | |
---|
| 89 | char *getPath(char in,char out,char *path,int maxlen,int *mapavailable=0); |
---|
| 90 | char *getFormatPath(char in,char out,char *path,int maxlen,int *mapavailable=0); |
---|
| 91 | }; |
---|
| 92 | |
---|
| 93 | #endif |
---|
| 94 | |
---|
| 95 | |
---|