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
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
home
lsstsw
stack
Linux64
utils
11.0-1-g47edd16
src
Utils.cc
Go to the documentation of this file.
1
/*
2
* LSST Data Management System
3
* Copyright 2008, 2009, 2010 LSST Corporation.
4
*
5
* This product includes software developed by the
6
* LSST Project (http://www.lsst.org/).
7
*
8
* This program is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the LSST License Statement and
19
* the GNU General Public License along with this program. If not,
20
* see <http://www.lsstcorp.org/LegalNotices/>.
21
*/
22
23
#include "
lsst/utils/Utils.h
"
24
25
#include <iostream>
26
#include <sstream>
27
#include <string>
28
#include "boost/regex.hpp"
29
#include "
lsst/pex/exceptions.h
"
30
31
namespace
lsst {
32
namespace
utils {
33
34
boost::any
stringToAny
(std::string valueString)
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
}
65
66
std::string
getPackageDir
(std::string
const
& packageName) {
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
}
79
80
}}
// namespace lsst::utils
Utils.h
exceptions.h
Include files required for standard LSST Exception handling.
lsst.utils::getPackageDir
std::string getPackageDir(std::string const &packageName)
return the root directory of a setup package
Definition:
Utils.cc:66
lsst::afw::geom::any
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
Definition:
CoordinateExpr.h:87
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Definition:
Exception.h:46
lsst.utils::stringToAny
boost::any stringToAny(std::string valueString)
Definition:
Utils.cc:34
Generated on Thu Sep 24 2015 02:29:16 for LSSTApplications by
1.8.5