casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LSQTraits.h
Go to the documentation of this file.
00001 //# LSQTraits.h: Typing support classes for LSQ classes
00002 //# Copyright (C) 2004
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: LSQTraits.h 18093 2004-11-30 17:51:10Z ddebonis $
00027 #ifndef SCIMATH_LSQTRAITS_H
00028 #define SCIMATH_LSQTRAITS_H
00029 
00030 //# Includes
00031 #include <casa/aips.h>
00032 #include <complex>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 //# Forward Declarations
00037 
00038 // <summary> Typing support classes for LSQ classes </summary>
00039 // <reviewed reviewer="Wim Brouw" date="2004/04/01" tests="tLSQFit, tLSQaips"
00040 //       demos="">
00041 // </reviewed>
00042 
00043 // <synopsis>
00044 // The following classes are used in detremining the type of iterator
00045 // presented to the LSQFit class. They are for a large part based on ideas by 
00046 // Alexandrescu(2001), 'Modern C++ design'.
00047 // </synopsis>
00048 
00049 // <example>
00050 // See <linkto class="LSQFit">LSQFit</linkto> class, especially the
00051 // <src>LSQFit2.cc</src>
00052 //  defintion file.
00053 // </example>
00054 
00055 // <motivation>
00056 // To ease the interface to Fitting (and probably other) classes, by producing
00057 // a framework that can be used with aips++ containers.
00058 // </motivation>
00059 
00060 // <todo asof="2004/04/01">
00061 //  <li> Add more type info if and when needed
00062 // </todo>
00063 
00064 // Type of real numeric class indicator
00065 class LSQReal {
00066   typedef LSQReal value_type;
00067 };
00068 
00069 // <summary> Type of complex numeric class indicator </summary>
00070 class LSQComplex {
00071   typedef LSQComplex value_type;
00072 };
00073 
00074 // <summary> Non relevant class indicator </summary>
00075 class LSQNull {};
00076 
00077 // <summary> Determine if pointer type </summary>
00078 template <class T>
00079 class LSQType {
00080  private:
00081   template <class U> struct PointerTraits {
00082     enum { result = False };
00083     typedef LSQNull Pointee;
00084   };
00085   template <class U> struct PointerTraits<U*> {
00086     enum { result = True };
00087     typedef U Pointee;
00088   };
00089  public:
00090   enum { isPointer = PointerTraits<T>::result };
00091   typedef typename PointerTraits<T>::Pointee Pointee;
00092 };
00093 
00094 // <summary> Traits for numeric classes used </summary>
00095 template <class T>
00096 class LSQTraits {
00097  public:
00098   // Defining type
00099   typedef T    value_type;
00100   // Numeric base type
00101   typedef Char base;
00102   // Numeric type
00103   typedef Char num_type;
00104   // Number of basic numeric type elements
00105   enum { size = 0 };
00106 };
00107 
00108 #if defined LSQTraits_F
00109 #undef LSQTraits_F
00110 #endif
00111 #define LSQTraits_F LSQTraits
00112 // <summary>LSQTraits specialization for Float</summary>
00113 template <> class LSQTraits_F<Float> {
00114  public:
00115   typedef Float        value_type;
00116   typedef Float        base;
00117   typedef LSQReal      num_type;
00118   enum { size = 1 };
00119 };
00120 #undef LSQTraits_F
00121 
00122 #if defined LSQTraits_D
00123 #undef LSQTraits_D
00124 #endif
00125 #define LSQTraits_D LSQTraits
00126 // <summary>LSQTraits specialization for Double</summary>
00127 template <> class LSQTraits_D<Double> {
00128  public:
00129   typedef Double       value_type;
00130   typedef Double       base;
00131   typedef LSQReal      num_type;
00132   enum { size = 1 };
00133 };
00134 #undef LSQTraits_D
00135 
00136 #if defined LSQTraits_CD
00137 #undef LSQTraits_CD
00138 #endif
00139 #define LSQTraits_CD LSQTraits
00140 // <summary>LSQTraits specialization for DComplex </summary>
00141 template <> class LSQTraits_CD<std::complex<Double> > {
00142  public:
00143   typedef std::complex<Double>    value_type;
00144   typedef Double                  base;
00145   typedef LSQComplex              num_type;
00146   enum { size = 2 };
00147 };
00148 #undef LSQTraits_CD
00149 
00150 #if defined LSQTraits_CF
00151 #undef LSQTraits_CF
00152 #endif
00153 #define LSQTraits_CF LSQTraits
00154 // <summary>LSQTraits specialization for Complex </summary>
00155 template <> class LSQTraits_CF<std::complex<Float> > {
00156  public:
00157   typedef std::complex<Float>    value_type;
00158   typedef Float                  base;
00159   typedef LSQComplex             num_type;
00160   enum { size = 2 };
00161 };
00162 #undef LSQTraits_CF
00163 
00164 
00165 } //# NAMESPACE CASA - END
00166 
00167 #endif