PointTmplDef.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifndef _PointTmplDef_
00024 #define _PointTmplDef_
00025 
00026 #include <string>
00027 #include <iostream>
00028 #include <sstream>
00029 
00030 namespace CLAM
00031 {
00032 
00037         template <class TX,class TY>
00038         inline std::istream& operator >> (std::istream & is,
00039                         PointTmpl<TX,TY> & a)
00040         {
00041                 if (is.flags() & std::ios::skipws) {
00042                         char c = '\0';
00043                         do
00044                                 is.get(c);
00045                         while (is && isspace(c));
00046                         if (is) is.putback(c);
00047                 }
00048                 char c = '\0';
00049                 is >> c;
00050                 if (c!='{') {
00051                         if (is) is.putback(c);
00052 //                      std::cerr << "A point starting with '" << c << "'" << std::endl;
00053                         return is;
00054                 }
00055                 TX x; 
00056                 TY y;
00057                 if (!(is >> x)) return is;
00058                 if (!(is >> y)) return is;
00059                 if (is.flags() & std::ios::skipws) {
00060                         char c = '\0';
00061                         do
00062                                 is.get(c);
00063                         while (is && isspace(c));
00064                         if (is) is.putback(c);
00065                 }
00066                 if (!is.get(c) || c!='}') return is;
00067 
00068                 a.SetX(x);
00069                 a.SetY(y);
00070                 return is;
00071         }
00072 
00073         template <class TX,class TY>
00074         std::ostream& operator << (std::ostream& myStream, const PointTmpl<TX,TY>& a)
00075         {
00076                 return myStream 
00077                         << "{"
00078                         << a.GetX()
00079                         << " "
00080                         << a.GetY()
00081                         << "}";
00082         }
00083 
00084 } // namespace CLAM
00085 
00086 
00087 #endif // _PointTmplDef_
00088 
Generated by  doxygen 1.6.3