1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
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; //stores names of converters so that these names persist and pointers to these names can be safely used externally |
---|
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 | SString in_format, //< input format, eg. "1" |
---|
46 | out_format; //< output format, eg. "0" |
---|
47 | paInt enabled; //< don't touch this! (used by configuration module) |
---|
48 | paInt mapsupport; //< set to 1 if your converter supports genotype mapping |
---|
49 | |
---|
50 | /// You have to reimplement this method. |
---|
51 | /// If your converter cannot do its job, return empty string - return SString(); |
---|
52 | /// Any other return value is assumed to be output genotype. |
---|
53 | /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object |
---|
54 | virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0; |
---|
55 | |
---|
56 | virtual ~GenoConverter() {} |
---|
57 | /// Don't forget to set public fields in your constructor |
---|
58 | GenoConverter() :name(""), in_format(Geno::UNKNOWN_FORMAT), out_format("0"), enabled(1), mapsupport(0) {} |
---|
59 | }; |
---|
60 | |
---|
61 | /// This class gathers abilities of all converters and can |
---|
62 | /// convert a genotype to any other one, provided there is |
---|
63 | /// a path of GenoConverters between them. |
---|
64 | /// In most cases you don't use this class directly, |
---|
65 | /// Geno::getConverted(int) provides full converting functionality. |
---|
66 | /// Explicit GenoConvManager object is only needed for registering |
---|
67 | /// your GenoConverter. |
---|
68 | /// Use DefaultGenoConvManager to register the standard genotype converters automatically. |
---|
69 | class GenoConvManager |
---|
70 | { |
---|
71 | friend class GenoConvParam; |
---|
72 | SList converters; |
---|
73 | public: |
---|
74 | GenoConvManager(); |
---|
75 | ~GenoConvManager(); |
---|
76 | class GenoConvParam param; |
---|
77 | /// make a genotype in other format. genotype will be invalid |
---|
78 | /// if GenoConvManager cannot convert it. |
---|
79 | Geno convert(Geno &in, SString format, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL); |
---|
80 | /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable) |
---|
81 | void addConverter(GenoConverter *conv); |
---|
82 | /// unregister GenoConverter |
---|
83 | void removeConverter(GenoConverter *conv); |
---|
84 | |
---|
85 | GenoConverter **getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable = 0); |
---|
86 | /// returns the list of converters meeting the specified criteria |
---|
87 | /// pass result=0 if you only need one result (by return value) |
---|
88 | /// default criteria values mean "don't care", pass anything else to narrow your search |
---|
89 | GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, const SString& in = Geno::UNKNOWN_FORMAT, const SString& out = Geno::UNKNOWN_FORMAT, int enabled = -1, char* name = 0); |
---|
90 | }; |
---|
91 | |
---|
92 | #endif |
---|