source: cpp/frams/genetics/geno.h @ 146

Last change on this file since 146 was 145, checked in by sz, 10 years ago

Genetics reorganization (affects ALL applications!):

  • Converters/Validators? are now configured/initialized in a more verbose but also less confusing way
  • At the same time, the PreconfiguredGenetics? object will help you avoid the increased complexity by creating the ready-to-use environment that is sufficient in 99% of cases (see the demos)
  • Format F genetics updated (work in progress)
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#ifndef _GENO_H_
6#define _GENO_H_
7
8#include <frams/util/sstring.h>
9#include <frams/util/extvalue.h>
10
11class MultiMap;
12class Geno;
13class GenoConvManager;
14
15class GenoValidator
16{
17  public:
18virtual int testGenoValidity(Geno& g)=0;/// -1=no information  0=invalid  1=valid
19};
20
21/// basic GenoValidator that works by building a Model from any Geno (by converting to f0)
22/// validation fails when the model can't be built or the genotype can't be converted
23class ModelGenoValidator: public GenoValidator
24{
25public:
26        int testGenoValidity(Geno& g);
27};
28
29/// basic information about a single genotype.
30class Geno: public DestrBase
31{
32friend class Simulator;//needs to access validators directly
33SString gen;
34SString name;
35char format;
36SString txt;
37int isvalid; ///< <0 -> unknown   >=0 -> value for "isValid"
38
39Geno *f0gen;
40
41int mapinshift; /// # of characters in the initial comment
42int mapoutshift; /// # of characters in the output comment
43int multiline;
44
45void init(const SString& genstring,char genformat,const SString& genname,const SString& comment);
46void validate(void);
47
48void freeF0();
49
50bool isInvalid() {return isvalid==0;}
51
52friend class Model;
53friend class GenoConvManager;
54       
55public:
56/// create a genotype object from primitives
57/// @param genstring pure genotype, without any comments
58/// @param genformat genotype format
59/// @param comment information about genotype (for genetic operators and "history")
60Geno(const char *genstring=0,char genformat=-1,const char *genname=0,const char *comment=0);
61
62/// create a genotype object from primitives
63/// @param genstring pure genotype, wihtout any comments
64/// @param genformat genotype format
65/// @param name genotype name, new name will generated if needed
66/// @param comment information about genotype (for genetic operators and "history")
67Geno(const SString& genstring,char genformat,const SString& genname,const SString& comment);
68
69/// create object from full string, containing optional format and comment information
70Geno(const SString & fullstring);
71
72/// clone
73Geno(const Geno& src);
74
75void operator=(const Geno& src);
76
77~Geno();
78
79void setValid(int v) {isvalid=v;}
80int getValid() {return isvalid;}
81
82/// return string representation, with format comment at the beginning
83SString toString(void) const;
84SString shortString(void) const;
85
86void setString(const SString& genewithcomments);
87
88/** @param newformat=-1 -> don't change */
89void setGene(const SString& g, char newformat=-1);
90SString getGene(void) const;
91
92SString getName(void) const;
93void setName(const SString&);
94char getFormat(void) const;
95
96SString getComment(void) const;
97void setComment(const SString&);
98
99/// invalid genotype cannot be used to build a creature
100bool isValid(void);
101
102/// make converted version of the genotype.
103Geno getConverted(char otherformat,MultiMap *m=0);
104
105/// @return -1 = before first char in the string
106/// @return -2 = after last char in the string
107int mapGenToString(int genpos) const;
108/// @return -1 = before first char in the genotype
109/// @return -2 = after last char in the genotype
110int mapStringToGen(int stringpos) const;
111
112int operator==(const Geno &g) {return (format==g.format)&&(gen==g.gen);}
113
114void* owner;
115
116// managing global Geno-related objects (used for validation and conversion)
117static void addValidator(GenoValidator* gv) {validators+=gv;}
118static void removeValidator(GenoValidator* gv) {validators-=gv;}
119static void useConverters(GenoConvManager& gcm) {converters=&gcm;}
120static GenoConvManager &getConverters() {return *converters;}
121  protected:
122static GenoConvManager *converters;
123static SListTempl<GenoValidator*> validators;
124};
125
126#ifndef NO_GENOCONVMANAGER
127#include "genoconv.h"
128#endif
129
130#endif
Note: See TracBrowser for help on using the repository browser.