ComplexWrapper.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef Complex_CLASS
00028 #define Complex_CLASS
00029
00030 #include <vector>
00031 #include <complex>
00032 #include <iostream>
00033 #include <string>
00034 using namespace std;
00035 using std::complex;
00036
00037 #ifndef WITHOUT_ACS
00038 #include <asdmIDLTypesC.h>
00039 using asdmIDLTypes::IDLComplex;
00040 #endif
00041
00042 #include <DoubleWrapper.h>
00043 #include <StringTokenizer.h>
00044 #include <NumberFormatException.h>
00045 using asdm::Double;
00046 using asdm::StringTokenizer;
00047 using asdm::NumberFormatException;
00048
00049 #include "EndianStream.h"
00050 using asdm::EndianOSStream;
00051 using asdm::EndianIStream;
00052
00053 namespace asdm {
00054
00064 class Complex : public std::complex<double> {
00065
00066 public:
00067 static Complex fromString(const string&) throw(NumberFormatException);
00068 static string toString(const Complex&);
00069 static Complex getComplex(StringTokenizer &t) throw(NumberFormatException);
00070
00071 Complex();
00072 Complex(const Complex &);
00073 Complex(const string &s);
00074 #ifndef WITHOUT_ACS
00075 Complex(const IDLComplex &);
00076 #endif
00077 Complex(double re, double im);
00078
00079 double getReal() const;
00080 double getImg() const;
00081 void setReal(double re);
00082 void setImg(double im);
00083
00084 bool isZero() const;
00085 bool equals(const Complex &) const;
00086
00087 string toString() const;
00088 #ifndef WITHOUT_ACS
00089 IDLComplex toIDLComplex() const;
00090 #endif
00091
00095 void toBin(EndianOSStream& eoss);
00096
00102 static void toBin(const vector<Complex>& cmplx, EndianOSStream& eoss);
00103
00109 static void toBin(const vector<vector<Complex> >& cmplx, EndianOSStream& eoss);
00110
00116 static void toBin(const vector<vector<vector<Complex> > >& cmplx, EndianOSStream& eoss);
00117
00124 static Complex fromBin(EndianIStream& eis);
00125
00132 static vector<Complex> from1DBin(EndianIStream & eis);
00133
00140 static vector<vector<Complex> > from2DBin(EndianIStream & eis);
00141
00148 static vector<vector<vector<Complex> > > from3DBin(EndianIStream & eis);
00149
00150 };
00151
00152
00153 inline Complex::Complex() : std::complex<double>(0.0,0.0) {
00154 }
00155
00156 inline Complex::Complex(const Complex &t) : std::complex<double>(t.real(),t.imag()) {
00157 }
00158
00159 inline Complex::Complex(const string &s) : std::complex<double>(Complex::fromString(s)) {
00160 }
00161
00162 #ifndef WITHOUT_ACS
00163 inline Complex::Complex(const IDLComplex &l) : std::complex<double>(l.re,l.im) {
00164 }
00165 #endif
00166
00167 inline Complex::Complex(double r, double i) : std::complex<double>(r,i) {
00168 }
00169
00170 inline double Complex::getReal() const {
00171 return real();
00172 }
00173
00174 inline double Complex::getImg() const {
00175 return imag();
00176 }
00177
00178 inline void Complex::setReal(double re) {
00179 *this = Complex(re,imag());
00180 }
00181
00182 inline void Complex::setImg(double im) {
00183 *this = Complex(real(),im);
00184 }
00185
00186 inline bool Complex::isZero() const {
00187 return real() == 0.0 && imag() == 0.0;
00188 }
00189
00190 inline bool Complex::equals(const Complex &x) const {
00191 return real() == x.real() && imag() == x.imag();
00192 }
00193
00194 #ifndef WITHOUT_ACS
00195 inline IDLComplex Complex::toIDLComplex() const {
00196 IDLComplex x;
00197 x.re = getReal();
00198 x.im = getImg();
00199 return x;
00200 }
00201 #endif
00202
00203 inline string Complex::toString() const {
00204 return Double::toString(getReal()) + " " + Double::toString(getImg());
00205 }
00206
00207 }
00208
00209 #endif