39 # define __attribute__(x) 45 #include "boost/regex.hpp" 46 #include "lsst/pex/exceptions.h" 47 #include "lsst/log/Log.h" 51 namespace pexExcept = lsst::pex::exceptions;
54 LOG_LOGGER _log = LOG_GET(
"daf.persistence.LogicalLocation");
57 dafBase::PropertySet::Ptr dafPersist::LogicalLocation::_map;
62 std::string
const& locString, CONST_PTR(dafBase::PropertySet) additionalData) :
63 lsst::daf::base::Citizen(typeid(*this)), _locString() {
64 boost::regex expr(
"(%.*?)\\((\\w+?)\\)");
65 boost::sregex_iterator i = make_regex_iterator(locString, expr);
66 boost::sregex_iterator last;
67 LOGLS_DEBUG(_log,
"Input string: " << locString);
68 while (i != boost::sregex_iterator()) {
70 if ((*i).prefix().matched) {
71 _locString += (*i).prefix().str();
73 std::string fmt = (*i).str(1);
74 std::string key = (*i).str(2);
75 LOGLS_DEBUG(_log,
"Key: " << key);
76 if (_map && _map->exists(key)) {
77 if (_map->typeOf(key) ==
typeid(int)) {
78 int value = _map->getAsInt(key);
79 LOGLS_DEBUG(_log,
"Map Val: " << value);
81 _locString += (boost::format(
"%1%") % value).str();
84 _locString += (boost::format(fmt) % value).str();
88 std::string value = _map->getAsString(key);
89 LOGLS_DEBUG(_log,
"Map Val: " << value);
93 else if (additionalData && additionalData->exists(key)) {
94 if (additionalData->typeOf(key) ==
typeid(int)) {
95 int value = additionalData->getAsInt(key);
96 LOGLS_DEBUG(_log,
"Map Val: " << value);
98 _locString += (boost::format(
"%1%") % value).str();
101 _locString += (boost::format(fmt) % value).str();
105 std::string value = additionalData->getAsString(key);
106 LOGLS_DEBUG(_log,
"Map Val: " << value);
111 throw LSST_EXCEPT(pexExcept::RuntimeError,
112 "Unknown substitution: " + key);
116 if (last == boost::sregex_iterator()) {
118 LOGLS_DEBUG(_log,
"Copy to: " << _locString);
121 _locString += (*last).suffix().str();
122 LOGLS_DEBUG(_log,
"Result: " << _locString);
135 dafBase::PersistentCitizenScope scope;
137 _map = map->deepCopy();
std::string const & locString(void) const
Accessor.
LogicalLocation(std::string const &locString, boost::shared_ptr< dafBase::PropertySet const > additionalData=boost::shared_ptr< dafBase::PropertySet const >())
Constructor from string and additional data.
static void setLocationMap(boost::shared_ptr< dafBase::PropertySet > map)
Set the logical-to-less-logical map.
Interface for LogicalLocation class.