// Astrophysics Science Division, // NASA/ Goddard Space Flight Center // HEASARC // http://heasarc.gsfc.nasa.gov // e-mail: ccfits@legacy.gsfc.nasa.gov // // Original author: Ben Dorman #ifndef FITSUTILT_H #define FITSUTILT_H #ifdef _MSC_VER #include "MSconfig.h" // for truncation warning #endif #include "FITSUtil.h" #include #include #ifdef SSTREAM_DEFECT #include #else #include #endif namespace CCfits { namespace FITSUtil { // vector to vector conversion. template void fill(std::vector& outArray, const std::vector& inArray, size_t first, size_t last) { // vector to vector assign. stdlib takes care of deletion. int range = last - first + 1; if (outArray.size() != static_cast(range)) outArray.resize(range); for (size_t j = first - 1; j < last; ++j) { outArray[j - first + 1] = static_cast(inArray[j]); } } // vector to valarray conversion. template void fill(std::valarray& outArray, const std::vector& inArray, size_t first, size_t last) { // vector to valarray assign int range = last - first + 1; if (outArray.size() != static_cast(range)) outArray.resize(range); for (size_t j = first - 1; j < last; ++j) { outArray[j - first + 1] = static_cast(inArray[j]); } } // valarray to valarray conversion. template void fill(std::valarray& outArray, const std::valarray& inArray) { size_t n = inArray.size(); if (outArray.size() != n) outArray.resize(n); for (size_t j = 0;j < n; ++j) outArray[j] = static_cast(inArray[j]); } #ifdef TEMPLATE_AMBIG7_DEFECT template void fillMSva(std::vector& outArray, const std::valarray& inArray) { size_t n = inArray.size(); if (outArray.size() != n) outArray.resize(n); for (size_t j = 0;j < n; ++j) outArray[j] = static_cast(inArray[j]); } #else template void fill(std::vector& outArray, const std::valarray& inArray) { size_t n = inArray.size(); if (outArray.size() != n) outArray.resize(n); for (size_t j = 0;j < n; ++j) outArray[j] = static_cast(inArray[j]); } #endif // throw exceptions for string conversions to anything other than string. template void fill(std::vector& outArray, const std::vector& inArray, size_t first, size_t last) { first = 0; last = 0; throw InvalidConversion(errorMessage(outArray,inArray),false); } template void fill(std::vector& outArray, const std::vector& inArray, size_t first, size_t last) { first = 0; last = 0; throw InvalidConversion(errorMessage(outArray,inArray),false); } template string errorMessage( const S& out, const T& in) { #ifdef SSTREAM_DEFECT std::ostrstream errMsg; #else std::ostringstream errMsg; #endif errMsg << " Error: no conversion from " << typeid(in).name() << " to " << typeid(out).name() << std::endl; return errMsg.str(); } } } // namespace CCfits #endif