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