C++ main module for gpm Package  1.0
CORE_VectorReader.hpp
Go to the documentation of this file.
1 #ifndef CORE_VectorReader_HPP
2 #define CORE_VectorReader_HPP
3 
4 #include "CORE_String.h"
5 
6 template<class T>
7 tBoolean CORE_VectorReader::readVector(tString& current,vector<T>& values) {
8 
9 
10 
11  // length of the string
12  unsigned int lmax=current.length();
13 
14 
15  // find a [, current is set to the chars after [
16  unsigned int indexOB=current.find("[");
17  if (indexOB==0) {
18  current=current.substr(indexOB+1);
19  lmax=current.length();
20  }
21 
22 
23  // find a coma
24  size_t indexC=current.find(",");
25  size_t indexMax=current.find("]");
26  if (indexMax==tString::npos) indexMax=lmax;
27  int i=0;
28  tReal value;
29  while (indexC<indexMax) {//the first exists
30  // read the value at index i
31  CORE_String::parse(current.substr(0,indexC),value);
32  // add it
33  values.push_back(value);
34  // get the next value
35  current=current.substr(indexC+1,lmax-indexC-1);
36  lmax=current.length();
37  indexC=current.find(",");
38  indexMax=current.find("]");
39  if (indexMax==tString::npos) {
40  indexMax=lmax;
41  }
42 
43  i++;
44  }
45 
46 
47  //set the current to chars after ] it it exists
48 
49  tString v=current;
50  if (indexMax<lmax) {
51  // take the string v before ]
52  v=current.substr(0,indexMax);
53  // erase from current all the string before ]
54  current=current.substr(indexMax+1,lmax-indexMax-1);
55  // erase the ,
56  if (current[0]==',') current=current.substr(1);
57  }
58 
59 
60 
61  // parse the last value
62  CORE_String::parse(v,value);
63  values.push_back(value);
64 
65 
66  return true;
67 }
68 
69 #endif
#define tBoolean
Definition: types.h:35
static void parse(const tString &str, unsigned char &c)
parse unsigned char c in str
Definition: CORE_String.h:418
static tBoolean readVector(tString &str, vector< T > &vs)
read vector of string v v=[x,y,z,t] or x,y,z,t
Definition: CORE_VectorReader.hpp:7
#define tString
Definition: types.h:36
#define tReal
Definition: types.h:18