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
Namespaces | Classes | Functions
lsst.utils Namespace Reference

Namespaces

 multithreading
 
 tests
 
 version
 

Classes

class  Symbol
 
struct  n
 
struct  key
 

Functions

std::string demangleType (std::string const _typeName)
 
template<class T >
int fpclassify (T t)
 
template<class T >
int isfinite (T t)
 
template<class T >
int isinf (T t)
 
template<class T >
int isnan (T t)
 
template<class T >
int isnormal (T t)
 
std::string raRadToStr (double raRad)
 
std::string decRadToStr (double decRad)
 
std::string raDegToStr (double raDeg)
 
std::string decDegToStr (double decDeg)
 
std::string raDecRadToStr (double raRad, double decRad)
 
std::string raDecDegToStr (double raDeg, double decDeg)
 
double raStrToRad (std::string raStr, std::string delimiter=":")
 
double raStrToDeg (std::string raStr, std::string delimiter=":")
 
double decStrToRad (std::string decStr, std::string delimiter=":")
 
double decStrToDeg (std::string decStr, std::string delimiter=":")
 
std::string getPackageDir (std::string const &packageName)
 return the root directory of a setup package More...
 
boost::any stringToAny (std::string valueString)
 

Function Documentation

std::string lsst::utils::demangleType ( std::string const  _typeName)

Definition at line 113 of file Demangle.cc.

113  {
114 #if 1
115  typedef multi_index_container<
116  Symbol,
117  indexed_by<
118  ordered_unique<tag<n>,
119  member<Symbol, int, &Symbol::n> >,
120  ordered_unique<tag<key>,
121  member<Symbol, std::string, &Symbol::key> >
122  >
123  > SymbolTable;
124  typedef SymbolTable::index<n>::type::iterator nIterator;
125  typedef SymbolTable::index<key>::type::iterator keyIterator;
126  Symbol::reset();
127 
128  // Here's my symbol table and its indices
129  SymbolTable st;
130 
131  SymbolTable::index<n>::type &nIndex = st.get<n>();
132  SymbolTable::index<key>::type &keyIndex = st.get<key>();
133  //
134  // Start mangling
135  //
136  std::string typeName("");
137  const char *ptr = _typeName.c_str();
138 
139  if (*ptr == 'r' || *ptr == 'V' || *ptr == 'K') {
140  ptr++; // (restrict/volatile/const)
141  }
142 
143  if (*ptr == 'P') ptr++; // We passed "this" which is (type *)
144 
145  std::string currentSymbol = ""; // Current symbol
146  std::stack<char> typeStack; // Did we last see an N or an I?
147 
148  int lastTokenWasType = 0; // When > 0, the last token was a type such as int or float
149  while (*ptr != '\0') {
150  lastTokenWasType--;
151  switch (*ptr) {
152  case 'E':
153  ptr++;
154  currentSymbol = "";
155 
156  if (typeStack.empty()) {
157  typeStack.push('\a'); // at least don't crash
158  }
159 
160  if (typeStack.top() == 'I') {
161  typeName += '>';
162  } else if (typeStack.top() == 'L') {
163  ;
164  } else if (typeStack.top() == 'N') {
165  ;
166  }
167  typeStack.pop();
168 
169  if (!typeStack.empty() && typeStack.top() == 'I') {
170  if (*ptr != 'E' && typeName[typeName.size() - 1] != '<') {
171  typeName += ',';
172  }
173  }
174 
175  break;
176  case 'I':
177  typeStack.push(*ptr++);
178  currentSymbol = "";
179 
180  typeName += '<';
181  break;
182  case 'L':
183  typeStack.push(*ptr++);
184  currentSymbol = "";
185  {
186  std::string type;
187  if (interpret_typeletter(*ptr, type)) {
188  typeName += "(" + type + ')';
189  } else {
190  typeName += 'c';
191  }
192  ptr++;
193  }
194  if (*ptr == 'n') {
195  typeName += '-'; ptr++;
196  }
197  while (*ptr != '\0' && *ptr != 'E') {
198  typeName += *ptr++;
199  }
200  break;
201  case 'N':
202  typeStack.push(*ptr++);
203  currentSymbol = "";
204  break;
205  case 'S':
206  ++ptr;
207  switch (*ptr) {
208  case 't': typeName += "::std::"; break;
209  case 'a': typeName += "::std::allocator"; break;
210  case 'b': typeName += "::std::basic_string"; break;
211  case 's': typeName += "::std::basic_string<char,::std::char_traits<char>,::std::allocator<char>>"; break;
212  case 'i': typeName += "::std::basic_istream<char, std::char_traits<char> >"; break;
213  case 'o': typeName += "::std::basic_ostream<char,std::char_traits<char>>"; break;
214  case 'd': typeName += "::std::basic_iostream<char,std::char_traits<char>>"; break;
215  default:
216  {
217  int subst = 0; // number of substitution
218 
219  if (*ptr == '_') {
220  ; // S_ => 0
221  } else if (isdigit(*ptr) || isupper(*ptr)) {
222  while (isdigit(*ptr) || isupper(*ptr)) {
223  if (isdigit(*ptr)) {
224  subst = 36*subst + (*ptr - '0');
225  } else {
226  subst = 36*subst + 10 + (*ptr - 'A');
227  }
228  ptr++;
229  }
230  subst++; // S_ == 0; S1_ == 1
231  assert (*ptr == '_');
232  ptr++;
233  }
234 
235  nIterator sym = nIndex.find(subst);
236  if (sym == nIndex.end()) { // not found
237  typeName += (boost::format("[S%d]") % subst).str();
238  } else {
239  typeName += sym->key;
240  }
241 
242  }
243  break;
244  }
245  currentSymbol = "";
246  break;
247  case '0': case '1': case '2': case '3': case '4':
248  case '5': case '6': case '7': case '8': case '9':
249  {
250  const int len = atoi(ptr++);
251  while (isdigit(*ptr)) ptr++;
252 
253  std::string name = "";
254  for (int i = 0; *ptr != '\0' && i < len; i++) {
255  name += *ptr++;
256  }
257 
258  if (currentSymbol != "") {
259  currentSymbol += "::";
260  typeName += "::";
261  }
262 
263  currentSymbol += name;
264  typeName += name;
265 
266  if (keyIndex.find(currentSymbol) == keyIndex.end()) {
267  st.insert(currentSymbol);
268  }
269  }
270  break;
271  default:
272  {
273  std::string type;
274  if (interpret_typeletter(*ptr, type)) {
275  if (lastTokenWasType > 0) {
276  typeName += ",";
277  }
278  typeName += type;
279  lastTokenWasType = 2; // it'll be decremented on every char in the name
280  } else {
281  typeName += *ptr;
282  }
283  ptr++;
284  }
285  }
286  }
287 
288  static volatile bool dumpSymbolTable = false; // can be set from gdb
289  if (dumpSymbolTable) {
290  // The test on the iterator is paranoid, but they _could_
291  // have deleted elements. In this case, they didn't.
292  for (unsigned int i = 0; i < st.size(); i++) {
293  nIterator el = nIndex.find(2);
294  if (el != nIndex.end()) { // did we find it?
295  el->print();
296  }
297  }
298  }
299 
300  return typeName;
301 #else
302  return _typeName;
303 #endif
304 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
template<class T >
int lsst::utils::fpclassify ( t)

Definition at line 95 of file ieee.h.

95  {
96  return lsst_fpclassify(t);
97 }
std::string lsst::utils::getPackageDir ( std::string const &  packageName)

return the root directory of a setup package

Parameters
[in]packageNamename of package (e.g. "utils")
Exceptions
lsst::pex::exceptions::NotFoundErrorif desired version can't be found
Examples:
spatialCellExample.cc.

Definition at line 66 of file Utils.cc.

66  {
67  std::string envVar = packageName; // package's environment variable
68 
69  transform(envVar.begin(), envVar.end(), envVar.begin(), (int (*)(int)) toupper);
70  envVar += "_DIR";
71 
72  char const *dir = getenv(envVar.c_str());
73  if (!dir) {
74  throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError, "Package " + packageName + " not found");
75  }
76 
77  return dir;
78 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<class T >
int lsst::utils::isfinite ( t)

Definition at line 100 of file ieee.h.

100  {
101  return lsst_isfinite(t);
102 }
template<class T >
int lsst::utils::isinf ( t)

Definition at line 105 of file ieee.h.

105  {
106  return lsst_isinf(t);
107 }
template<class T >
int lsst::utils::isnan ( t)

Definition at line 110 of file ieee.h.

110  {
111  return lsst_isnan(t);
112 }
template<class T >
int lsst::utils::isnormal ( t)

Definition at line 115 of file ieee.h.

115  {
116  return lsst_isnormal(t);
117 }
boost::any lsst::utils::stringToAny ( std::string  valueString)

Definition at line 34 of file Utils.cc.

35 {
36  const boost::regex intRegex("(\\Q+\\E|\\Q-\\E){0,1}[0-9]+");
37  const boost::regex doubleRegex("(\\Q+\\E|\\Q-\\E){0,1}([0-9]*\\.[0-9]+|[0-9]+\\.[0-9]*)((e|E)(\\Q+\\E|\\Q-\\E){0,1}[0-9]+){0,1}");
38  const boost::regex FitsStringRegex("'(.*)'");
39 
40  boost::smatch matchStrings;
41 
42  std::istringstream converter(valueString);
43 
44  if (boost::regex_match(valueString, intRegex)) {
45  // convert the string to an int
46  int intVal;
47  converter >> intVal;
48  return boost::any(intVal);
49  }
50 
51  if (boost::regex_match(valueString, doubleRegex)) {
52  // convert the string to a double
53  double doubleVal;
54  converter >> doubleVal;
55  return boost::any(doubleVal);
56  }
57 
58  if (boost::regex_match(valueString, matchStrings, FitsStringRegex)) {
59  // strip off the enclosing single quotes and return the string
60  return boost::any(matchStrings[1].str());
61  }
62 
63  return boost::any(valueString);
64 }
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.