Ignore:
Timestamp:
05/02/23 01:36:15 (13 months ago)
Author:
Maciej Komosinski
Message:
  • Thanks to r1230, it is possible to detect (and repair=remove) junk trailing genes that are left after successful parsing (after last '>')
  • The validate() function may attempt to repair a genotype where earlier it would give up
  • Stricter parsing of the '#' gene
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_conv.cpp

    r1227 r1231  
    2727SString GenoConv_f40::convert(SString &in, MultiMap *map, bool using_checkpoints)
    2828{
    29         int res;
    3029        f4_Model *model = new f4_Model();
    31         res = model->buildFromF4(in, using_checkpoints);
    32         if (GENOPER_OK != res)
     30        int res = model->buildFromF4(in, using_checkpoints);
     31        if (res != GENOPER_OK)
    3332        {
    3433                delete model;
     
    5554SString GenoConv_F41_TestOnly::convert(SString &in, MultiMap *map, bool using_checkpoints)
    5655{
    57         int res;
    5856        f4_Model *model = new f4_Model();
    59         res = model->buildFromF4(in, using_checkpoints);
    60         if (GENOPER_OK != res)
     57        int res = model->buildFromF4(in, using_checkpoints);
     58        if (res != GENOPER_OK)
    6159        {
    6260                delete model;
     
    8280int f4_Model::buildFromF4(SString &geno, bool using_checkpoints)
    8381{
    84         int i;
    85 
    8682        error = GENOPER_OK;
    8783        errorpos = -1;
    8884
     85        // transform geno from string to nodes
     86        f4_Node f4rootnode;
     87        int res = f4_process(geno.c_str(), &f4rootnode);
     88        if (res || (f4rootnode.childCount() != 1)) //consider any error fatal, preventing building a model
     89        {
     90                error = GENOPER_OPFAIL;
     91                errorpos = res;
     92                return error;
     93        }
     94
    8995        // build cells, and simulate
    9096        if (cells) delete cells;
    91         cells = new f4_Cells(geno, 0);
    92         if (GENOPER_OK != cells->getErrorCode())
     97        cells = new f4_Cells(f4rootnode.child, false);
     98        if (cells->getErrorCode() != GENOPER_OK)
    9399        {
    94100                error = cells->getErrorCode();
     
    99105
    100106        cells->simulate();
    101         if (GENOPER_OK != cells->getErrorCode())
     107        if (cells->getErrorCode() != GENOPER_OK)
    102108        {
    103109                error = cells->getErrorCode();
     
    107113
    108114        // reset recursive traverse flags
    109         for (i = 0; i < cells->cell_count; i++)
     115        for (int i = 0; i < cells->cell_count; i++)
    110116                cells->C[i]->recProcessedFlag = 0;
    111117
     
    113119
    114120        // process every cell
    115         int res;
    116         for (i = 0; i < cells->cell_count; i++)
    117         {
    118                 res = buildModelRec(cells->C[i]);
     121        for (int i = 0; i < cells->cell_count; i++)
     122        {
     123                int res = buildModelRec(cells->C[i]);
    119124                if (res)
    120125                {
    121                         logMessage("f4_Model", "buildFromF4", LOG_ERROR, "Error in building a Model");
     126                        logPrintf("f4_Model", "buildFromF4", LOG_ERROR, "Error %d when building a Model", res);
    122127                        error = res;
    123128                        break;
     
    125130        }
    126131
    127         res = close();
    128         if (0 == res) // invalid
     132        int res_close = close();
     133        if (res_close == 0) // invalid
     134        {
     135                logPrintf("f4_Model", "buildFromF4", LOG_ERROR, "Error %d when closing a Model", res_close);
    129136                error = -10;
     137        }
    130138
    131139        return error;
Note: See TracChangeset for help on using the changeset viewer.