00001 //# ConvertScalar.h: Templated functions to convert scalars 00002 //# Copyright (C) 2000,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef CASA_CONVERTSCALAR_H 00029 #define CASA_CONVERTSCALAR_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/BasicSL/Complex.h> 00034 00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00036 00037 // <summary> 00038 // Templated functions to convert scalars from one type to another. 00039 // </summary> 00040 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00041 // </reviewed> 00042 00043 // <synopsis> 00044 // Templated functions to convert scalars from one type to another. 00045 // They are useful to be able to convert a DComplex to a Complex 00046 // in templated classes. 00047 // A Complex,DComplex specialisation is necessary because the complex 00048 // class in the standard C++ library does not have such an automatic 00049 // conversion. 00050 // </synopsis> 00051 00052 // <group name="Scalar conversion"> 00053 template<class T, class F> inline void convertScalar (T& out, F in) 00054 { out = static_cast<T>(in); } 00055 inline void convertScalar (Complex& out, DComplex in) 00056 { out = Complex(in.real(), in.imag()); } 00057 // </group> 00058 00059 00060 } //# NAMESPACE CASACORE - END 00061 00062 #endif