Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

function/complex.hh
Go to the documentation of this file.
00001 /* Complex valued functions
00002  */
00003 
00004 #ifndef complex_hh
00005 #define complex_hh
00006 
00007 #include <complex>
00008 #include "basis.hh"
00009 #include "basics/exceptions.hh"
00010 #include "basics/typedefs.hh"
00011 
00012 namespace concepts {
00013 
00014   // ************************************************************* CmplxPart **
00015 
00022   class CmplxPart : public Function<Real> {
00023   public:
00025     inline CmplxPart(const Function<Cmplx>& fnc) :
00026       Function<Real>(fnc.dim()), cfnc_(&fnc), fnc_(0) {}
00027     inline CmplxPart(Function<Cmplx>& fnc) :
00028       Function<Real>(fnc.dim()), cfnc_(0), fnc_(&fnc) {}
00029 
00031     virtual Function<Real>& operator=(const Function<Real>& fnc) {
00032       throw conceptsException(MissingFeature("not implemented"));
00033       return *this;
00034     }
00035   protected:
00036     virtual std::ostream& info(std::ostream& os) const;
00037     const Function<Cmplx>* cfnc_;
00038     Function<Cmplx>* fnc_;
00039   };
00040 
00041   // ************************************************************** RealPart **
00042   
00047   class RealPart : public CmplxPart {
00048   public:
00050     inline RealPart(const Function<Cmplx>& fnc) : CmplxPart(fnc) {}
00051     inline RealPart(Function<Cmplx>& fnc) : CmplxPart(fnc) {}
00052 
00054     virtual Real& operator()(uint i) {
00055       conceptsAssert(this->fnc_, Assertion());
00056       return *(Real*)&(*this->fnc_)(i);
00057     }
00059     virtual Real operator()(uint i) const { 
00060       if (this->fnc_)
00061         return std::real((*this->fnc_)(i));
00062       return std::real((*this->cfnc_)(i));
00063     }
00064   protected:
00065     virtual std::ostream& info(std::ostream& os) const;
00066   };
00067 
00068   // ************************************************************** ImagPart **
00069 
00074   class ImagPart : public CmplxPart {
00075   public:
00077     inline ImagPart(const Function<Cmplx>& fnc) : CmplxPart(fnc) {}
00078     inline ImagPart(Function<Cmplx>& fnc) : CmplxPart(fnc) {}
00079 
00081     virtual Real& operator()(uint i) {
00082       conceptsAssert(this->fnc_, Assertion());
00083       return *((Real*)&(*this->fnc_)(i)+1);
00084     }
00086     virtual Real operator()(uint i) const { 
00087       if (this->fnc_)
00088         return std::imag((*this->fnc_)(i));
00089       return std::imag((*this->cfnc_)(i));
00090     }
00091   protected:
00092     virtual std::ostream& info(std::ostream& os) const;
00093   };
00094 
00095   // ******************************************************* ComplexFunction **
00096 
00101   class ComplexFunction : public Function<Cmplx> {
00102   public:
00104     inline ComplexFunction(const Function<Real>& fnc) :
00105       Function<Cmplx>(fnc.dim()), cfnc_(fnc) {}
00107     virtual Function<Cmplx>& operator=(const Function<Cmplx>& fnc) {
00108       throw conceptsException(MissingFeature("not assignable"));
00109       return *this;
00110     }
00111 
00113     virtual Cmplx& operator()(uint i) {
00114       throw conceptsException(MissingFeature("not assignable"));
00115       return dummy_;
00116     }
00118     virtual Cmplx operator()(uint i) const { 
00119       return cfnc_(i);
00120     }
00121   protected:
00122     virtual std::ostream& info(std::ostream& os) const;
00123   private:
00124     const Function<Real>& cfnc_;
00125     Cmplx dummy_;
00126   };
00127 
00128 } // namespace concepts
00129 
00130 #endif // complex_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)