- Timestamp:
- 07/18/16 04:16:11 (8 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/geno.cpp
r522 r530 29 29 owner = 0; 30 30 f0gen = 0; 31 isvalid = -1; 32 name = genname; 33 txt = comment; 34 setGeneAndFormat(genstring,genformat); 35 } 36 37 void Geno::setGeneAndFormat(const SString& genstring, char genformat) 38 { 31 39 mapinshift = 0; 32 40 mapoutshift = 0; 33 isvalid = -1;34 41 SString gencopy(genstring); 35 42 if (genformat == -1) … … 43 50 case '/': 44 51 genformat = genstring.charAt(2); 45 if ((genformat == '\0') || isspace(genformat))46 genformat = INVALID_FORMAT;47 52 if ((end = genstring.indexOf('\n')) >= 0) 48 53 { 54 mapinshift = end + 1; 55 gencopy = genstring.substr(end + 1); 56 if ((end>0) && (genstring[end-1]=='\r')) end--; 49 57 error_end = end; 50 58 if (end != 3) genformat = INVALID_FORMAT; 51 gencopy = genstring.substr(end + 1);52 mapinshift = end + 1;53 59 } 54 60 else … … 61 67 case '*': 62 68 genformat = genstring.charAt(2); 63 if ((genformat == '\0') || isspace(genformat))64 genformat = INVALID_FORMAT;65 69 if ((end = genstring.indexOf("*/")) >= 0) 66 70 { … … 78 82 break; 79 83 } 84 if (!isalnum(genformat)) genformat=INVALID_FORMAT; 80 85 if (genformat == INVALID_FORMAT) 81 86 { … … 88 93 cut = genstring.substr(0, error_end); 89 94 int lf = cut.indexOf('\n'); 90 if (lf >= 0) cut = cut.substr(0, lf); 91 logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), genname.len() ? SString::sprintf(" in '%s'", genname.c_str()).c_str() : ""); 95 if (lf >= 0) { if ((lf>0)&&(cut[lf-1]=='\r')) lf--; cut = cut.substr(0, lf); } 96 sstringQuote(cut); 97 logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), name.len() ? SString::sprintf(" in '%s'", name.c_str()).c_str() : ""); 92 98 } 93 99 94 100 } 95 101 } 96 97 102 gen = gencopy; 103 multiline = (strchr(gen.c_str(), '\n') != 0); 98 104 format = genformat; 99 name = genname; 100 txt = comment; 101 multiline = (strchr(gen.c_str(), '\n') != 0); 105 freeF0(); 106 isvalid = -1; 102 107 // mapoutshift...? 103 108 } … … 146 151 } 147 152 148 void Geno::setGene (const SString& g, char newformat)153 void Geno::setGeneOnly(const SString& g) 149 154 { 150 155 gen = g; 151 156 isvalid = -1; 152 157 freeF0(); 153 if (newformat >= 0) format = newformat;154 158 } 155 159 … … 170 174 } 171 175 172 SString Geno::toString(void) const 173 { 174 SString out; 175 int comment = 0; 176 if ((format != '1') || (comment = (txt.len() || name.len()))) 177 { 178 if (multiline) 179 out += "//"; 180 else 181 out += "/*"; 182 out += format; 183 if (comment) 184 { 185 if (txt.len()) { out += ";"; out += txt; } 186 if (name.len()){ out += ";"; out += name; } 187 } 188 if (multiline) 189 out += "\n"; 190 else 191 out += "*/"; 192 } 193 out += gen; 194 return out; 195 } 196 197 SString Geno::shortString(void) const 176 SString Geno::getGeneAndFormat(void) const 198 177 { 199 178 SString out; -
cpp/frams/genetics/geno.h
r522 r530 55 55 56 56 public: 57 static const intINVALID_FORMAT = '!';57 static const char INVALID_FORMAT = '!'; 58 58 typedef SListTempl<GenoValidator*> Validators; 59 59 … … 85 85 86 86 /// return string representation, with format comment at the beginning 87 SString toString(void) const; 88 SString shortString(void) const; 87 SString getGeneAndFormat(void) const; 89 88 90 89 void setString(const SString& genewithcomments); 91 90 92 /** @param newformat=-1 -> don't change */ 93 void setGene(const SString& g, char newformat = -1); 91 /** @param genformat=-1 -> take from genstring comment (like the constructor) else specify the valid format in genformat and pure gene in genstring */ 92 void setGeneAndFormat(const SString& genstring, char genformat=-1); 93 /** g must be pure gene, without format. for the standard behavior use setGeneAndFormat() */ 94 void setGeneOnly(const SString& g); 94 95 SString getGene(void) const; 95 96
Note: See TracChangeset
for help on using the changeset viewer.