Changeset 420 for cpp/frams/vm/classes/genoobj.cpp
- Timestamp:
- 08/03/15 01:43:55 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/genoobj.cpp
r415 r420 9 9 10 10 #define FIELDSTRUCT GenoObj 11 ParamEntry geno_paramtab[] =11 ParamEntry geno_paramtab[] = 12 12 { 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"}, 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),"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),}, 21 {"getConverted",0,PARAM_NOSTATIC,"get converted genotype","p oGeno(d format)",PROCEDURE(p_getconvert),}, 22 {"f0genotype",0,PARAM_NOSTATIC | PARAM_READONLY,"f0 genotype","s 1",GETONLY(f0genotype),"converted to f0 genotype",}, 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),}, 26 {"autoname",0,PARAM_NOSTATIC | PARAM_READONLY,"Autogenerated name","s",GETONLY(autoname),}, 27 {"toVector",0,PARAM_READONLY | PARAM_NOSTATIC,"serialization support","oVector",GETONLY(toVector),}, 28 {"newFromVector",0,0,"serialization support","p oGeno(oVector)",PROCEDURE(p_newfromvector),}, 29 {0,0,0,}, 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" }, 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), "Genes as a string of characters", }, 19 { "isValid", 0, PARAM_NOSTATIC | PARAM_READONLY | PARAM_DEPRECATED, "Valid", "d 0 1", GETONLY(isvalid), "Use 'is_valid' instead of 'isValid'." }, 20 { "is_valid", 0, PARAM_NOSTATIC, "Validity", "d -1 1 -1", GETSET(isvalid), 21 "0 = invalid genotype\n" 22 "1 = valid genotype\n" 23 "-1 = validity is not known. This is a transient state. The value of \"is_valid\" will never be -1 when read. It is safe to treat is_valid as boolean in statements like \"if (g.is_valid) ...\". Setting \"is_valid=-1\" will make it 0 or 1 again. This third state (-1) is only needed for loading Genotype objects from files where the \"is_valid\" field might not be present." 24 }, 25 { "getConverted", 0, PARAM_NOSTATIC, "get converted genotype", "p oGeno(d format)", PROCEDURE(p_getconvert), }, 26 { "f0genotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "f0 genotype", "s 1", GETONLY(f0genotype), "converted to f0 genotype", }, 27 { "new", 0, 0, "create new empty object", "p oGeno()", PROCEDURE(p_new), }, 28 { "newFromString", 0, 0, "create new object from supplied string argument", "p oGeno(s genotype)", PROCEDURE(p_newfromstring), }, 29 { "newFrom", 0, 0, "create new object", "p oGeno(s genotype,d format,s name,s description)", PROCEDURE(p_newfrom), }, 30 { "autoname", 0, PARAM_NOSTATIC | PARAM_READONLY, "Autogenerated name", "s", GETONLY(autoname), }, 31 { "toVector", 0, PARAM_READONLY | PARAM_NOSTATIC, "serialization support", "oVector", GETONLY(toVector), }, 32 { "newFromVector", 0, 0, "serialization support", "p oGeno(oVector)", PROCEDURE(p_newfromvector), }, 33 { 0, 0, 0, }, 30 34 }; 31 35 #undef FIELDSTRUCT 32 36 33 37 void GenoObj::get_isvalid(ExtValue *ret) 34 {ret->setInt(isValid());} 38 { 39 ret->setInt(isValid()); 40 } 35 41 36 42 int GenoObj::set_isvalid(const ExtValue *v) 37 43 { 38 paInt n=v->getInt();39 if (getValid()!=n)44 paInt n = v->getInt(); 45 if (getValid() != n) 40 46 { 41 setValid(n);42 return PSET_CHANGED;47 setValid(n); 48 return PSET_CHANGED; 43 49 } 44 return 0;50 return 0; 45 51 } 46 52 47 53 void GenoObj::get_genotype(ExtValue *ret) 48 {ret->setString(getGene());} 54 { 55 ret->setString(getGene()); 56 } 49 57 50 58 void GenoObj::get_name(ExtValue *ret) 51 {ret->setString(getName());} 59 { 60 ret->setString(getName()); 61 } 52 62 53 63 void GenoObj::get_autoname(ExtValue *ret) 54 64 { 55 Model m(*this);56 ret->setString(AutoName::makeName(m));65 Model m(*this); 66 ret->setString(AutoName::makeName(m)); 57 67 } 58 68 59 69 int GenoObj::set_name(const ExtValue *v) 60 {setName(v->getString()); 61 return PSET_CHANGED;} 70 { 71 setName(v->getString()); 72 return PSET_CHANGED; 73 } 62 74 63 75 void GenoObj::get_info(ExtValue *ret) 64 {ret->setString(getComment());} 76 { 77 ret->setString(getComment()); 78 } 65 79 66 80 void GenoObj::get_string(ExtValue *ret) 67 {ret->setString(shortString());} 81 { 82 ret->setString(shortString()); 83 } 68 84 69 85 void GenoObj::get_format(ExtValue *ret) 70 {ret->setInt(getFormat());} 86 { 87 ret->setInt(getFormat()); 88 } 71 89 72 90 int GenoObj::set_info(const ExtValue *v) 73 {setComment(v->getString()); 74 return PSET_CHANGED;} 91 { 92 setComment(v->getString()); 93 return PSET_CHANGED; 94 } 75 95 76 96 void GenoObj::get_f0genotype(ExtValue *ret) 77 {ret->setString(getConverted('0').getGene());} 97 { 98 ret->setString(getConverted('0').getGene()); 99 } 78 100 79 void GenoObj::p_getconvert(ExtValue *args,ExtValue *ret) 80 {*ret=makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));} 101 void GenoObj::p_getconvert(ExtValue *args, ExtValue *ret) 102 { 103 *ret = makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt()))); 104 } 81 105 82 void GenoObj::p_new(ExtValue *args,ExtValue *ret) 83 {*ret=makeDynamicObjectAndDecRef(new Geno());} 106 void GenoObj::p_new(ExtValue *args, ExtValue *ret) 107 { 108 *ret = makeDynamicObjectAndDecRef(new Geno()); 109 } 84 110 85 void GenoObj::p_newfromstring(ExtValue *args,ExtValue *ret) 86 {*ret=makeDynamicObjectAndDecRef(new Geno(args[0].getString()));} 111 void GenoObj::p_newfromstring(ExtValue *args, ExtValue *ret) 112 { 113 *ret = makeDynamicObjectAndDecRef(new Geno(args[0].getString())); 114 } 87 115 88 void 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()));} 116 void GenoObj::p_newfrom(ExtValue *args, ExtValue *ret) 117 { 118 *ret = makeDynamicObjectAndDecRef(new Geno(args[3].getString(), (char)args[2].getInt(), 119 args[1].getString(), args[0].getString())); 120 } 91 121 92 122 Param& GenoObj::getStaticParam() 93 123 { 94 124 #ifdef __CODEGUARD__ 95 static GenoObj static_genoobj;96 static Param static_genoparam(geno_paramtab,&static_genoobj);125 static GenoObj static_genoobj; 126 static Param static_genoparam(geno_paramtab,&static_genoobj); 97 127 #else 98 static Param static_genoparam(geno_paramtab);128 static Param static_genoparam(geno_paramtab); 99 129 #endif 100 return static_genoparam;130 return static_genoparam; 101 131 } 102 132 103 133 Param& GenoObj::getDynamicParam() 104 134 { 105 static Param dynamic_genoparam(geno_paramtab);106 return dynamic_genoparam;135 static Param dynamic_genoparam(geno_paramtab); 136 return dynamic_genoparam; 107 137 } 108 138 109 ParamInterface* GenoObj::getInterface() { return &getStaticParam();}139 ParamInterface* GenoObj::getInterface() { return &getStaticParam(); } 110 140 111 141 ExtObject GenoObj::makeStaticObject(Geno* g) 112 {return ExtObject(&getStaticParam(),(void*)g);} 142 { 143 return ExtObject(&getStaticParam(), (void*)g); 144 } 113 145 114 146 ExtObject GenoObj::makeDynamicObject(Geno* g) 115 {return ExtObject(&getDynamicParam(),(DestrBase*)g);} 147 { 148 return ExtObject(&getDynamicParam(), (DestrBase*)g); 149 } 116 150 117 151 ExtObject GenoObj::makeDynamicObjectAndDecRef(Geno* g) 118 152 { 119 const ExtObject& o=makeDynamicObject(g);120 g->decref();121 return o;153 const ExtObject& o = makeDynamicObject(g); 154 g->decref(); 155 return o; 122 156 } 123 157 124 158 Geno* GenoObj::fromObject(const ExtValue& v, bool warn) 125 159 { 126 return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn);160 return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn); 127 161 } 128 162 129 163 void GenoObj::get_toVector(ExtValue *ret) 130 164 { 131 VectorObject *vec=new VectorObject;132 vec->data+=new ExtValue(shortString());133 vec->data+=new ExtValue(getName());134 vec->data+=new ExtValue(getComment());135 ret->setObject(ExtObject(&VectorObject::par,vec));165 VectorObject *vec = new VectorObject; 166 vec->data += new ExtValue(shortString()); 167 vec->data += new ExtValue(getName()); 168 vec->data += new ExtValue(getComment()); 169 ret->setObject(ExtObject(&VectorObject::par, vec)); 136 170 } 137 171 138 void GenoObj::p_newfromvector(ExtValue *args, ExtValue *ret)172 void GenoObj::p_newfromvector(ExtValue *args, ExtValue *ret) 139 173 { 140 VectorObject *vec=VectorObject::fromObject(args->getObject());141 if (vec && (vec->data.size()>=3))174 VectorObject *vec = VectorObject::fromObject(args->getObject()); 175 if (vec && (vec->data.size() >= 3)) 142 176 { 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();146 *ret=makeDynamicObjectAndDecRef(new Geno(g,-1,n,c));177 SString g = vec->get(0) ? vec->get(0)->getString() : SString::empty(); 178 SString n = vec->get(1) ? vec->get(1)->getString() : SString::empty(); 179 SString c = vec->get(2) ? vec->get(2)->getString() : SString::empty(); 180 *ret = makeDynamicObjectAndDecRef(new Geno(g, -1, n, c)); 147 181 } 148 else149 ret->setEmpty();182 else 183 ret->setEmpty(); 150 184 } 151 185
Note: See TracChangeset
for help on using the changeset viewer.