Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/cxx/Array.cxx
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 //=================================================================
00021 template <typename Obj,unsigned int SIZE>
00022 Obj tlp::Array<Obj,SIZE>::operator[](const unsigned int i) const {
00023   assert(i<SIZE);
00024   return array[i];
00025 }
00026 //=================================================================
00027 template <typename Obj,unsigned int SIZE>
00028 Obj& tlp::Array<Obj,SIZE>::operator[](const unsigned int i) {
00029   assert(i<SIZE);
00030   return array[i];
00031 }
00032 //=================================================================
00033 template <typename Obj,unsigned int SIZE>
00034 std::ostream& tlp::operator<<(std::ostream &os,const tlp::Array<Obj,SIZE> &a) {
00035   os << "(" ;
00036 
00037   for ( unsigned int i=0 ; i<SIZE ; ++i ) {
00038     if( i>0 )
00039       os << ",";
00040 
00041     os << a[i];
00042   }
00043 
00044   os << ")" ;
00045   return os;
00046 }
00047 //#include <sstream>
00048 //=================================================================
00049 //template <typename Obj,unsigned int SIZE>
00050 //QDebug operator<<(QDebug dbg,const tlp::Array<Obj,SIZE>& s) {
00051 //  std::stringstream ss;
00052 //  ss << s;
00053 //  dbg.nospace() << ss.str().c_str();
00054 //  return dbg.space();
00055 //}
00056 
00057 template <typename Obj,unsigned int SIZE>
00058 std::istream & tlp::operator>> (std::istream &is, tlp::Array<Obj,SIZE> & outA) {
00059   char c;
00060   int pos = is.tellg();
00061   is.clear();
00062 
00063   // skip spaces
00064   while(bool(is >> c) && isspace(c)) {}
00065 
00066   if(c!='(') {
00067     is.seekg(pos);
00068     is.setstate(std::ios::failbit);
00069     return is;
00070   }
00071 
00072   for(unsigned int i=0; i<SIZE; ++i) {
00073     bool ok;
00074 
00075     if (i>0 ) {
00076       // skip spaces
00077       while((ok = bool(is >> c)) && isspace(c)) {}
00078 
00079       if (!ok || c!=',') {
00080         is.seekg(pos);
00081         is.setstate(std::ios::failbit);
00082         return is;
00083       }
00084     }
00085 
00086     // skip spaces
00087     while((ok = bool(is >> c)) && isspace(c)) {}
00088 
00089     is.unget();
00090     bool done = bool(is >> outA.array[i]);
00091 
00092     if( !done ) {
00093       is.seekg(pos);
00094       is.setstate(std::ios::failbit);
00095       return is;
00096     }
00097   }
00098 
00099   // skip spaces
00100   while(bool(is >> c) && isspace(c)) {}
00101 
00102   if (c!=')' ) {
00103     is.seekg(pos);
00104     is.setstate(std::ios::failbit);
00105     return is;
00106   }
00107 
00108   return is;
00109 }
00110 //=================================================================
 All Classes Files Functions Variables Enumerations Enumerator Properties