source: cpp/gdk/genoconv.h @ 100

Last change on this file since 100 was 66, checked in by Maciej Komosinski, 14 years ago

set 'eol-style' to 'native'

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
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
17class GenoConvManager;
18
19class GenoConvParam: public Param
20{
21GenoConvManager *gcm;
22std::vector<std::string> gcnames;
23void freetab();
24public:
25GenoConvParam(GenoConvManager *g);
26~GenoConvParam();
27void *getTarget(int);
28const char* id(int i);
29void updatetab();
30};
31
32class 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.
40class GenoConverter
41{
42public:
43const char *name;       //< converter name (short)
44char in_format,         //< input format, eg. '1'
45        out_format;     //< output format, eg. '0'
46const char *info;       //< detailed info about converter, format or copyright
47long enabled;   //< don't touch this! (used by configuration module)
48long 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
55virtual SString convert(SString &i,MultiMap *map) {return SString();}
56
57virtual ~GenoConverter() {}
58/// Don't forget to set public fields in your constructor
59GenoConverter():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.
70class GenoConvManager
71{
72friend class GenoConvParam;
73SList converters;
74static GenoConvManager *globalobject;
75public:
76GenoConvManager();
77~GenoConvManager();
78class GenoConvParam param;
79/// select an object for use as global GenoConvManager
80void useManager(GenoConvManager *m) {globalobject=m;}
81/// get global converter
82static GenoConvManager *getGlobalObject() {return globalobject;}
83/// make a genotype in other format. genotype will be invalid
84/// if GenoConvManager cannot convert it.
85Geno convert(Geno &in,char format,MultiMap *map=0);
86/// static conversion function (uses global GenoConvManager)
87static Geno globalConvert(Geno &in,char format,MultiMap *map=0);
88/// register GenoConverter
89void addConverter(GenoConverter *conv);
90/// unregister GenoConverter
91void removeConverter(GenoConverter *conv);
92
93char *getPath(char in,char out,char *path,int maxlen,int *mapavailable=0);
94char *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
98GenoConverter *findConverters(SListTempl<GenoConverter*>* result=0,char in=-1,char out=-1,int enabled=-1,char* name=0);
99};
100
101#endif
102
103
Note: See TracBrowser for help on using the repository browser.