- Timestamp:
- 06/22/23 03:33:58 (18 months ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/defgenoconv.cpp
r1017 r1256 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 7 7 #include GEN_CONFIG_FILE 8 8 9 #ifdef USE_GENCONV_f00s 10 #include "f0s/f0s_conv.h" 11 #endif 9 12 #ifdef USE_GENCONV_f10 10 13 #include "f1/f1_conv.h" … … 58 61 void DefaultGenoConvManager::addDefaultConverters() 59 62 { 63 #ifdef USE_GENCONV_f00s 64 addConverter(new GenoConv_f00s()); 65 #endif 60 66 #ifdef USE_GENCONV_f10 61 67 addConverter(new GenoConv_f1()); … … 107 113 #endif 108 114 109 param.updatetab();115 conv_enabling_param.updatetab(); 110 116 } -
cpp/frams/genetics/genoconv.cpp
r1183 r1256 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 33 33 { 34 34 if (i >= gcm->converters.size()) return 0; 35 sprintf(tmp_id, "gen konw%d", i);35 sprintf(tmp_id, "genoconv_%s", ((GenoConverter*)gcm->converters(i))->id().c_str()); 36 36 return tmp_id; 37 37 } … … 45 45 freetab(); 46 46 tab = (ParamEntry*)calloc(2 + ile, sizeof(ParamEntry)); 47 tab[0].id = "Genetics: Conver sions";47 tab[0].id = "Genetics: Converters"; 48 48 tab[0].group = 1; 49 49 tab[0].flags = (paInt)ile; … … 81 81 82 82 GenoConvManager::GenoConvManager() 83 :param(this) 84 { 83 :conv_enabling_param(this), 84 param("GenoConverters", "Converters between genetic formats") 85 { 86 param += &conv_enabling_param; 85 87 } 86 88 … … 93 95 { 94 96 converters += gc; 95 param.updatetab(); 96 } 97 auto *pi = gc->getParam(); 98 if (pi) 99 param += pi; 100 conv_enabling_param.updatetab(); 101 } 102 97 103 void GenoConvManager::removeConverter(GenoConverter *gc) 98 104 { 99 105 converters -= gc; 100 param.updatetab(); 106 auto *pi = gc->getParam(); 107 if (pi) 108 param -= pi; 109 conv_enabling_param.updatetab(); 101 110 } 102 111 -
cpp/frams/genetics/genoconv.h
r999 r1256 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #include "geno.h" 9 9 #include <frams/param/param.h> 10 #include <frams/param/paramlist.h> 10 11 #include <frams/util/list.h> 11 12 #include <frams/util/sstring.h> … … 21 22 GenoConvManager *gcm; 22 23 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. 24 25 void freetab(); 25 26 public: … … 52 53 virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) = 0; 53 54 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 54 62 virtual ~GenoConverter() {} 55 63 /// Don't forget to set public fields in your constructor … … 57 65 }; 58 66 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 61 68 /// 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. 66 71 /// Use DefaultGenoConvManager to register the standard genotype converters automatically. 67 72 class GenoConvManager … … 72 77 GenoConvManager(); 73 78 ~GenoConvManager(); 74 class GenoConvParam param; 79 class GenoConvParam conv_enabling_param; 80 ParamList param; 75 81 /// make a genotype in other format. genotype will be invalid 76 82 /// if GenoConvManager cannot convert it.
Note: See TracChangeset
for help on using the changeset viewer.