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

Last change on this file since 119 was 109, checked in by sz, 8 years ago

source reorganization (see README)
new feature added: part/joint shapes (see frams/_demos/part_shapes.cpp)

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