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

Last change on this file since 1244 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
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
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
19class GenoConvParam : public Param
20{
21        GenoConvManager *gcm;
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
23        char tmp_id[20];
24        void freetab();
25public:
26        GenoConvParam(GenoConvManager *g);
27        ~GenoConvParam();
28        void *getTarget(int);
29        const char* id(int i);
30        void updatetab();
31};
32
33class MultiMap;
34
35/// Base class for all Geno Converters.
36/// In constructor you have to set public fields indicating your identity and supported formats.
37/// Each converter serves one in-out format pair.
38/// The instance of your converter should be registered in GenoConvManager.
39class GenoConverter
40{
41public:
42        const char *name;       //< converter name (short)
43        SString in_format,      //< input format, e.g. "1"
44                out_format;     //< output format, e.g. "0"
45        paInt enabled;  //< don't touch this! (used by configuration module)
46        paInt mapsupport; //< set to 1 if your converter supports genotype mapping
47
48        /// You have to reimplement this method.
49        /// If your converter cannot do its job, return empty string - return SString();
50        /// Any other return value is assumed to be output genotype.
51        /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object
52        virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0;
53
54        virtual ~GenoConverter() {}
55        /// Don't forget to set public fields in your constructor
56        GenoConverter() :name(""), in_format(Geno::FORMAT_UNKNOWN), out_format("0"), enabled(1), mapsupport(0) {}
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{
69        friend class GenoConvParam;
70        SList converters;
71public:
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.
77        Geno convert(Geno &in, SString format_list, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
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);
82
83        GenoConverter **getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable = 0);
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
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);
88};
89
90#endif
Note: See TracBrowser for help on using the repository browser.