source: cpp/gdk/genoconv.h @ 5

Last change on this file since 5 was 5, checked in by sz, 15 years ago

added the GDK (Genotype Development Kit)

File size: 3.1 KB
Line 
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
14class GenoConvManager;
15
16class GenoConvParam: public Param
17{
18GenoConvManager *gcm;
19void freetab();
20public:
21GenoConvParam(GenoConvManager *g);
22~GenoConvParam();
23void *getTarget(int);
24const char* id(int i);
25void updatetab();
26};
27
28class 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.
36class GenoConverter
37{
38public:
39const char *name;       //< converter name (short)
40char in_format,         //< input format, eg. '1'
41        out_format;     //< output format, eg. '0'
42const char *info;       //< detailed info about converter, format or copyright
43long enabled;   //< don't touch this! (used by configuration module)
44long 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
51virtual SString convert(SString &i,MultiMap *map) {return SString();}
52
53virtual ~GenoConverter() {}
54/// Don't forget to set public fields in your constructor
55GenoConverter():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.
66class GenoConvManager
67{
68friend class GenoConvParam;
69SList converters;
70static GenoConvManager *globalobject;
71public:
72GenoConvManager();
73~GenoConvManager();
74class GenoConvParam param;
75/// select an object for use as global GenoConvManager
76void useManager(GenoConvManager *m) {globalobject=m;}
77/// get global converter
78static GenoConvManager *getGlobalObject() {return globalobject;}
79/// make a genotype in other format. genotype will be invalid
80/// if GenoConvManager cannot convert it.
81Geno convert(Geno &in,char format,MultiMap *map=0);
82/// static conversion function (uses global GenoConvManager)
83static Geno globalConvert(Geno &in,char format,MultiMap *map=0);
84/// register GenoConverter
85void addConverter(GenoConverter *conv);
86/// unregister GenoConverter
87void removeConverter(GenoConverter *conv);
88
89char *getPath(char in,char out,char *path,int maxlen,int *mapavailable=0);
90char *getFormatPath(char in,char out,char *path,int maxlen,int *mapavailable=0);
91};
92
93#endif
94
95
Note: See TracBrowser for help on using the repository browser.