Tulip  5.2.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 template <typename T, size_t N>
21 std::ostream &tlp::operator<<(std::ostream &os, const tlp::Array<T, N> &a) {
22  os << "(";
23 
24  for (unsigned int i = 0; i < N; ++i) {
25  if (i > 0)
26  os << ",";
27 
28  os << a[i];
29  }
30 
31  os << ")";
32  return os;
33 }
34 
35 template <typename T, size_t N>
36 std::istream &tlp::operator>>(std::istream &is, tlp::Array<T, N> &outA) {
37  char c;
38  int pos = is.tellg();
39  is.clear();
40 
41  // skip spaces
42  while (bool(is >> c) && isspace(c)) {
43  }
44 
45  if (c != '(') {
46  is.seekg(pos);
47  is.setstate(std::ios::failbit);
48  return is;
49  }
50 
51  for (unsigned int i = 0; i < N; ++i) {
52  bool ok;
53 
54  if (i > 0) {
55  // skip spaces
56  while ((ok = bool(is >> c)) && isspace(c)) {
57  }
58 
59  if (!ok || c != ',') {
60  is.seekg(pos);
61  is.setstate(std::ios::failbit);
62  return is;
63  }
64  }
65 
66  // skip spaces
67  while ((ok = bool(is >> c)) && isspace(c)) {
68  }
69 
70  is.unget();
71  bool done = bool(is >> outA[i]);
72 
73  if (!done) {
74  is.seekg(pos);
75  is.setstate(std::ios::failbit);
76  return is;
77  }
78  }
79 
80  // skip spaces
81  while (bool(is >> c) && isspace(c)) {
82  }
83 
84  if (c != ')') {
85  is.seekg(pos);
86  is.setstate(std::ios::failbit);
87  return is;
88  }
89 
90  return is;
91 }
92 //=================================================================
std::istream & operator>>(std::istream &is, Array< T, N > &array)
operator >> stream operator to easily read an array