CCfits  2.6
FITSUtilT.h
1 // Astrophysics Science Division,
2 // NASA/ Goddard Space Flight Center
3 // HEASARC
4 // http://heasarc.gsfc.nasa.gov
5 // e-mail: ccfits@legacy.gsfc.nasa.gov
6 //
7 // Original author: Ben Dorman
8 
9 #ifndef FITSUTILT_H
10 #define FITSUTILT_H
11 
12 #ifdef _MSC_VER
13 #include "MSconfig.h" // for truncation warning
14 #endif
15 
16 
17 #include "FITSUtil.h"
18 
19 #include<typeinfo>
20 #include<iostream>
21 
22 #ifdef SSTREAM_DEFECT
23 #include <strstream>
24 #else
25 #include<sstream>
26 #endif
27 
28 namespace CCfits
29 {
30 
31  namespace FITSUtil
32  {
33 
34  // vector to vector conversion.
35 
36  template <typename S, typename T>
37  void
38  fill(std::vector<S>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
39  {
40  // vector to vector assign. stdlib takes care of deletion.
41  int range = last - first + 1;
42  if (outArray.size() != static_cast<size_t>(range)) outArray.resize(range);
43  for (size_t j = first - 1; j < last; ++j)
44  {
45  outArray[j - first + 1] = static_cast<S>(inArray[j]);
46  }
47  }
48 
49  // vector to valarray conversion.
50 
51  template <typename S, typename T>
52  void fill(std::valarray<S>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
53  {
54  // vector to valarray assign
55  int range = last - first + 1;
56  if (outArray.size() != static_cast<size_t>(range)) outArray.resize(range);
57  for (size_t j = first - 1; j < last; ++j)
58  {
59  outArray[j - first + 1] = static_cast<S>(inArray[j]);
60  }
61  }
62  // valarray to valarray conversion.
63 
64 
65  template <typename S, typename T>
66  void fill(std::valarray<S>& outArray, const std::valarray<T>& inArray)
67  {
68  size_t n = inArray.size();
69  if (outArray.size() != n) outArray.resize(n);
70  for (size_t j = 0;j < n; ++j) outArray[j]
71  = static_cast<S>(inArray[j]);
72  }
73 
74 #ifdef TEMPLATE_AMBIG7_DEFECT
75  template <typename S, typename T>
76  void fillMSva(std::vector<S>& outArray, const std::valarray<T>& inArray)
77  {
78  size_t n = inArray.size();
79  if (outArray.size() != n) outArray.resize(n);
80  for (size_t j = 0;j < n; ++j) outArray[j]
81  = static_cast<S>(inArray[j]);
82  }
83 
84 #else
85  template <typename S, typename T>
86  void fill(std::vector<S>& outArray, const std::valarray<T>& inArray)
87  {
88  size_t n = inArray.size();
89  if (outArray.size() != n) outArray.resize(n);
90  for (size_t j = 0;j < n; ++j) outArray[j]
91  = static_cast<S>(inArray[j]);
92  }
93 #endif
94 
95  // throw exceptions for string conversions to anything other than string.
96 
97 
98  template <typename T>
99  void
100  fill(std::vector<string>& outArray, const std::vector<T>& inArray, size_t first, size_t last)
101  {
102  first = 0;
103  last = 0;
104  throw InvalidConversion(errorMessage(outArray,inArray),false);
105 
106  }
107 
108  template <typename T>
109  void fill(std::vector<T>& outArray, const std::vector<string>& inArray, size_t first, size_t last)
110  {
111  first = 0;
112  last = 0;
113  throw InvalidConversion(errorMessage(outArray,inArray),false);
114  }
115 
116 
117 
118 
119  template<typename S, typename T>
120  string errorMessage( const S& out, const T& in)
121  {
122 #ifdef SSTREAM_DEFECT
123  std::ostrstream errMsg;
124 #else
125  std::ostringstream errMsg;
126 #endif
127  errMsg << " Error: no conversion from " << typeid(in).name() << " to "
128  << typeid(out).name() << std::endl;
129  return errMsg.str();
130 
131  }
132 
133  }
134 
135 } // namespace CCfits
136 
137 
138 #endif
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
FITSUtil is a namespace containing functions used internally by CCfits, but which might be of use for...