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

Last change on this file since 1252 was 999, checked in by Maciej Komosinski, 4 years ago

More consistent usage of "shapetype" (vs. "shape")

  • 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/
[955]2// Copyright (C) 1999-2020  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;
[783]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
[150]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.
[999]36/// In constructor you have to set public fields indicating your identity and supported formats.
[109]37/// Each converter serves one in-out format pair.
[999]38/// The instance of your converter should be registered in GenoConvManager.
[109]39class GenoConverter
40{
41public:
[150]42        const char *name;       //< converter name (short)
[999]43        SString in_format,      //< input format, e.g. "1"
44                out_format;     //< output format, e.g. "0"
[247]45        paInt enabled;  //< don't touch this! (used by configuration module)
46        paInt mapsupport; //< set to 1 if your converter supports genotype mapping
[109]47
[150]48        /// You have to reimplement this method.
[513]49        /// If your converter cannot do its job, return empty string - return SString();
50        /// Any other return value is assumed to be output genotype.
[150]51        /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object
[735]52        virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0;
[109]53
[150]54        virtual ~GenoConverter() {}
55        /// Don't forget to set public fields in your constructor
[988]56        GenoConverter() :name(""), in_format(Geno::FORMAT_UNKNOWN), out_format("0"), enabled(1), mapsupport(0) {}
[109]57};
58
59/// This class gathers abilities of all converters and can
60/// convert a genotype to any other one, provided there is
61/// a path of GenoConverters between them.
62/// In most cases you don't use this class directly,
63/// Geno::getConverted(int) provides full converting functionality.
64/// Explicit GenoConvManager object is only needed for registering
65/// your GenoConverter.
66/// Use DefaultGenoConvManager to register the standard genotype converters automatically.
67class GenoConvManager
68{
[150]69        friend class GenoConvParam;
70        SList converters;
[109]71public:
[150]72        GenoConvManager();
73        ~GenoConvManager();
74        class GenoConvParam param;
75        /// make a genotype in other format. genotype will be invalid
76        /// if GenoConvManager cannot convert it.
[972]77        Geno convert(Geno &in, SString format_list, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
[150]78        /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable)
79        void addConverter(GenoConverter *conv);
80        /// unregister GenoConverter
81        void removeConverter(GenoConverter *conv);
[109]82
[955]83        GenoConverter **getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable = 0);
[150]84        /// returns the list of converters meeting the specified criteria
85        /// pass result=0 if you only need one result (by return value)
86        /// default criteria values mean "don't care", pass anything else to narrow your search
[988]87        GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, const SString& in = Geno::FORMAT_UNKNOWN, const SString& out = Geno::FORMAT_UNKNOWN, int enabled = -1, char* name = 0);
[109]88};
89
90#endif
Note: See TracBrowser for help on using the repository browser.