LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | List of all members
lsst::meas::algorithms::shapelet::ConvertibleString Class Reference

#include <ConfigFile.h>

Inheritance diagram for lsst::meas::algorithms::shapelet::ConvertibleString:

Public Member Functions

 ConvertibleString ()
 
 ConvertibleString (const std::string s)
 
template<typename T >
 ConvertibleString (const T &x)
 
template<typename T >
 ConvertibleString (const std::vector< T > &x)
 
 ~ConvertibleString ()
 
ConvertibleStringoperator= (const std::string &rhs)
 
template<typename T >
ConvertibleStringoperator= (const T &x)
 
template<typename T >
ConvertibleStringoperator= (const std::vector< T > &x)
 
template<typename T >
 operator T () const
 
template<typename T >
 operator std::vector< T > () const
 

Private Member Functions

bool operator_bool () const
 

Detailed Description

Definition at line 54 of file ConfigFile.h.

Constructor & Destructor Documentation

lsst::meas::algorithms::shapelet::ConvertibleString::ConvertibleString ( )
inline

Definition at line 58 of file ConfigFile.h.

58 : std::string("") {};
lsst::meas::algorithms::shapelet::ConvertibleString::ConvertibleString ( const std::string  s)
inline

Definition at line 59 of file ConfigFile.h.

59 : std::string(s) {}
template<typename T >
lsst::meas::algorithms::shapelet::ConvertibleString::ConvertibleString ( const T &  x)
inlineexplicit

Definition at line 62 of file ConfigFile.h.

63  { *this = x; }
double x
template<typename T >
lsst::meas::algorithms::shapelet::ConvertibleString::ConvertibleString ( const std::vector< T > &  x)
inlineexplicit

Definition at line 66 of file ConfigFile.h.

67  { *this = x; }
double x
lsst::meas::algorithms::shapelet::ConvertibleString::~ConvertibleString ( )
inline

Definition at line 69 of file ConfigFile.h.

69 {};

Member Function Documentation

template<typename T >
lsst::meas::algorithms::shapelet::ConvertibleString::operator std::vector< T > ( ) const
inline

Definition at line 141 of file ConfigFile.h.

142  {
143 #ifdef Use_Zero_Default
144  if (*this == "") return std::vector<T>();
145 #endif
146 
147  std::string err="Could not convert ConvertibleString to input type ";
148  err += std::string("std::vector<")+typeid(T).name()+">";
149  err += std::string(": this = ") + *this;
150 
151  // Two syntaxes: "{1.,2.,3.}" or "1. 2. 3."
152  if ((*this)[0] == '{') {
153  // Using "{1.,2.,3.}" syntax
154 
155  int i1 = this->find_first_not_of(" \t\n\r\f",1);
156  if (i1 == int(std::string::npos)) {
157 #ifdef NOTHROW
158  std::cerr<<err<<std::endl;
159  exit(1);
160  return std::vector<T>();
161 #else
162  throw ParameterException(err);
163 #endif
164  }
165  if ((*this)[i1] == '}') {
166  // string is empty: "{ }"
167  return std::vector<T>();
168  }
169 
170  int nComma = std::count(this->begin(),this->end(),',');
171  std::vector<T> ret(nComma+1);
172 
173  int i2 = this->find_first_of("},",i1);
174  int j = 0;
175 
176  while ((*this)[i2] != '}') {
177  std::string s = this->substr(i1,i2-i1);
178  std::stringstream ss(s);
179  ss >> ret[j++];
180  i1 = i2+1;
181  i2 = this->find_first_of("},",i1);
182  }
183  {
184  // Do last element
185  std::string s = this->substr(i1,i2-i1);
186  std::stringstream ss(s);
187  ss >> ret[j];
188  }
189  if (j != nComma) {
190  throw ParameterException(err);
191  }
192  return ret;
193  } else {
194  // Using "1. 2. 3." syntax
195  std::stringstream ss(*this);
196  std::vector<T> ret;
197  T x;
198  while (ss >> x) ret.push_back(x);
199  return ret;
200  }
201  }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
double x
template<typename T >
lsst::meas::algorithms::shapelet::ConvertibleString::operator T ( ) const
inline

Definition at line 98 of file ConfigFile.h.

99  {
100  // Handle bool specially
101  if (is_bool<T>::value) {
102  return operator_bool();
103  }
104 
105  // OK, not bool
106 #ifdef Use_Zero_Default
107  if (*this == "") return T();
108 #endif
109 
110  std::string err="Could not convert ConvertibleString to input type ";
111  err += typeid(T).name();
112  err += std::string(": this = ") + *this;
113  T temp;
114  std::stringstream ss(*this);
115 
116  // This bit is needed to get the oct and hex to work:
117  // I haven't incorporated it into the below vector conversion,
118  // so those always need to be decimal.
119  if (std::numeric_limits<T>::is_integer) {
120  if ((*this)[0] == '0') {
121  if ((*this)[1] == 'x' || (*this)[1] == 'X') {
122  ss >> std::hex;
123  } else {
124  ss >> std::oct;
125  }
126  }
127  }
128  ss >> temp;
129  if (!ss) {
130 #ifndef NOTHROW
131  std::cerr<<err<<std::endl;
132  exit(1);
133 #else
134  throw ParameterException(err);
135 #endif
136  }
137  return temp;
138  }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
ConvertibleString& lsst::meas::algorithms::shapelet::ConvertibleString::operator= ( const std::string &  rhs)
inline

Definition at line 71 of file ConfigFile.h.

72  {
73  std::string::operator=(rhs);
74  return *this;
75  }
template<typename T >
ConvertibleString& lsst::meas::algorithms::shapelet::ConvertibleString::operator= ( const T &  x)
inline

Definition at line 78 of file ConfigFile.h.

79  {
80  std::stringstream oss;
81  oss << x;
82  *this = oss.str();
83  return *this;
84  }
double x
template<typename T >
ConvertibleString& lsst::meas::algorithms::shapelet::ConvertibleString::operator= ( const std::vector< T > &  x)
inline

Definition at line 87 of file ConfigFile.h.

88  {
89  std::stringstream oss;
90  const int n = x.size();
91  if (n > 0) oss << x[0];
92  for(int i=1;i<n;++i) oss << ' ' << x[i];
93  *this = oss.str();
94  return *this;
95  }
bool lsst::meas::algorithms::shapelet::ConvertibleString::operator_bool ( ) const
inlineprivate

Definition at line 207 of file ConfigFile.h.

208  {
209 #ifdef Use_Zero_Default
210  if (*this == "") return false;
211 #endif
212 
213  // make string all caps
214  std::string sup = *this;
215  for ( std::string::iterator p = sup.begin(); p != sup.end(); ++p )
216  *p = toupper(*p);
217 
218  if ( sup=="FALSE" || sup=="F" || sup=="NO" || sup=="N" ||
219  sup=="0" || sup=="NONE" ) {
220  return false;
221  } else if ( sup=="TRUE" || sup=="T" || sup=="YES" || sup=="Y" ||
222  sup=="1" ) {
223  return true;
224  } else {
225  std::string err=
226  "Could not convert ConvertibleString to input type bool"
227  ": this = " + *this;
228 #ifdef NOTHROW
229  std::cerr<<err<<std::endl;
230  exit(1);
231  return false;
232 #else
233  throw ParameterException(err);
234 #endif
235  }
236  }

The documentation for this class was generated from the following file: