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