source: cpp/frams/genetics/genoconv.h @ 753

Last change on this file since 753 was 735, checked in by Maciej Komosinski, 7 years ago

Base genotype converter is now abstract, which triggers compilation errors in obsolete genetic converters (the ones which do not have the use_checkpoints argument)

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[732]2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[109]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
17class GenoConvManager;
18
[150]19class GenoConvParam : public Param
[109]20{
[150]21        GenoConvManager *gcm;
22        std::vector<std::string> gcnames;
23        char tmp_id[20];
24        void freetab();
[109]25public:
[150]26        GenoConvParam(GenoConvManager *g);
27        ~GenoConvParam();
28        void *getTarget(int);
29        const char* id(int i);
30        void updatetab();
[109]31};
32
33class 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.
41class GenoConverter
42{
43public:
[150]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
[247]48        paInt enabled;  //< don't touch this! (used by configuration module)
49        paInt mapsupport; //< set to 1 if your converter supports genotype mapping
[109]50
[150]51        /// You have to reimplement this method.
[513]52        /// If your converter cannot do its job, return empty string - return SString();
53        /// Any other return value is assumed to be output genotype.
[150]54        /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object
[735]55        virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0;
[109]56
[150]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) {}
[109]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{
[150]72        friend class GenoConvParam;
73        SList converters;
[109]74public:
[150]75        GenoConvManager();
76        ~GenoConvManager();
77        class GenoConvParam param;
78        /// make a genotype in other format. genotype will be invalid
79        /// if GenoConvManager cannot convert it.
[732]80        Geno convert(Geno &in, char format, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
[150]81        /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable)
82        void addConverter(GenoConverter *conv);
83        /// unregister GenoConverter
84        void removeConverter(GenoConverter *conv);
[109]85
[150]86        char *getPath(char in, char out, char *path, int maxlen, int *mapavailable = 0);
87        char *getFormatPath(char in, char out, char *path, int maxlen, int *mapavailable = 0);
88        /// returns the list of converters meeting the specified criteria
89        /// pass result=0 if you only need one result (by return value)
90        /// default criteria values mean "don't care", pass anything else to narrow your search
91        GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, char in = -1, char out = -1, int enabled = -1, char* name = 0);
[109]92};
93
94#endif
Note: See TracBrowser for help on using the repository browser.