[138] | 1 | // This file is a part of the Framsticks GDK. |
---|
[197] | 2 | // Copyright (C) 1999-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
[138] | 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 |
---|
| 10 | ParamEntry 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 | |
---|
| 29 | void GenoObj::get_isvalid(ExtValue *ret) |
---|
| 30 | {ret->setInt(isValid());} |
---|
| 31 | |
---|
| 32 | void GenoObj::get_genotype(ExtValue *ret) |
---|
| 33 | {ret->setString(getGene());} |
---|
| 34 | |
---|
| 35 | void GenoObj::get_name(ExtValue *ret) |
---|
| 36 | {ret->setString(getName());} |
---|
| 37 | |
---|
| 38 | void GenoObj::get_autoname(ExtValue *ret) |
---|
| 39 | { |
---|
| 40 | Model m(*this); |
---|
| 41 | ret->setString(AutoName::makeName(m)); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | int GenoObj::set_name(const ExtValue *v) |
---|
| 45 | {setName(v->getString()); |
---|
| 46 | return PSET_CHANGED;} |
---|
| 47 | |
---|
| 48 | void GenoObj::get_info(ExtValue *ret) |
---|
| 49 | {ret->setString(getComment());} |
---|
| 50 | |
---|
| 51 | void GenoObj::get_string(ExtValue *ret) |
---|
| 52 | {ret->setString(shortString());} |
---|
| 53 | |
---|
| 54 | void GenoObj::get_format(ExtValue *ret) |
---|
| 55 | {ret->setInt(getFormat());} |
---|
| 56 | |
---|
| 57 | int GenoObj::set_info(const ExtValue *v) |
---|
| 58 | {setComment(v->getString()); |
---|
| 59 | return PSET_CHANGED;} |
---|
| 60 | |
---|
| 61 | void GenoObj::get_f0genotype(ExtValue *ret) |
---|
| 62 | {ret->setString(getConverted('0').getGene());} |
---|
| 63 | |
---|
| 64 | void GenoObj::p_getconvert(ExtValue *args,ExtValue *ret) |
---|
| 65 | {*ret=makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));} |
---|
| 66 | |
---|
| 67 | void GenoObj::p_new(ExtValue *args,ExtValue *ret) |
---|
| 68 | {*ret=makeDynamicObjectAndDecRef(new Geno());} |
---|
| 69 | |
---|
| 70 | void GenoObj::p_newfromstring(ExtValue *args,ExtValue *ret) |
---|
| 71 | {*ret=makeDynamicObjectAndDecRef(new Geno(args[0].getString()));} |
---|
| 72 | |
---|
| 73 | void 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 | |
---|
| 77 | Param& GenoObj::getStaticParam() |
---|
| 78 | { |
---|
| 79 | #ifdef __CODEGUARD__ |
---|
| 80 | static GenoObj static_genoobj; |
---|
| 81 | static Param static_genoparam(geno_paramtab,&static_genoobj); |
---|
| 82 | #else |
---|
| 83 | static Param static_genoparam(geno_paramtab); |
---|
| 84 | #endif |
---|
| 85 | return static_genoparam; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | Param& GenoObj::getDynamicParam() |
---|
| 89 | { |
---|
| 90 | static Param dynamic_genoparam(geno_paramtab); |
---|
| 91 | return dynamic_genoparam; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | ParamInterface* GenoObj::getInterface() {return &getStaticParam();} |
---|
| 95 | |
---|
| 96 | ExtObject GenoObj::makeStaticObject(Geno* g) |
---|
| 97 | {return ExtObject(&getStaticParam(),(void*)g);} |
---|
| 98 | |
---|
| 99 | ExtObject GenoObj::makeDynamicObject(Geno* g) |
---|
| 100 | {return ExtObject(&getDynamicParam(),(DestrBase*)g);} |
---|
| 101 | |
---|
| 102 | ExtObject GenoObj::makeDynamicObjectAndDecRef(Geno* g) |
---|
| 103 | { |
---|
| 104 | const ExtObject& o=makeDynamicObject(g); |
---|
| 105 | g->decref(); |
---|
| 106 | return o; |
---|
| 107 | } |
---|
| 108 | |
---|
[171] | 109 | Geno* GenoObj::fromObject(const ExtValue& v, bool warn) |
---|
[138] | 110 | { |
---|
[171] | 111 | return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn); |
---|
[138] | 112 | } |
---|