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