casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ComplexWrapper.h
Go to the documentation of this file.
1 /*
2  * ALMA - Atacama Large Millimeter Array
3  * (c) European Southern Observatory, 2002
4  * (c) Associated Universities Inc., 2002
5  * Copyright by ESO (in the framework of the ALMA collaboration),
6  * Copyright by AUI (in the framework of the ALMA collaboration),
7  * All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY, without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  *
24  * File Complex.h
25  */
26 
27 #ifndef Complex_CLASS
28 #define Complex_CLASS
29 
30 #include <vector>
31 #include <complex>
32 #include <iostream>
33 #include <string>
34 
35 #ifndef WITHOUT_ACS
36 #include <asdmIDLTypesC.h>
37 #endif
38 
42 
43 #include <alma/ASDM/EndianStream.h>
44 
45 namespace asdm {
46 
56 class Complex : public std::complex<double> {
57 
58 public:
59  static Complex fromString(const std::string&) throw(NumberFormatException);
60  static std::string toString(const Complex&);
62 
63  Complex(); // default constructor
64  Complex(const Complex &); // X const X& constructor
65  Complex(const std::string &s);
66 #ifndef WITHOUT_ACS
67  Complex(const asdmIDLTypes::IDLComplex &);
68 #endif
69  Complex(double re, double im);
70 
71  double getReal() const;
72  double getImg() const;
73  void setReal(double re);
74  void setImg(double im);
75 
76  bool isZero() const;
77  bool equals(const Complex &) const;
78 
79  std::string toString() const;
80 #ifndef WITHOUT_ACS
81  asdmIDLTypes::IDLComplex toIDLComplex() const;
82 #endif
83 
87  void toBin(EndianOSStream& eoss);
88 
94  static void toBin(const std::vector<Complex>& cmplx, EndianOSStream& eoss);
95 
101  static void toBin(const std::vector<std::vector<Complex> >& cmplx, EndianOSStream& eoss);
102 
108  static void toBin(const std::vector<std::vector<std::vector<Complex> > >& cmplx, EndianOSStream& eoss);
109 
116  static Complex fromBin(EndianIStream& eis);
117 
124  static std::vector<Complex> from1DBin(EndianIStream & eis);
125 
132  static std::vector<std::vector<Complex> > from2DBin(EndianIStream & eis);
133 
140  static std::vector<std::vector<std::vector<Complex> > > from3DBin(EndianIStream & eis);
141 
142 };
143 
144 // Complex constructors
145 inline Complex::Complex() : std::complex<double>(0.0,0.0) {
146 }
147 
148 inline Complex::Complex(const Complex &t) : std::complex<double>(t.real(),t.imag()) {
149 }
150 
151 inline Complex::Complex(const std::string &s) : std::complex<double>(Complex::fromString(s)) {
152 }
153 
154 #ifndef WITHOUT_ACS
155 inline Complex::Complex(const asdmIDLTypes::IDLComplex &l) : std::complex<double>(l.re,l.im) {
156 }
157 #endif
158 
159 inline Complex::Complex(double r, double i) : std::complex<double>(r,i) {
160 }
161 
162 inline double Complex::getReal() const {
163  return real();
164 }
165 
166 inline double Complex::getImg() const {
167  return imag();
168 }
169 
170 inline void Complex::setReal(double re) {
171  *this = Complex(re,imag());
172 }
173 
174 inline void Complex::setImg(double im) {
175  *this = Complex(real(),im);
176 }
177 
178 inline bool Complex::isZero() const {
179  return real() == 0.0 && imag() == 0.0;
180 }
181 
182 inline bool Complex::equals(const Complex &x) const {
183  return real() == x.real() && imag() == x.imag();
184 }
185 
186 #ifndef WITHOUT_ACS
187 inline asdmIDLTypes::IDLComplex Complex::toIDLComplex() const {
188  asdmIDLTypes::IDLComplex x;
189  x.re = getReal();
190  x.im = getImg();
191  return x;
192 }
193 #endif
194 
195 inline std::string Complex::toString() const {
196  return Double::toString(getReal()) + " " + Double::toString(getImg());
197 }
198 
199 } // End namespace asdm
200 
201 #endif /* Complex_CLASS */
void setImg(double im)
LatticeExprNode imag(const LatticeExprNode &expr)
static Complex fromString(const std::string &)
double getImg() const
The StringTokenizer class is a translation into C++ of the Java class of the same name in Java&#39;s util...
bool isZero() const
static std::vector< std::vector< Complex > > from2DBin(EndianIStream &eis)
Read the binary representation of a vector of vector of Complex from an EndianIStream and use the rea...
asdmIDLTypes::IDLComplex toIDLComplex() const
The NumberFormatException class represents an exception when an error occurs in converting a numeric ...
The Complex class extends the Complex class in the C++ standard library.
void toBin(EndianOSStream &eoss)
Write the binary representation of this to a EndianOSStream.
static std::string toString(double d)
Encode a double value into its string representation.
static Complex getComplex(StringTokenizer &t)
Complex()
Complex constructors.
static std::vector< Complex > from1DBin(EndianIStream &eis)
Read the binary representation of a vector of Complex from an EndianIStream and use the read value to...
bool equals(const Complex &) const
double getReal() const
std::string toString() const
static Complex fromBin(EndianIStream &eis)
Read the binary representation of an Complex from a EndianIStream and use the read value to set an Co...
void setReal(double re)
static std::vector< std::vector< std::vector< Complex > > > from3DBin(EndianIStream &eis)
Read the binary representation of a vector of vector of vector of Complex from an EndianIStream and u...
LatticeExprNode real(const LatticeExprNode &expr)