Changeset 2286 in Sophya


Ignore:
Timestamp:
Dec 5, 2002, 12:15:55 PM (23 years ago)
Author:
ansari
Message:

Correction lecture tableaux en ASCII - Reza 5/12/02

Location:
trunk/SophyaLib/TArray
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/basarr.h

    r2267 r2286  
    154154  // Lecture,Ecriture sur fichier ASCII
    155155  //! 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;
    157158  //! Writes an array to an ASCII stream
    158159  virtual void   WriteASCII(ostream& os) const = 0;
  • trunk/SophyaLib/TArray/tarray.cc

    r2267 r2286  
    10891089  \param nr : Number of non empty (or comment) lines in stream (return value)
    10901090  \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
    10911093  \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*/
     1095template <class T>
     1096sa_size_t TArray<T>::ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc,
     1097                               char clm, const char* sep)
    10951098{
    10961099  EnumeratedSequence es;
    1097   sa_size_t n = es.FillFromFile(is, nr, nc);
     1100  sa_size_t n = es.FillFromFile(is, nr, nc, clm, sep);
    10981101  if ( (n < 1) || (nr < 1) || (nc < 1) ) return(n);
    10991102  if (!IsAllocated()) {
  • trunk/SophyaLib/TArray/tarray.h

    r1891 r2286  
    175175
    176176// 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");
    178179  virtual void   WriteASCII(ostream& os) const;
    179180
  • trunk/SophyaLib/TArray/utilarr.cc

    r2149 r2286  
    195195/*!
    196196  \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.
    198199  \return the number of added elements.
    199200*/
    200 sa_size_t EnumeratedSequence::Append(string const & str, int& nbad)
     201sa_size_t EnumeratedSequence::Append(string const & str, int& nbad, const char* sep)
    201202{
    202203  nbad = 0;
     
    204205  size_t l = str.length();
    205206  if (l < 1) return(0);
    206   if ((str[0] == '#') || (str[0] == '*')) return(0);
     207  //  if ((str[0] == '#') || (str[0] == '*')) return(0);
    207208  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);
    209212  if ((str[p] == '+') || (str[p] == '-')) {
    210213    if (p == l-1)  return(0);
     
    212215  }
    213216  else if (!isdigit(str[p]) && (str[p] != '\'') && (str[p] != '(') ) return(0);
    214 
     217  */
    215218  while(q < l) {
    216     p = str.find_first_not_of(" \t",q);
     219    p = str.find_first_not_of(sep,q);
    217220    if (p >= l)  break;
    218221    if (str[p] == '\'')    {  // Decodage d'un string
     
    236239    }
    237240    else {
    238       q = str.find_first_of(" \t",p);
     241      q = str.find_first_of(sep,p);
    239242      if (!isdigit(str[p]) && !(str[p] == '+') && !(str[p] == '-') ) { // une chaine
    240         continue;
     243        vecv_.push_back(MuTyV(str.substr(p,q-p)));
    241244      }
    242245      else {  // C'est un nombre
     
    260263    \param nr : Number of non empty (or comment) lines in stream (return value)
    261264    \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
    262267    \return Number of decoded elements
    263268*/
    264 sa_size_t EnumeratedSequence::FillFromFile(istream& is,
    265                                            sa_size_t& nr, sa_size_t& nc)
     269sa_size_t EnumeratedSequence::FillFromFile(istream& is, sa_size_t& nr, sa_size_t& nc,
     270                                           char clm, const char* sep)
    266271{
    267272  nr = 0;
     
    278283    line += buff;
    279284    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;
    286293      line = "";
    287294    }
    288295  }
    289   if (line.length() > 0) {
     296  if ((line.length() > 0) && (line[0]!=clm)) {
    290297    nel = Append(line, nbad);
    291     //    cout << " Decoding Eline = " << line << " Nel= " << nel << endl;
     298        cout << " Decoding Eline = " << line << " Nel= " << nel << endl;
    292299    if (nel > 0)  {
    293300      nr++;  n += nel;
  • trunk/SophyaLib/TArray/utilarr.h

    r1558 r2286  
    109109
    110110  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");
    113114
    114115private:
Note: See TracChangeset for help on using the changeset viewer.