Changeset 797 for cpp/frams/genetics/fB/fB_conv.cpp
- Timestamp:
- 06/06/18 01:45:18 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fB/fB_conv.cpp
r780 r797 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 // See LICENSE.txt for details. 4 1 5 #include "fB_conv.h" 2 6 … … 89 93 continue; 90 94 } 91 fH_Handle *handle = convertCharacterToHandle(gene[2], dims, start, end, ranges); 95 int hclasspos = 2; 96 if (gene[2] == '"') 97 { 98 hclasspos--; 99 if (!getNextCharId(gene, hclasspos)) 100 { 101 return ""; 102 } 103 } 104 fH_Handle *handle = convertCharacterToHandle(gene[hclasspos], dims, start, end, ranges); 92 105 ParamEntry *tab = creature.getParamTab(handle->type); 93 106 void *obj = ParamObject::makeObject(tab); … … 97 110 98 111 int propindex = 0; 99 int z = 3; 112 int z = hclasspos; 113 if (gene[z] == '"') 114 { 115 z--; 116 if (!getNextCharId(gene, z)) 117 { 118 delete handle; 119 ParamObject::freeObject(obj); 120 return ""; 121 } 122 } 100 123 endoffset = 0; 101 124 if (gene.indexOf("zz", 0) != -1) endoffset = 2; 125 int nclassdefcount = 1; 102 126 while (z < gene.len() - endoffset) 103 127 { 104 if (processNextLetter(creature, handle, par, gene, propindex, z, ranges) == -1) 105 { 106 logMessage("GenoConv_fBH", "convert", LOG_WARN, "Property of fH could not be parsed"); 107 } 128 if (processNextLetter(creature, handle, par, gene, propindex, z, ranges, nclassdefcount) == -1) 129 { 130 logMessage("GenoConv_fBH", "convert", LOG_ERROR, "Property of fH could not be parsed"); 131 delete handle; 132 ParamObject::freeObject(obj); 133 return ""; 134 } 135 } 136 if (handle->type == fHBodyType::NEURON && propindex < par.getPropCount()) 137 { 138 SString nclass; 139 if (!getNeuroClass(gene, nclass, nclassdefcount)) 140 { 141 delete handle; 142 ParamObject::freeObject(obj); 143 return ""; 144 } 145 par.setStringById(FH_PE_NEURO_DET, nclass); 108 146 } 109 147 handle->loadProperties(par); … … 132 170 } 133 171 134 int GenoConv_fBH::processNextLetter(fH_Builder &creature, fH_Handle *&currhandle, Param &par, SString gene, int &propindex, int &i, std::vector<IRange> ranges[3]) 172 bool GenoConv_fBH::getNextCharId(SString genotype, int &i) 173 { 174 i++; 175 if (genotype[i] == '"') 176 { 177 int nextid = i + 1; 178 do 179 { 180 nextid = genotype.indexOf('"', nextid); 181 if (nextid == -1) 182 { 183 return false; 184 } 185 nextid++; 186 } 187 while (genotype[nextid] == '"'); 188 i = nextid; 189 } 190 return true; 191 } 192 193 bool GenoConv_fBH::getNeuroClass(SString gene, SString &def, int nclassdefcount) 194 { 195 SString lastdef = "N"; 196 int nclass = 0; 197 int pos = 0; 198 while (nclass < nclassdefcount) 199 { 200 pos = gene.indexOf('\"', pos); 201 if (pos == -1) 202 { 203 def = lastdef; 204 return true; 205 } 206 pos++; 207 SString currdef; 208 if (gene.indexOf('\"', pos) == -1 || !gene.getNextToken(pos, currdef, '\"')) 209 { 210 def = lastdef; 211 return false; 212 } 213 lastdef = currdef; 214 nclass++; 215 } 216 def = lastdef; 217 return true; 218 } 219 220 int GenoConv_fBH::processNextLetter(fH_Builder &creature, fH_Handle *&currhandle, Param &par, SString gene, int &propindex, int &i, std::vector<IRange> ranges[3], int &nclassdefcount) 135 221 { 136 222 if (propindex >= par.getPropCount()) … … 147 233 par.setDefault(); 148 234 propindex = 0; 149 i++; 235 if (!getNextCharId(gene, i)) 236 return -1; 150 237 return 0; 151 238 } … … 166 253 } 167 254 propindex++; 168 i++; 255 if (!getNextCharId(gene, i)) 256 return -1; 169 257 return 0; 170 258 } 171 259 else if (currhandle->type == fHBodyType::NEURON && *par.id(propindex) == 'd') 172 260 { 173 //TODO: handle neuron classes and properties 261 //When 'd' property appears for i-th element in gene, the method 262 //looks for i-th neuron definition 263 SString nclass; 264 if (!getNeuroClass(gene, nclass, nclassdefcount)) return -1; 265 par.setString(propindex, nclass); 174 266 propindex++; 175 i++; 267 nclassdefcount++; 268 if (!getNextCharId(gene, i)) 269 return -1; 176 270 return 0; 177 271 }
Note: See TracChangeset
for help on using the changeset viewer.