Changeset 955 for cpp/frams/genetics/genoconv.cpp
- Timestamp:
- 06/25/20 00:34:29 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/genoconv.cpp
r841 r955 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 57 57 pe->flags = 0; 58 58 std::string descr = "f"; 59 descr += gk->in_format ;59 descr += gk->in_format.c_str(); 60 60 descr += " --> f"; 61 descr += gk->out_format ;61 descr += gk->out_format.c_str(); 62 62 descr += " : "; 63 63 descr += gk->name; … … 101 101 } 102 102 103 GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, c har in, charout, int enabled, char* name)103 GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, const SString& in, const SString& out, int enabled, char* name) 104 104 { 105 105 GenoConverter *gk, *retval = 0; … … 107 107 for (; gk = (GenoConverter*)converters(i); i++) 108 108 { 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; 111 111 if ((enabled != -1) && (enabled != gk->enabled)) continue; 112 112 if ((name) && (strcmp(name, gk->name))) continue; … … 123 123 /// (can be NULL if you don't need this information) 124 124 125 char *GenoConvManager::getPath(char in, char out, char*path, int maxlen, int *mapavailable)125 GenoConverter **GenoConvManager::getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable) 126 126 { 127 127 if (!maxlen) return 0; … … 132 132 if ((gk->enabled) && (gk->in_format == in)) 133 133 { 134 *path = (char)i;134 *path = gk; 135 135 if (gk->out_format == out) 136 136 { … … 142 142 { 143 143 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); 145 145 if (ret) 146 146 { … … 155 155 } 156 156 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) 157 Geno GenoConvManager::convert(Geno &in, SString format, MultiMap *map, bool using_checkpoints, bool *converter_missing) 169 158 { 170 159 if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; } 171 charpath[10];160 GenoConverter *path[10]; 172 161 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"); } 175 164 int mapavail; 176 165 for (dep = 1; dep < (int)sizeof(path); dep++) //iterative deepening 177 166 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"); } 179 168 if (converter_missing) *converter_missing = false; 180 169 if (!map) mapavail = 0; 181 char*t = path;170 GenoConverter **t = path; 182 171 SString tmp; 183 172 tmp = in.getGenes(); … … 186 175 for (; t <= ret; t++) 187 176 { 188 GenoConverter *gk = (GenoConverter*)converters(*t);177 GenoConverter *gk = *t; 189 178 tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints); 190 179 if (!tmp.len()) 191 180 { 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()); 194 183 } 195 184 if (mapavail)
Note: See TracChangeset
for help on using the changeset viewer.