Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
Array.cxx
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 //=================================================================
21 template <typename Obj,unsigned int SIZE>
22 Obj tlp::Array<Obj,SIZE>::operator[](const unsigned int i) const {
23  assert(i<SIZE);
24  return array[i];
25 }
26 //=================================================================
27 template <typename Obj,unsigned int SIZE>
28 Obj& tlp::Array<Obj,SIZE>::operator[](const unsigned int i) {
29  assert(i<SIZE);
30  return array[i];
31 }
32 //=================================================================
33 template <typename Obj,unsigned int SIZE>
34 std::ostream& tlp::operator<<(std::ostream &os,const tlp::Array<Obj,SIZE> &a) {
35  os << "(" ;
36 
37  for ( unsigned int i=0 ; i<SIZE ; ++i ) {
38  if( i>0 )
39  os << ",";
40 
41  os << a[i];
42  }
43 
44  os << ")" ;
45  return os;
46 }
47 //#include <sstream>
48 //=================================================================
49 //template <typename Obj,unsigned int SIZE>
50 //QDebug operator<<(QDebug dbg,const tlp::Array<Obj,SIZE>& s) {
51 // std::stringstream ss;
52 // ss << s;
53 // dbg.nospace() << ss.str().c_str();
54 // return dbg.space();
55 //}
56 
57 template <typename Obj,unsigned int SIZE>
58 std::istream & tlp::operator>> (std::istream &is, tlp::Array<Obj,SIZE> & outA) {
59  char c;
60  int pos = is.tellg();
61  is.clear();
62 
63  // skip spaces
64  while((is >> c) && isspace(c)) {}
65 
66  if(c!='(') {
67  is.seekg(pos);
68  is.setstate( std::ios::failbit );
69  return is;
70  }
71 
72  for( unsigned int i=0; i<SIZE; ++i ) {
73  bool ok;
74 
75  if (i>0 ) {
76  // skip spaces
77  while((ok = (is >> c)) && isspace(c)) {}
78 
79  if (!ok || c!=',') {
80  is.seekg(pos);
81  is.setstate( std::ios::failbit );
82  return is;
83  }
84  }
85 
86  // skip spaces
87  while((ok = (is >> c)) && isspace(c)) {}
88 
89  is.unget();
90  bool done = true;
91  done = ( is >> outA.array[i] );
92 
93  if( !done ) {
94  is.seekg(pos);
95  is.setstate( std::ios::failbit );
96  return is;
97  }
98  }
99 
100  // skip spaces
101  while((is >> c) && isspace(c)) {}
102 
103  if (c!=')' ) {
104  is.seekg(pos);
105  is.setstate( std::ios::failbit );
106  return is;
107  }
108 
109  return is;
110 }
111 //=================================================================