00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2016, Southwest Research Institute® (SwRI®) 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Southwest Research Institute® (SwRI®) nor the 00014 // names of its contributors may be used to endorse or promote products 00015 // derived from this software without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 // 00028 // ***************************************************************************** 00029 #include <swri_route_util/route_point.h> 00030 00031 namespace swri_route_util 00032 { 00033 RoutePoint::RoutePoint() 00034 { 00035 id_ = "<not-initialized>"; 00036 stop_point_ = false; 00037 } 00038 00039 std::vector<std::string> RoutePoint::getPropertyNames() const 00040 { 00041 std::vector<std::string> names; 00042 names.push_back("stop_point"); 00043 names.push_back("stop_point_delay"); 00044 00045 for (auto const &it : properties_) { 00046 names.push_back(it.first); 00047 } 00048 00049 return names; 00050 } 00051 00052 std::string RoutePoint::getProperty(const std::string &name) const 00053 { 00054 if (name == "stop_point") { 00055 return stop_point_ ? "true" : "false"; 00056 } 00057 00058 if (name == "stop_point_delay") { 00059 return boost::lexical_cast<std::string>(stop_point_delay_); 00060 } 00061 00062 if (properties_.count(name)) { 00063 return properties_.at(name); 00064 } else { 00065 return ""; 00066 } 00067 } 00068 00069 bool RoutePoint::hasProperty(const std::string &name) const 00070 { 00071 if (name == "stop_point") { return true; } 00072 if (name == "stop_point_delay") { return true; } 00073 return properties_.count(name); 00074 } 00075 00076 void RoutePoint::setProperty(const std::string &name, const std::string &value) 00077 { 00078 if (name == "stop_point") { 00079 stop_point_ = (value == "1") || (value == "true"); 00080 } else if (name == "stop_point_delay") { 00081 stop_point_delay_ = boost::lexical_cast<double>(value); 00082 } else { 00083 properties_[name] = value; 00084 } 00085 } 00086 00087 void RoutePoint::deleteProperty(const std::string &name) 00088 { 00089 // If we add "native" properties that are erasable, we should check 00090 // for those here first and mark them as deleted when appropriate. 00091 00092 // Otherwise, fall back to the generic properties. 00093 // std::map::erase() ignores the call if the key is not found. 00094 properties_.erase(name); 00095 } 00096 } // namespace swri_route_util