Changeset 2286 in Sophya
- Timestamp:
- Dec 5, 2002, 12:15:55 PM (23 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/basarr.h
r2267 r2286 154 154 // Lecture,Ecriture sur fichier ASCII 155 155 //! Reads an array from an ASCII stream 156 virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc) = 0; 156 virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc, 157 char clm='#', const char* sep=" \t") = 0; 157 158 //! Writes an array to an ASCII stream 158 159 virtual void WriteASCII(ostream& os) const = 0; -
trunk/SophyaLib/TArray/tarray.cc
r2267 r2286 1089 1089 \param nr : Number of non empty (or comment) lines in stream (return value) 1090 1090 \param nc : Number of columns (= ntot/nlines) (return value) 1091 \param clm : Lines starting with clm character are treated as comment lines 1092 \param sep : word separator in lines 1091 1093 \return Number of decoded elements 1092 */ 1093 template <class T> 1094 sa_size_t TArray<T>::ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc) 1094 */ 1095 template <class T> 1096 sa_size_t TArray<T>::ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc, 1097 char clm, const char* sep) 1095 1098 { 1096 1099 EnumeratedSequence es; 1097 sa_size_t n = es.FillFromFile(is, nr, nc );1100 sa_size_t n = es.FillFromFile(is, nr, nc, clm, sep); 1098 1101 if ( (n < 1) || (nr < 1) || (nc < 1) ) return(n); 1099 1102 if (!IsAllocated()) { -
trunk/SophyaLib/TArray/tarray.h
r1891 r2286 175 175 176 176 // Lecture,Ecriture sur fichier ASCII 177 virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc); 177 virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc, 178 char clm='#', const char* sep=" \t"); 178 179 virtual void WriteASCII(ostream& os) const; 179 180 -
trunk/SophyaLib/TArray/utilarr.cc
r2149 r2286 195 195 /*! 196 196 \param str : string to be decoded 197 \param nbad : number of unmatched quotes or parenthesis 197 \param nbad : number of unmatched quotes or parenthesis (returned value) 198 \param sep : word separator in string. Each word is decoded as a MuTyV value. 198 199 \return the number of added elements. 199 200 */ 200 sa_size_t EnumeratedSequence::Append(string const & str, int& nbad )201 sa_size_t EnumeratedSequence::Append(string const & str, int& nbad, const char* sep) 201 202 { 202 203 nbad = 0; … … 204 205 size_t l = str.length(); 205 206 if (l < 1) return(0); 206 if ((str[0] == '#') || (str[0] == '*')) return(0);207 // if ((str[0] == '#') || (str[0] == '*')) return(0); 207 208 size_t q = 0; 208 size_t p = str.find_first_not_of(" \t"); 209 size_t p = 0; 210 /* 211 size_t p = str.find_first_not_of(sep); 209 212 if ((str[p] == '+') || (str[p] == '-')) { 210 213 if (p == l-1) return(0); … … 212 215 } 213 216 else if (!isdigit(str[p]) && (str[p] != '\'') && (str[p] != '(') ) return(0); 214 217 */ 215 218 while(q < l) { 216 p = str.find_first_not_of( " \t",q);219 p = str.find_first_not_of(sep,q); 217 220 if (p >= l) break; 218 221 if (str[p] == '\'') { // Decodage d'un string … … 236 239 } 237 240 else { 238 q = str.find_first_of( " \t",p);241 q = str.find_first_of(sep,p); 239 242 if (!isdigit(str[p]) && !(str[p] == '+') && !(str[p] == '-') ) { // une chaine 240 continue;243 vecv_.push_back(MuTyV(str.substr(p,q-p))); 241 244 } 242 245 else { // C'est un nombre … … 260 263 \param nr : Number of non empty (or comment) lines in stream (return value) 261 264 \param nc : Number of columns (= ntot/nlines) (return value) 265 \param clm : Lines starting with clm character are treated as comment lines 266 \param sep : word separator in lines 262 267 \return Number of decoded elements 263 268 */ 264 sa_size_t EnumeratedSequence::FillFromFile(istream& is, 265 sa_size_t& nr, sa_size_t& nc)269 sa_size_t EnumeratedSequence::FillFromFile(istream& is, sa_size_t& nr, sa_size_t& nc, 270 char clm, const char* sep) 266 271 { 267 272 nr = 0; … … 278 283 line += buff; 279 284 if (is.good()) { 280 nel = Append(line, nbad); 281 // cout << " Decoding line = " << line << " Nel= " << nel << endl; 282 if (nel > 0) { 283 nr++; n += nel; 284 } 285 nbadtot += nbad; 285 if ((line.length() > 0) && (line[0]!=clm)) { 286 nel = Append(line, nbad); 287 if (nel > 0) { 288 nr++; n += nel; 289 } 290 nbadtot += nbad; 291 } 292 cout << " Decoding line = " << line << " Nel= " << nel << endl; 286 293 line = ""; 287 294 } 288 295 } 289 if ( line.length() > 0) {296 if ((line.length() > 0) && (line[0]!=clm)) { 290 297 nel = Append(line, nbad); 291 //cout << " Decoding Eline = " << line << " Nel= " << nel << endl;298 cout << " Decoding Eline = " << line << " Nel= " << nel << endl; 292 299 if (nel > 0) { 293 300 nr++; n += nel; -
trunk/SophyaLib/TArray/utilarr.h
r1558 r2286 109 109 110 110 sa_size_t Append(EnumeratedSequence const & seq); 111 sa_size_t Append(string const & str, int & nbad); 112 sa_size_t FillFromFile(istream& is, sa_size_t& nr, sa_size_t& nc); 111 sa_size_t Append(string const & str, int & nbad, const char* sep=" \t"); 112 sa_size_t FillFromFile(istream& is, sa_size_t& nr, sa_size_t& nc, 113 char clm='#', const char* sep=" \t"); 113 114 114 115 private:
Note:
See TracChangeset
for help on using the changeset viewer.