Changeset 516 for cpp/frams


Ignore:
Timestamp:
06/22/16 16:34:36 (8 years ago)
Author:
Maciej Komosinski
Message:

Geno format as a string (no longer ascii number)

Location:
cpp/frams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/genman.cpp

    r513 r516  
    467467void GenMan::p_getsimplest(ExtValue *args, ExtValue *ret)
    468468{
    469         int format = args[0].getInt() + 48;
     469        int format = GenoObj::formatFromExtValue(args[0]);
    470470        if (!getOper_f(format))
    471471                ret->setEmpty();
  • cpp/frams/vm/classes/genoobj.cpp

    r420 r516  
    1515        { "rawgenotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "Raw genotype", "s 1", GETONLY(genotype), "Genotype, excluding the format specifier" },
    1616        { "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", },
     17        { "format", 0, PARAM_NOSTATIC | PARAM_READONLY, "Format", "s", GETONLY(format), "Genotype format", },
    1818        { "genotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "Genotype", "s 1", GETONLY(string), "Genes as a string of characters", },
    1919        { "isValid", 0, PARAM_NOSTATIC | PARAM_READONLY | PARAM_DEPRECATED, "Valid", "d 0 1", GETONLY(isvalid), "Use 'is_valid' instead of 'isValid'." },
     
    2323        "-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."
    2424        },
    25         { "getConverted", 0, PARAM_NOSTATIC, "get converted genotype", "p oGeno(d format)", PROCEDURE(p_getconvert), },
     25        { "getConverted", 0, PARAM_NOSTATIC, "get converted genotype", "p oGeno(s format)", PROCEDURE(p_getconvert), },
    2626        { "f0genotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "f0 genotype", "s 1", GETONLY(f0genotype), "converted to f0 genotype", },
    2727        { "new", 0, 0, "create new empty object", "p oGeno()", PROCEDURE(p_new), },
    2828        { "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), },
     29        { "newFrom", 0, 0, "create new object", "p oGeno(s genotype,s format,s name,s description)", PROCEDURE(p_newfrom), },
    3030        { "autoname", 0, PARAM_NOSTATIC | PARAM_READONLY, "Autogenerated name", "s", GETONLY(autoname), },
    3131        { "toVector", 0, PARAM_READONLY | PARAM_NOSTATIC, "serialization support", "oVector", GETONLY(toVector), },
     
    8585void GenoObj::get_format(ExtValue *ret)
    8686{
    87         ret->setInt(getFormat());
     87        char format_as_string[2]={getFormat(),0};
     88        ret->setString(format_as_string);
    8889}
    8990
     
    99100}
    100101
     102char GenoObj::formatFromExtValue(ExtValue& v)
     103{
     104if (v.getType()==TInt)
     105        return v.getInt();
     106if (v.getType()==TString)
     107        {
     108        SString s=v.getString();
     109        if (s.len()==1)
     110                return s.charAt(0);
     111        }
     112return Geno::INVALID_FORMAT;
     113}
     114
    101115void GenoObj::p_getconvert(ExtValue *args, ExtValue *ret)
    102116{
    103         *ret = makeDynamicObjectAndDecRef(new Geno(getConverted((char)args[0].getInt())));
     117        *ret = makeDynamicObjectAndDecRef(new Geno(getConverted(formatFromExtValue(args[0]))));
    104118}
    105119
     
    116130void GenoObj::p_newfrom(ExtValue *args, ExtValue *ret)
    117131{
    118         *ret = makeDynamicObjectAndDecRef(new Geno(args[3].getString(), (char)args[2].getInt(),
     132        *ret = makeDynamicObjectAndDecRef(new Geno(args[3].getString(), formatFromExtValue(args[2]),
    119133                args[1].getString(), args[0].getString()));
    120134}
  • cpp/frams/vm/classes/genoobj.h

    r420 r516  
    3838        static Geno* fromObject(const ExtValue& v, bool warn = true);
    3939        static ParamInterface* getInterface();
     40        static char formatFromExtValue(ExtValue& v);
    4041
    4142        static Param& getStaticParam();
Note: See TracChangeset for help on using the changeset viewer.