C++ main module for emicrom 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  tUIndex lmax=current.length();
13 
14 
15  // find a [, current is set to the chars after [
16  tUIndex indexOB=current.find("[");
17  if (indexOB!=tString::npos) {
18  current=current.substr(indexOB+1);
19  lmax=current.length();
20  }
21 
22 
23  // find a coma
24  tUIndex indexC=current.find(",");
25  tUIndex indexMax=current.find("]");
26  if (indexMax==tString::npos) indexMax=lmax;
27  tUIndex i=0;
28  T 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 template<class T>
71  //read the vector
72  vector<T> vs;
73  tBoolean succeeds=readVector(current,vs);
74 
75 
76  //turn it into an array
77  if (succeeds) values.setValues(vs);
78  return succeeds;
79 
80 }
81 
82 #endif
static void parse(const tString &str, tUChar &c)
parse unsigned char c in str
Definition: CORE_String.h:504
#define tBoolean
Definition: types.h:139
static tBoolean readVector(tString &str, vector< T > &vs)
read vector of string str v=[x,y,z,t] or x,y,z,t
Definition: CORE_VectorReader.hpp:7
this class describes an array
Definition: CORE_Array.h:19
void setValues(const tUIndex &n, const Q *v)
set the values of the array by copying the n first values of pointer v
Definition: CORE_Array.h:445
#define tUIndex
Definition: types.h:126
#define tString
Definition: types.h:135