Ignore:
Timestamp:
06/25/20 00:34:29 (4 years ago)
Author:
Maciej Komosinski
Message:

Genetic format ID becomes a string (no longer limited to a single character)

File:
1 edited

Legend:

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

    r841 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    5757                pe->flags = 0;
    5858                std::string descr = "f";
    59                 descr += gk->in_format;
     59                descr += gk->in_format.c_str();
    6060                descr += " --> f";
    61                 descr += gk->out_format;
     61                descr += gk->out_format.c_str();
    6262                descr += "  :  ";
    6363                descr += gk->name;
     
    101101}
    102102
    103 GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, char in, char out, int enabled, char* name)
     103GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, const SString& in, const SString& out, int enabled, char* name)
    104104{
    105105        GenoConverter *gk, *retval = 0;
     
    107107        for (; gk = (GenoConverter*)converters(i); i++)
    108108        {
    109                 if ((in != -1) && (in != gk->in_format)) continue;
    110                 if ((out != -1) && (out != gk->out_format)) continue;
     109                if ((in != Geno::UNKNOWN_FORMAT) && (in != gk->in_format)) continue;
     110                if ((out != Geno::UNKNOWN_FORMAT) && (out != gk->out_format)) continue;
    111111                if ((enabled != -1) && (enabled != gk->enabled)) continue;
    112112                if ((name) && (strcmp(name, gk->name))) continue;
     
    123123/// (can be NULL if you don't need this information)
    124124
    125 char *GenoConvManager::getPath(char in, char out, char *path, int maxlen, int *mapavailable)
     125GenoConverter **GenoConvManager::getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable)
    126126{
    127127        if (!maxlen) return 0;
     
    132132                if ((gk->enabled) && (gk->in_format == in))
    133133                {
    134                         *path = (char)i;
     134                        *path = gk;
    135135                        if (gk->out_format == out)
    136136                        {
     
    142142                        {
    143143                                int mapavail;
    144                                 char *ret = getPath(gk->out_format, out, path + 1, maxlen - 1, &mapavail);
     144                                GenoConverter **ret = getPath(gk->out_format, out, path + 1, maxlen - 1, &mapavail);
    145145                                if (ret)
    146146                                {
     
    155155}
    156156
    157 char *GenoConvManager::getFormatPath(char in, char out, char *path, int maxlen, int *mapavailable)
    158 {
    159         char *ret = getPath(in, out, path, maxlen, mapavailable);
    160         if (ret)
    161         {
    162                 for (char*t = path; t <= ret; t++)
    163                         *t = ((GenoConverter*)converters(*t))->out_format;
    164         }
    165         return ret;
    166 }
    167 
    168 Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool using_checkpoints, bool *converter_missing)
     157Geno GenoConvManager::convert(Geno &in, SString format, MultiMap *map, bool using_checkpoints, bool *converter_missing)
    169158{
    170159        if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; }
    171         char path[10];
     160        GenoConverter *path[10];
    172161        int dep;
    173         char *ret;
    174         if (in.isInvalid()) { if (converter_missing) *converter_missing = false; return Geno("", 0, "", "invalid genotype cannot be converted"); }
     162        GenoConverter **ret;
     163        if (in.isInvalid()) { if (converter_missing) *converter_missing = false; return Geno("", Geno::INVALID_FORMAT, "", "invalid genotype cannot be converted"); }
    175164        int mapavail;
    176165        for (dep = 1; dep < (int)sizeof(path); dep++) //iterative deepening
    177166                if (ret = getPath(in.getFormat(), format, path, dep, &mapavail)) break;
    178         if (!ret) { if (converter_missing) *converter_missing = true; return Geno("", 0, "", "converter not found"); }
     167        if (!ret) { if (converter_missing) *converter_missing = true; return Geno("", Geno::INVALID_FORMAT, "", "converter not found"); }
    179168        if (converter_missing) *converter_missing = false;
    180169        if (!map) mapavail = 0;
    181         char *t = path;
     170        GenoConverter **t = path;
    182171        SString tmp;
    183172        tmp = in.getGenes();
     
    186175        for (; t <= ret; t++)
    187176        {
    188                 GenoConverter *gk = (GenoConverter*)converters(*t);
     177                GenoConverter *gk = *t;
    189178                tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints);
    190179                if (!tmp.len())
    191180                {
    192                         string t = ssprintf("f%c->f%c conversion failed (%s)", gk->in_format, gk->out_format, gk->name);
    193                         return Geno(0, 0, 0, t.c_str());
     181                        string t = ssprintf("f%s->f%s conversion failed (%s)", gk->in_format.c_str(), gk->out_format.c_str(), gk->name);
     182                        return Geno("", Geno::INVALID_FORMAT, "", t.c_str());
    194183                }
    195184                if (mapavail)
Note: See TracChangeset for help on using the changeset viewer.