[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> |
---|
[203] | 8 | #include "collectionobj.h" |
---|
[138] | 9 | |
---|
| 10 | #define FIELDSTRUCT GenoObj |
---|
| 11 | ParamEntry geno_paramtab[]= |
---|
| 12 | { |
---|
[203] | 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"}, |
---|
[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",}, |
---|
| 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),}, |
---|
[138] | 20 | {"getConverted",0,PARAM_NOSTATIC,"get converted genotype","p oGeno(d format)",PROCEDURE(p_getconvert),}, |
---|
[240] | 21 | {"f0genotype",0,PARAM_NOSTATIC | PARAM_READONLY,"f0 genotype","s 1",GETONLY(f0genotype),"converted to f0 genotype",}, |
---|
[138] | 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),}, |
---|
[240] | 25 | {"autoname",0,PARAM_NOSTATIC | PARAM_READONLY,"Autogenerated name","s",GETONLY(autoname),}, |
---|
| 26 | {"toVector",0,PARAM_READONLY | PARAM_NOSTATIC,"serialization support","oVector",GETONLY(toVector),}, |
---|
[203] | 27 | {"newFromVector",0,0,"serialization support","p oGeno(oVector)",PROCEDURE(p_newfromvector),}, |
---|
[138] | 28 | {0,0,0,}, |
---|
| 29 | }; |
---|
| 30 | #undef FIELDSTRUCT |
---|
| 31 | |
---|
| 32 | void GenoObj::get_isvalid(ExtValue *ret) |
---|
| 33 | {ret->setInt(isValid());} |
---|
| 34 | |
---|
| 35 | void GenoObj::get_genotype(ExtValue *ret) |
---|
| 36 | {ret->setString(getGene());} |
---|
| 37 | |
---|
| 38 | void GenoObj::get_name(ExtValue *ret) |
---|
| 39 | {ret->setString(getName());} |
---|
| 40 | |
---|
| 41 | void GenoObj::get_autoname(ExtValue *ret) |
---|
| 42 | { |
---|
| 43 | Model m(*this); |
---|
| 44 | ret->setString(AutoName::makeName(m)); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | int GenoObj::set_name(const ExtValue *v) |
---|
| 48 | {setName(v->getString()); |
---|
| 49 | return PSET_CHANGED;} |
---|
| 50 | |
---|
| 51 | void GenoObj::get_info(ExtValue *ret) |
---|
| 52 | {ret->setString(getComment());} |
---|
| 53 | |
---|
| 54 | void GenoObj::get_string(ExtValue *ret) |
---|
| 55 | {ret->setString(shortString());} |
---|
| 56 | |
---|
| 57 | void GenoObj::get_format(ExtValue *ret) |
---|
| 58 | {ret->setInt(getFormat());} |
---|
| 59 | |
---|
| 60 | int GenoObj::set_info(const ExtValue *v) |
---|
| 61 | {setComment(v->getString()); |
---|
| 62 | return PSET_CHANGED;} |
---|
| 63 | |
---|
| 64 | void GenoObj::get_f0genotype(ExtValue *ret) |
---|
| 65 | {ret->setString(getConverted('0').getGene());} |
---|
| 66 | |
---|
| 67 | void GenoObj::p_getconvert(ExtValue *args,ExtValue *ret) |
---|
| 68 | {*ret=makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));} |
---|
| 69 | |
---|
| 70 | void GenoObj::p_new(ExtValue *args,ExtValue *ret) |
---|
| 71 | {*ret=makeDynamicObjectAndDecRef(new Geno());} |
---|
| 72 | |
---|
| 73 | void GenoObj::p_newfromstring(ExtValue *args,ExtValue *ret) |
---|
| 74 | {*ret=makeDynamicObjectAndDecRef(new Geno(args[0].getString()));} |
---|
| 75 | |
---|
| 76 | void 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 | |
---|
| 80 | Param& GenoObj::getStaticParam() |
---|
| 81 | { |
---|
| 82 | #ifdef __CODEGUARD__ |
---|
| 83 | static GenoObj static_genoobj; |
---|
| 84 | static Param static_genoparam(geno_paramtab,&static_genoobj); |
---|
| 85 | #else |
---|
| 86 | static Param static_genoparam(geno_paramtab); |
---|
| 87 | #endif |
---|
| 88 | return static_genoparam; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | Param& GenoObj::getDynamicParam() |
---|
| 92 | { |
---|
| 93 | static Param dynamic_genoparam(geno_paramtab); |
---|
| 94 | return dynamic_genoparam; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | ParamInterface* GenoObj::getInterface() {return &getStaticParam();} |
---|
| 98 | |
---|
| 99 | ExtObject GenoObj::makeStaticObject(Geno* g) |
---|
| 100 | {return ExtObject(&getStaticParam(),(void*)g);} |
---|
| 101 | |
---|
| 102 | ExtObject GenoObj::makeDynamicObject(Geno* g) |
---|
| 103 | {return ExtObject(&getDynamicParam(),(DestrBase*)g);} |
---|
| 104 | |
---|
| 105 | ExtObject GenoObj::makeDynamicObjectAndDecRef(Geno* g) |
---|
| 106 | { |
---|
| 107 | const ExtObject& o=makeDynamicObject(g); |
---|
| 108 | g->decref(); |
---|
| 109 | return o; |
---|
| 110 | } |
---|
| 111 | |
---|
[171] | 112 | Geno* GenoObj::fromObject(const ExtValue& v, bool warn) |
---|
[138] | 113 | { |
---|
[171] | 114 | return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn); |
---|
[138] | 115 | } |
---|
[203] | 116 | |
---|
| 117 | void GenoObj::get_toVector(ExtValue *ret) |
---|
| 118 | { |
---|
| 119 | VectorObject *vec=new VectorObject; |
---|
| 120 | vec->data+=new ExtValue(shortString()); |
---|
| 121 | vec->data+=new ExtValue(getName()); |
---|
| 122 | vec->data+=new ExtValue(getComment()); |
---|
| 123 | ret->setObject(ExtObject(&VectorObject::par,vec)); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void GenoObj::p_newfromvector(ExtValue *args,ExtValue *ret) |
---|
| 127 | { |
---|
| 128 | VectorObject *vec=VectorObject::fromObject(args->getObject()); |
---|
| 129 | if (vec && (vec->data.size()>=3)) |
---|
| 130 | { |
---|
[219] | 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(); |
---|
[203] | 134 | *ret=makeDynamicObjectAndDecRef(new Geno(g,-1,n,c)); |
---|
| 135 | } |
---|
| 136 | else |
---|
| 137 | ret->setEmpty(); |
---|
| 138 | } |
---|
[222] | 139 | |
---|
| 140 | ///////////// |
---|
| 141 | |
---|
| 142 | REGISTER_DESERIALIZABLE(GenoObj) |
---|