CLAM-Development  1.4.0
ComplexTmplDef.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 #ifndef _ComplexTmplDef_
24 #define _ComplexTmplDef_
25 
26 // remove me
27 #include <iostream>
28 
29 namespace CLAM
30 {
31 
32  template <class T>
33  inline std::istream& operator >> (std::istream & is, ComplexTmpl<T> & a)
34  {
35  if (is.flags() & std::ios::skipws) {
36  char c = '\0';
37  do
38  is.get(c);
39  while (is && isspace(c));
40  if (is) is.putback(c);
41  }
42  char c = '\0';
43  is >> c;
44  if (c!='{') {
45  if (is) is.putback(c);
46  // std::cerr << "A complex starting with '" << c << "'" << std::endl;
47  return is;
48  }
49  T x;
50  T y;
51  if (!(is >> x)) return is;
52  if (!(is >> y)) return is;
53  if (is.flags() & std::ios::skipws) {
54  char c = '\0';
55  do
56  is.get(c);
57  while (is && isspace(c));
58  if (is) is.putback(c);
59  }
60  if (!is.get(c) || c!='i') return is;
61  if (is.flags() & std::ios::skipws) {
62  char c = '\0';
63  do
64  is.get(c);
65  while (is && isspace(c));
66  if (is) is.putback(c);
67  }
68  if (!is.get(c) || c!='}') return is;
69 
70  a.SetReal(x);
71  a.SetImag(y);
72  return is;
73  }
74 
75  template <class T>
76  inline std::ostream& operator << (std::ostream & os, const ComplexTmpl<T> & a)
77  {
78  return os
79  << "{"
80  << a.Real()
81  << " "
82  << a.Imag()
83  << "i}";
84  }
85 
86 } // namespace CLAM
87 
88 
89 #endif // _ComplexTmplDef_
90