source: cpp/frams/vm/classes/genoobj.cpp @ 200

Last change on this file since 200 was 197, checked in by Maciej Komosinski, 11 years ago

GDK used by developers since 1999, distributed on the web since 2002

  • 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) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "genoobj.h"
6#include <frams/util/extvalue.h>
7#include <frams/model/autoname.h>
8
9#define FIELDSTRUCT GenoObj
10ParamEntry geno_paramtab[]=
11{
12{"Geno",1,12,"Geno","All information about a single genotype.\nThis is a genetics-only object which does not contain any performance data. See also: Genotype class"},
13{"name",0,PARAM_NOSTATIC,"Name","s 0 40",GETSET(name),},
14{"rawgenotype",0,PARAM_NOSTATIC+PARAM_READONLY,"Raw genotype","s 1",GETONLY(genotype),"Genotype, excluding the format specifier"},
15{"info",0,PARAM_NOSTATIC,"Info","s 1",GETSET(info),"Additional information or comments",},
16{"format",0,PARAM_NOSTATIC+PARAM_READONLY,"Format","d",GETONLY(format),"Genotype format",},
17{"genotype",0,PARAM_NOSTATIC+PARAM_READONLY,"Genotype","s 1",GETONLY(string),},
18{"isValid",0,PARAM_NOSTATIC+PARAM_READONLY,"Valid","d 0 1",GETONLY(isvalid),},
19{"getConverted",0,PARAM_NOSTATIC,"get converted genotype","p oGeno(d format)",PROCEDURE(p_getconvert),},
20{"f0genotype",0,PARAM_NOSTATIC+PARAM_READONLY,"f0 genotype","s 1",GETONLY(f0genotype),"converted to f0 genotype",},
21{"new",0,0,"create new empty object","p oGeno()",PROCEDURE(p_new),},
22{"newFromString",0,0,"create new object from supplied string argument","p oGeno(s genotype)",PROCEDURE(p_newfromstring),},
23{"newFrom",0,0,"create new object","p oGeno(s genotype,d format,s name,s description)",PROCEDURE(p_newfrom),},
24{"autoname",0,PARAM_NOSTATIC+PARAM_READONLY,"Autogenerated name","s",GETONLY(autoname),},
25{0,0,0,},
26};
27#undef FIELDSTRUCT
28
29void GenoObj::get_isvalid(ExtValue *ret)
30{ret->setInt(isValid());}
31
32void GenoObj::get_genotype(ExtValue *ret)
33{ret->setString(getGene());}
34
35void GenoObj::get_name(ExtValue *ret)
36{ret->setString(getName());}
37
38void GenoObj::get_autoname(ExtValue *ret)
39{
40Model m(*this);
41ret->setString(AutoName::makeName(m));
42}
43
44int GenoObj::set_name(const ExtValue *v)
45{setName(v->getString());
46return PSET_CHANGED;}
47
48void GenoObj::get_info(ExtValue *ret)
49{ret->setString(getComment());}
50
51void GenoObj::get_string(ExtValue *ret)
52{ret->setString(shortString());}
53
54void GenoObj::get_format(ExtValue *ret)
55{ret->setInt(getFormat());}
56
57int GenoObj::set_info(const ExtValue *v)
58{setComment(v->getString());
59return PSET_CHANGED;}
60
61void GenoObj::get_f0genotype(ExtValue *ret)
62{ret->setString(getConverted('0').getGene());}
63
64void GenoObj::p_getconvert(ExtValue *args,ExtValue *ret)
65{*ret=makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));}
66
67void GenoObj::p_new(ExtValue *args,ExtValue *ret)
68{*ret=makeDynamicObjectAndDecRef(new Geno());}
69
70void GenoObj::p_newfromstring(ExtValue *args,ExtValue *ret)
71{*ret=makeDynamicObjectAndDecRef(new Geno(args[0].getString()));}
72
73void GenoObj::p_newfrom(ExtValue *args,ExtValue *ret)
74{*ret=makeDynamicObjectAndDecRef(new Geno(args[3].getString(),(char)args[2].getInt(),
75                                 args[1].getString(),args[0].getString()));}
76
77Param& GenoObj::getStaticParam()
78{
79#ifdef __CODEGUARD__
80static GenoObj static_genoobj;
81static Param static_genoparam(geno_paramtab,&static_genoobj);
82#else
83static Param static_genoparam(geno_paramtab);
84#endif
85return static_genoparam;
86}
87
88Param& GenoObj::getDynamicParam()
89{
90static Param dynamic_genoparam(geno_paramtab);
91return dynamic_genoparam;
92}
93
94ParamInterface* GenoObj::getInterface() {return &getStaticParam();}
95
96ExtObject GenoObj::makeStaticObject(Geno* g)
97{return ExtObject(&getStaticParam(),(void*)g);}
98
99ExtObject GenoObj::makeDynamicObject(Geno* g)
100{return ExtObject(&getDynamicParam(),(DestrBase*)g);}
101
102ExtObject GenoObj::makeDynamicObjectAndDecRef(Geno* g)
103{
104const ExtObject& o=makeDynamicObject(g);
105g->decref();
106return o;
107}
108
109Geno* GenoObj::fromObject(const ExtValue& v, bool warn)
110{
111return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn);
112}
Note: See TracBrowser for help on using the repository browser.