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