1 | // This file is a part of the Framsticks GDK library. |
---|
2 | // Copyright (C) 2002-2011 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 "sstring.h" |
---|
9 | #include "extvalue.h" |
---|
10 | |
---|
11 | class MultiMap; |
---|
12 | class Geno; |
---|
13 | |
---|
14 | class GenoValidator |
---|
15 | { |
---|
16 | public: |
---|
17 | virtual int testGenoValidity(Geno& g)=0;/// -1=no information 0=invalid 1=valid |
---|
18 | }; |
---|
19 | |
---|
20 | /// basic information about a single genotype. |
---|
21 | class Geno: public DestrBase |
---|
22 | { |
---|
23 | SString gen; |
---|
24 | SString name; |
---|
25 | char format; |
---|
26 | SString txt; |
---|
27 | int isvalid; ///< <0 -> unknown >=0 -> value for "isValid" |
---|
28 | |
---|
29 | Geno *f0gen; |
---|
30 | |
---|
31 | int mapinshift; /// # of characters in the initial comment |
---|
32 | int mapoutshift; /// # of characters in the output comment |
---|
33 | int multiline; |
---|
34 | |
---|
35 | void init(const SString& genstring,int genformat,const SString& genname,const SString& comment); |
---|
36 | void validate(void); |
---|
37 | |
---|
38 | void freeF0(); |
---|
39 | |
---|
40 | int isInvalid() {return isvalid==0;} |
---|
41 | |
---|
42 | friend class Model; |
---|
43 | friend class GenoConvManager; |
---|
44 | |
---|
45 | public: |
---|
46 | /// create a genotype object from primitives |
---|
47 | /// @param genstring pure genotype, without any comments |
---|
48 | /// @param genformat genotype format |
---|
49 | /// @param comment information about genotype (for genetic operators and "history") |
---|
50 | Geno(const char *genstring=0,int genformat=-1,const char *genname=0,const char *comment=0); |
---|
51 | |
---|
52 | /// create a genotype object from primitives |
---|
53 | /// @param genstring pure genotype, wihtout any comments |
---|
54 | /// @param genformat genotype format |
---|
55 | /// @param name genotype name, new name will generated if needed |
---|
56 | /// @param comment information about genotype (for genetic operators and "history") |
---|
57 | Geno(const SString& genstring,int genformat,const SString& genname,const SString& comment); |
---|
58 | |
---|
59 | /// create object from full string, containing optional format and comment information |
---|
60 | Geno(const SString & fullstring); |
---|
61 | |
---|
62 | /// clone |
---|
63 | Geno(const Geno& src); |
---|
64 | |
---|
65 | void operator=(const Geno& src); |
---|
66 | |
---|
67 | ~Geno(); |
---|
68 | |
---|
69 | void setValid(int v) {isvalid=v;} |
---|
70 | int getValid() {return isvalid;} |
---|
71 | |
---|
72 | /// return string representation, with format comment at the beginning |
---|
73 | SString toString(void); |
---|
74 | SString shortString(void); |
---|
75 | |
---|
76 | void setString(const SString& genewithcomments); |
---|
77 | |
---|
78 | /** @param newformat=-1 -> don't change */ |
---|
79 | void setGene(const SString& g, int newformat=-1); |
---|
80 | SString getGene(void) const; |
---|
81 | |
---|
82 | SString getName(void) const; |
---|
83 | void setName(const SString&); |
---|
84 | int getFormat(void) const; |
---|
85 | |
---|
86 | SString getComment(void) const; |
---|
87 | void setComment(const SString&); |
---|
88 | |
---|
89 | /// invalid genotype cannot be used to build a creature |
---|
90 | int isValid(void); |
---|
91 | |
---|
92 | /// make converted version of the genotype. |
---|
93 | Geno getConverted(int otherformat,MultiMap *m=0); |
---|
94 | |
---|
95 | /// @return -1 = before first char in the string |
---|
96 | /// @return -2 = after last char in the string |
---|
97 | int mapGenToString(int genpos) const; |
---|
98 | /// @return -1 = before first char in the genotype |
---|
99 | /// @return -2 = after last char in the genotype |
---|
100 | int mapStringToGen(int stringpos) const; |
---|
101 | |
---|
102 | int operator==(const Geno &g) {return (format==g.format)&&(gen==g.gen);} |
---|
103 | |
---|
104 | void* owner; |
---|
105 | static SListTempl<GenoValidator*> validators; |
---|
106 | }; |
---|
107 | |
---|
108 | #ifndef NO_GENOCONVMANAGER |
---|
109 | #include "genoconv.h" |
---|
110 | #endif |
---|
111 | |
---|
112 | #endif |
---|