Complex.cxx

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 #include "Complex.hxx"
00023 
00024 // remove me
00025 #include <iostream>
00026 
00027 namespace CLAM
00028 {
00029 
00030         std::istream& operator >> (std::istream & is, Complex & a)
00031         {
00032                 if (is.flags() & std::ios::skipws) {
00033                         char c = '\0';
00034                         do
00035                                 is.get(c);
00036                         while (is && isspace(c));
00037                         if (is) is.putback(c);
00038                 }
00039                 char c = '\0';
00040                 is >> c;
00041                 if (c!='{') {
00042                         if (is) is.putback(c);
00043         //                      std::cerr << "A complex starting with '" << c << "'" << std::endl;
00044                         return is;
00045                 }
00046                 TData x;
00047                 TData y;
00048                 if (!(is >> x)) return is;
00049                 if (!(is >> y)) return is;
00050                 if (is.flags() & std::ios::skipws) {
00051                         char c = '\0';
00052                         do
00053                                 is.get(c);
00054                         while (is && isspace(c));
00055                         if (is) is.putback(c);
00056                 }
00057                 if (!is.get(c) || c!='i') return is;
00058                 if (is.flags() & std::ios::skipws) {
00059                         char c = '\0';
00060                         do
00061                                 is.get(c);
00062                         while (is && isspace(c));
00063                         if (is) is.putback(c);
00064                 }
00065                 if (!is.get(c) || c!='}') return is;
00066 
00067                 a.SetReal(x);
00068                 a.SetImag(y);
00069                 return is;
00070         }
00071 
00072         std::ostream& operator << (std::ostream & os, const Complex & a)
00073         {
00074                 return os
00075                         << "{"
00076                         << a.Real()
00077                         << " "
00078                         << a.Imag()
00079                         << "i}";
00080         }
00081 
00082 } // namespace CLAM
00083 
Generated by  doxygen 1.6.3