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

Last change on this file since 415 was 415, checked in by Maciej Komosinski, 9 years ago

Introduced a new field, is_valid, which combines isValid and validity, and is saved to .gen files

  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
[138]4
5#include "genoobj.h"
6#include <frams/util/extvalue.h>
7#include <frams/model/autoname.h>
[203]8#include "collectionobj.h"
[138]9
10#define FIELDSTRUCT GenoObj
11ParamEntry geno_paramtab[]=
12{
[415]13{"Geno",1,15,"Geno","All information about a single genotype.\nThis is a genetics-only object which does not contain any performance data. See also: Genotype class"},
[138]14{"name",0,PARAM_NOSTATIC,"Name","s 0 40",GETSET(name),},
[240]15{"rawgenotype",0,PARAM_NOSTATIC | PARAM_READONLY,"Raw genotype","s 1",GETONLY(genotype),"Genotype, excluding the format specifier"},
[138]16{"info",0,PARAM_NOSTATIC,"Info","s 1",GETSET(info),"Additional information or comments",},
[240]17{"format",0,PARAM_NOSTATIC | PARAM_READONLY,"Format","d",GETONLY(format),"Genotype format",},
[415]18{"genotype",0,PARAM_NOSTATIC | PARAM_READONLY,"Genotype","s 1",GETONLY(string),"Genes as a string of characters",},
19{"isValid",0,PARAM_NOSTATIC | PARAM_READONLY | PARAM_DEPRECATED,"Valid","d 0 1",GETONLY(isvalid),},
20{"is_valid",0,PARAM_NOSTATIC,"Valid","d -1 1 -1",GETSET(isvalid),},
[138]21{"getConverted",0,PARAM_NOSTATIC,"get converted genotype","p oGeno(d format)",PROCEDURE(p_getconvert),},
[240]22{"f0genotype",0,PARAM_NOSTATIC | PARAM_READONLY,"f0 genotype","s 1",GETONLY(f0genotype),"converted to f0 genotype",},
[138]23{"new",0,0,"create new empty object","p oGeno()",PROCEDURE(p_new),},
24{"newFromString",0,0,"create new object from supplied string argument","p oGeno(s genotype)",PROCEDURE(p_newfromstring),},
25{"newFrom",0,0,"create new object","p oGeno(s genotype,d format,s name,s description)",PROCEDURE(p_newfrom),},
[240]26{"autoname",0,PARAM_NOSTATIC | PARAM_READONLY,"Autogenerated name","s",GETONLY(autoname),},
27{"toVector",0,PARAM_READONLY | PARAM_NOSTATIC,"serialization support","oVector",GETONLY(toVector),},
[203]28{"newFromVector",0,0,"serialization support","p oGeno(oVector)",PROCEDURE(p_newfromvector),},
[138]29{0,0,0,},
30};
31#undef FIELDSTRUCT
32
33void GenoObj::get_isvalid(ExtValue *ret)
34{ret->setInt(isValid());}
35
[415]36int GenoObj::set_isvalid(const ExtValue *v)
37{
38paInt n=v->getInt();
39if (getValid()!=n)
40        {
41        setValid(n);
42        return PSET_CHANGED;
43        }
44return 0;
45}
46
[138]47void GenoObj::get_genotype(ExtValue *ret)
48{ret->setString(getGene());}
49
50void GenoObj::get_name(ExtValue *ret)
51{ret->setString(getName());}
52
53void GenoObj::get_autoname(ExtValue *ret)
54{
55Model m(*this);
56ret->setString(AutoName::makeName(m));
57}
58
59int GenoObj::set_name(const ExtValue *v)
60{setName(v->getString());
61return PSET_CHANGED;}
62
63void GenoObj::get_info(ExtValue *ret)
64{ret->setString(getComment());}
65
66void GenoObj::get_string(ExtValue *ret)
67{ret->setString(shortString());}
68
69void GenoObj::get_format(ExtValue *ret)
70{ret->setInt(getFormat());}
71
72int GenoObj::set_info(const ExtValue *v)
73{setComment(v->getString());
74return PSET_CHANGED;}
75
76void GenoObj::get_f0genotype(ExtValue *ret)
77{ret->setString(getConverted('0').getGene());}
78
79void GenoObj::p_getconvert(ExtValue *args,ExtValue *ret)
80{*ret=makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));}
81
82void GenoObj::p_new(ExtValue *args,ExtValue *ret)
83{*ret=makeDynamicObjectAndDecRef(new Geno());}
84
85void GenoObj::p_newfromstring(ExtValue *args,ExtValue *ret)
86{*ret=makeDynamicObjectAndDecRef(new Geno(args[0].getString()));}
87
88void GenoObj::p_newfrom(ExtValue *args,ExtValue *ret)
89{*ret=makeDynamicObjectAndDecRef(new Geno(args[3].getString(),(char)args[2].getInt(),
90                                 args[1].getString(),args[0].getString()));}
91
92Param& GenoObj::getStaticParam()
93{
94#ifdef __CODEGUARD__
95static GenoObj static_genoobj;
96static Param static_genoparam(geno_paramtab,&static_genoobj);
97#else
98static Param static_genoparam(geno_paramtab);
99#endif
100return static_genoparam;
101}
102
103Param& GenoObj::getDynamicParam()
104{
105static Param dynamic_genoparam(geno_paramtab);
106return dynamic_genoparam;
107}
108
109ParamInterface* GenoObj::getInterface() {return &getStaticParam();}
110
111ExtObject GenoObj::makeStaticObject(Geno* g)
112{return ExtObject(&getStaticParam(),(void*)g);}
113
114ExtObject GenoObj::makeDynamicObject(Geno* g)
115{return ExtObject(&getDynamicParam(),(DestrBase*)g);}
116
117ExtObject GenoObj::makeDynamicObjectAndDecRef(Geno* g)
118{
119const ExtObject& o=makeDynamicObject(g);
120g->decref();
121return o;
122}
123
[171]124Geno* GenoObj::fromObject(const ExtValue& v, bool warn)
[138]125{
[171]126return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn);
[138]127}
[203]128
129void GenoObj::get_toVector(ExtValue *ret)
130{
131VectorObject *vec=new VectorObject;
132vec->data+=new ExtValue(shortString());
133vec->data+=new ExtValue(getName());
134vec->data+=new ExtValue(getComment());
135ret->setObject(ExtObject(&VectorObject::par,vec));
136}
137
138void GenoObj::p_newfromvector(ExtValue *args,ExtValue *ret)
139{
140VectorObject *vec=VectorObject::fromObject(args->getObject());
141if (vec && (vec->data.size()>=3))
142        {
[219]143        SString g=vec->get(0)?vec->get(0)->getString():SString::empty();
144        SString n=vec->get(1)?vec->get(1)->getString():SString::empty();
145        SString c=vec->get(2)?vec->get(2)->getString():SString::empty();
[203]146        *ret=makeDynamicObjectAndDecRef(new Geno(g,-1,n,c));
147        }
148else
149        ret->setEmpty();
150}
[222]151
152/////////////
153
154REGISTER_DESERIALIZABLE(GenoObj)
Note: See TracBrowser for help on using the repository browser.