Changeset 1256 for cpp


Ignore:
Timestamp:
06/22/23 03:33:58 (18 months ago)
Author:
Maciej Komosinski
Message:
  • reasonable field names for enabling converters
  • automatically attach converter Param to GenoConvParam?
Location:
cpp/frams/genetics
Files:
3 edited

Legend:

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

    r1017 r1256  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    77#include GEN_CONFIG_FILE
    88
     9#ifdef USE_GENCONV_f00s
     10#include "f0s/f0s_conv.h"
     11#endif
    912#ifdef USE_GENCONV_f10
    1013#include "f1/f1_conv.h"
     
    5861void DefaultGenoConvManager::addDefaultConverters()
    5962{
     63#ifdef USE_GENCONV_f00s
     64        addConverter(new GenoConv_f00s());
     65#endif
    6066#ifdef USE_GENCONV_f10
    6167        addConverter(new GenoConv_f1());
     
    107113#endif
    108114
    109         param.updatetab();
     115        conv_enabling_param.updatetab();
    110116}
  • cpp/frams/genetics/genoconv.cpp

    r1183 r1256  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3333{
    3434        if (i >= gcm->converters.size()) return 0;
    35         sprintf(tmp_id, "genkonw%d", i);
     35        sprintf(tmp_id, "genoconv_%s", ((GenoConverter*)gcm->converters(i))->id().c_str());
    3636        return tmp_id;
    3737}
     
    4545        freetab();
    4646        tab = (ParamEntry*)calloc(2 + ile, sizeof(ParamEntry));
    47         tab[0].id = "Genetics: Conversions";
     47        tab[0].id = "Genetics: Converters";
    4848        tab[0].group = 1;
    4949        tab[0].flags = (paInt)ile;
     
    8181
    8282GenoConvManager::GenoConvManager()
    83         :param(this)
    84 {
     83        :conv_enabling_param(this),
     84        param("GenoConverters", "Converters between genetic formats")
     85{
     86        param += &conv_enabling_param;
    8587}
    8688
     
    9395{
    9496        converters += gc;
    95         param.updatetab();
    96 }
     97        auto *pi = gc->getParam();
     98        if (pi)
     99                param += pi;
     100        conv_enabling_param.updatetab();
     101}
     102
    97103void GenoConvManager::removeConverter(GenoConverter *gc)
    98104{
    99105        converters -= gc;
    100         param.updatetab();
     106        auto *pi = gc->getParam();
     107        if (pi)
     108                param -= pi;
     109        conv_enabling_param.updatetab();
    101110}
    102111
  • cpp/frams/genetics/genoconv.h

    r999 r1256  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    88#include "geno.h"
    99#include <frams/param/param.h>
     10#include <frams/param/paramlist.h>
    1011#include <frams/util/list.h>
    1112#include <frams/util/sstring.h>
     
    2122        GenoConvManager *gcm;
    2223        std::vector<std::string> gcnames; //stores names of converters so that these names persist and pointers to these names can be safely used externally
    23         char tmp_id[20];
     24        char tmp_id[20]; //id() always returns a pointer to this array, filled with the appropriate field id. The root of the problem is that Param functions return char pointers having unspecified lifetime. In contrast, name() returns individual preallocated pointers for individual items, but apparently, id() was too simple to deserve a better but more tedious implementation. Param api will not change, but what could be improved here is perhaps using ParamObject's dynamic paramtab (which did not exist when GenoConvParam was first implemented) so we don't have to care about individual pointers at all.
    2425        void freetab();
    2526public:
     
    5253        virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0;
    5354
     55        /// genoconverter enable/disable fields are named "genoconv_id", where id="f"+input_format+"_f"+output_format by default.
     56        /// Converters should implement id() and provide unique value - required when adding more than one converter operating on the same formats.
     57        virtual SString id() { return SString("f") + in_format + SString("_f") + out_format; }
     58
     59        /// Optional user-settable configuration for this converter which automatically gets added to GenoConvParam
     60        virtual ParamInterface* getParam() { return NULL; }
     61
    5462        virtual ~GenoConverter() {}
    5563        /// Don't forget to set public fields in your constructor
     
    5765};
    5866
    59 /// This class gathers abilities of all converters and can
    60 /// convert a genotype to any other one, provided there is
     67/// This class gathers abilities of all converters and can convert a genotype to any other one, provided there is
    6168/// a path of GenoConverters between them.
    62 /// In most cases you don't use this class directly,
    63 /// Geno::getConverted(int) provides full converting functionality.
    64 /// Explicit GenoConvManager object is only needed for registering
    65 /// your GenoConverter.
     69/// In most cases you don't use this class directly, Geno::getConverted(int) provides full converting functionality.
     70/// Explicit GenoConvManager object is only needed for registering your GenoConverter.
    6671/// Use DefaultGenoConvManager to register the standard genotype converters automatically.
    6772class GenoConvManager
     
    7277        GenoConvManager();
    7378        ~GenoConvManager();
    74         class GenoConvParam param;
     79        class GenoConvParam conv_enabling_param;
     80        ParamList param;
    7581        /// make a genotype in other format. genotype will be invalid
    7682        /// if GenoConvManager cannot convert it.
Note: See TracChangeset for help on using the changeset viewer.