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
LogicalLocation.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 
38 #ifndef __GNUC__
39 # define __attribute__(x) /*NOTHING*/
40 #endif
41 static char const* SVNid __attribute__((unused)) = "$Id$";
42 
44 
45 #include "boost/regex.hpp"
46 #include "lsst/pex/exceptions.h"
47 #include "lsst/pex/logging/Trace.h"
48 
49 namespace dafBase = lsst::daf::base;
50 namespace dafPersist = lsst::daf::persistence;
51 namespace pexExcept = lsst::pex::exceptions;
52 namespace pexLog = lsst::pex::logging;
53 
55 
59  std::string const& locString, CONST_PTR(dafBase::PropertySet) additionalData) :
60  lsst::daf::base::Citizen(typeid(*this)), _locString() {
61  boost::regex expr("(%.*?)\\((\\w+?)\\)");
62  boost::sregex_iterator i = make_regex_iterator(locString, expr);
63  boost::sregex_iterator last;
64  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
65  "Input string: " + locString);
66  while (i != boost::sregex_iterator()) {
67  last = i;
68  if ((*i).prefix().matched) {
69  _locString += (*i).prefix().str();
70  }
71  std::string fmt = (*i).str(1);
72  std::string key = (*i).str(2);
73  pexLog::TTrace<5>("daf.persistence.LogicalLocation", "Key: " + key);
74  if (_map && _map->exists(key)) {
75  if (_map->typeOf(key) == typeid(int)) {
76  int value = _map->getAsInt(key);
77  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
78  "Map Val: %d", value);
79  if (fmt == "%") {
80  _locString += (boost::format("%1%") % value).str();
81  }
82  else {
83  _locString += (boost::format(fmt) % value).str();
84  }
85  }
86  else {
87  std::string value = _map->getAsString(key);
88  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
89  "Map Val: " + value);
90  _locString += value;
91  }
92  }
93  else if (additionalData && additionalData->exists(key)) {
94  if (additionalData->typeOf(key) == typeid(int)) {
95  int value = additionalData->getAsInt(key);
96  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
97  "Map Val: %d", value);
98  if (fmt == "%") {
99  _locString += (boost::format("%1%") % value).str();
100  }
101  else {
102  _locString += (boost::format(fmt) % value).str();
103  }
104  }
105  else {
106  std::string value = additionalData->getAsString(key);
107  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
108  "Map Val: " + value);
109  _locString += value;
110  }
111  }
112  else {
113  throw LSST_EXCEPT(pexExcept::RuntimeError,
114  "Unknown substitution: " + key);
115  }
116  ++i;
117  }
118  if (last == boost::sregex_iterator()) {
120  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
121  "Copy to: " + _locString);
122  }
123  else {
124  _locString += (*last).suffix().str();
125  pexLog::TTrace<5>("daf.persistence.LogicalLocation",
126  "Result: " + _locString);
127  }
128 }
129 
132 std::string const& dafPersist::LogicalLocation::locString(void) const {
133  return _locString;
134 }
135 
140  if (map) {
141  _map = map->deepCopy();
142  } else {
143  _map.reset();
144  }
145 }
Include files required for standard LSST Exception handling.
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
definition of the Trace messaging facilities
#define PTR(...)
Definition: base.h:41
static boost::shared_ptr< dafBase::PropertySet > _map
The logical-to-less-logical map.
int getAsInt(std::string const &name) const
Definition: PropertySet.cc:333
LogicalLocation(std::string const &locString, boost::shared_ptr< dafBase::PropertySet const > additionalData=boost::shared_ptr< dafBase::PropertySet const >())
std::string const & locString(void) const
std::string _locString
The location string.
#define __attribute__(x)
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static void setLocationMap(boost::shared_ptr< dafBase::PropertySet > map)
std::type_info const & typeOf(std::string const &name) const
Definition: PropertySet.cc:227
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
#define CONST_PTR(...)
Definition: base.h:47
Interface for LogicalLocation class.
bool exists(std::string const &name) const
Definition: PropertySet.cc:190