Tulip  5.1.0
Large graphs analysis and drawing
Array.cxx
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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(bool(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 = bool(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 = bool(is >> c)) && isspace(c)) {}
88 
89  is.unget();
90  bool done = bool(is >> outA.array[i]);
91 
92  if( !done ) {
93  is.seekg(pos);
94  is.setstate(std::ios::failbit);
95  return is;
96  }
97  }
98 
99  // skip spaces
100  while(bool(is >> c) && isspace(c)) {}
101 
102  if (c!=')' ) {
103  is.seekg(pos);
104  is.setstate(std::ios::failbit);
105  return is;
106  }
107 
108  return is;
109 }
110 //=================================================================
Obj array[SIZE]
array The underlying array of data.
Definition: Array.h:41
std::istream & operator>>(std::istream &is, Array< Obj, SIZE > &array)
operator >> stream operator to easily read an array
Definition: Array.cxx:58
Obj operator[](const unsigned int i) const
operator [] Read-only accessor.
Definition: Array.cxx:22
Fixed-size array encapsulation.In debug mode, a bound check is performed at each access. Stream operators implementations are provided.
Definition: Array.h:37