00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef FITSUTILT_H
00010 #define FITSUTILT_H
00011
00012 #ifdef _MSC_VER
00013 #include "MSconfig.h"
00014 #endif
00015
00016 #ifdef HAVE_CONFIG_H
00017 #include "config.h"
00018 #endif
00019
00020 #include "FITSUtil.h"
00021
00022 #include<typeinfo>
00023 #include<iostream>
00024
00025 #ifdef SSTREAM_DEFECT
00026 #include <strstream>
00027 #else
00028 #include<sstream>
00029 #endif
00030
00031 namespace CCfits
00032 {
00033
00034 namespace FITSUtil
00035 {
00036
00037
00038
00039 template <typename S, typename T>
00040 void
00041 fill(std::vector<S>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
00042 {
00043
00044 int range = last - first + 1;
00045 if (outArray.size() != static_cast<size_t>(range)) outArray.resize(range);
00046 for (size_t j = first - 1; j < last; ++j)
00047 {
00048 outArray[j - first + 1] = static_cast<S>(inArray[j]);
00049 }
00050 }
00051
00052
00053
00054 template <typename S, typename T>
00055 void fill(std::valarray<S>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
00056 {
00057
00058 int range = last - first + 1;
00059 if (outArray.size() != static_cast<size_t>(range)) outArray.resize(range);
00060 for (size_t j = first - 1; j < last; ++j)
00061 {
00062 outArray[j - first + 1] = static_cast<S>(inArray[j]);
00063 }
00064 }
00065
00066
00067
00068 template <typename S, typename T>
00069 void fill(std::valarray<S>& outArray, const std::valarray<T>& inArray)
00070 {
00071 size_t n = inArray.size();
00072 if (outArray.size() != n) outArray.resize(n);
00073 for (size_t j = 0;j < n; ++j) outArray[j]
00074 = static_cast<S>(inArray[j]);
00075 }
00076
00077 #ifdef TEMPLATE_AMBIG7_DEFECT
00078 template <typename S, typename T>
00079 void fillMSva(std::vector<S>& outArray, const std::valarray<T>& inArray)
00080 {
00081 size_t n = inArray.size();
00082 if (outArray.size() != n) outArray.resize(n);
00083 for (size_t j = 0;j < n; ++j) outArray[j]
00084 = static_cast<S>(inArray[j]);
00085 }
00086
00087 #else
00088 template <typename S, typename T>
00089 void fill(std::vector<S>& outArray, const std::valarray<T>& inArray)
00090 {
00091 size_t n = inArray.size();
00092 if (outArray.size() != n) outArray.resize(n);
00093 for (size_t j = 0;j < n; ++j) outArray[j]
00094 = static_cast<S>(inArray[j]);
00095 }
00096 #endif
00097
00098
00099
00100
00101 template <typename T>
00102 void
00103 fill(std::vector<string>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
00104 {
00105 first = 0;
00106 last = 0;
00107 throw InvalidConversion(errorMessage(outArray,inArray),false);
00108
00109 }
00110
00111 template <typename T>
00112 void fill(std::vector<T>& outArray, const std::vector<string>& inArray, size_t first, size_t last)
00113 {
00114 first = 0;
00115 last = 0;
00116 throw InvalidConversion(errorMessage(outArray,inArray),false);
00117 }
00118
00119
00120
00121
00122 template<typename S, typename T>
00123 string errorMessage( const S& out, const T& in)
00124 {
00125 #ifdef SSTREAM_DEFECT
00126 std::ostrstream errMsg;
00127 #else
00128 std::ostringstream errMsg;
00129 #endif
00130 errMsg << " Error: no conversion from " << typeid(in).name() << " to "
00131 << typeid(out).name() << std::endl;
00132 return errMsg.str();
00133
00134 }
00135
00136 }
00137
00138 }
00139
00140
00141 #endif