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

Last change on this file since 390 was 286, checked in by Maciej Komosinski, 10 years ago

Updated headers

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