/usr/include/SurgSim/DataStructures/DataStructuresConvert-inl.h is in libopensurgsim-dev 0.7.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | // This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H
#define SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H
#include <string>
#include "SurgSim/Framework/Log.h"
namespace SurgSim
{
namespace DataStructures
{
namespace Convert
{
const std::string serializeLogger = "Serialization";
const std::string hasValueName = "HasValue";
const std::string valueName = "Value";
};
};
};
template <class T>
YAML::Node YAML::convert<SurgSim::DataStructures::OptionalValue<T>>::encode(
const SurgSim::DataStructures::OptionalValue<T>& rhs)
{
Node node;
node[SurgSim::DataStructures::Convert::hasValueName] = rhs.hasValue();
if (rhs.hasValue())
{
node[SurgSim::DataStructures::Convert::valueName] = rhs.getValue();
}
else
{
node[SurgSim::DataStructures::Convert::valueName] = "Not set";
}
return node;
}
template <class T>
bool YAML::convert<SurgSim::DataStructures::OptionalValue<T>>::decode(
const Node& node, SurgSim::DataStructures::OptionalValue<T>& rhs) //NOLINT
{
bool result = true;
if (node.IsMap())
{
if (node[SurgSim::DataStructures::Convert::hasValueName].as<bool>())
{
try
{
rhs.setValue(node[SurgSim::DataStructures::Convert::valueName].as<T>());
}
catch (YAML::RepresentationException)
{
result = false;
auto logger = SurgSim::Framework::Logger::getLogger(SurgSim::DataStructures::Convert::serializeLogger);
SURGSIM_LOG(logger, WARNING) << "Bad conversion";
}
}
else
{
rhs.invalidate();
}
}
else if (node.IsScalar())
{
try
{
rhs.setValue(node.as<T>());
}
catch (YAML::RepresentationException)
{
result = false;
auto logger = SurgSim::Framework::Logger::getLogger(SurgSim::DataStructures::Convert::serializeLogger);
SURGSIM_LOG(logger, WARNING) << "Bad conversion";
}
}
return result;
}
template <class T, size_t N>
YAML::Node YAML::convert<std::array<T, N>>::encode(const std::array<T, N>& rhs)
{
Node node(NodeType::Sequence);
for (auto it = rhs.cbegin(); it != rhs.cend(); ++it)
{
node.push_back(*it);
}
return node;
}
template <class T, size_t N>
bool YAML::convert<std::array<T, N>>::decode(const Node& node, std::array<T, N>& rhs) //NOLINT
{
if (!node.IsSequence() || node.size() != N)
{
return false;
}
bool result = true;
auto rhsit = rhs.begin();
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it, ++rhsit)
{
try
{
(*rhsit) = it->as<T>();
}
catch (YAML::RepresentationException)
{
result = false;
auto logger = SurgSim::Framework::Logger::getLogger(SurgSim::DataStructures::Convert::serializeLogger);
SURGSIM_LOG(logger, WARNING) << __FUNCTION__ << ": Bad conversion";
}
}
return result;
}
template <class Key, class T>
YAML::Node YAML::convert<std::unordered_map<Key, T>>::encode(const std::unordered_map<Key, T>& rhs)
{
Node node(NodeType::Map);
for (auto it = std::begin(rhs); it != std::end(rhs); ++it)
{
node[it->first] = it->second;
}
return node;
}
template <class Key, class T>
bool YAML::convert<std::unordered_map<Key, T>>::decode(const Node& node, std::unordered_map<Key, T>& rhs) //NOLINT
{
if (!node.IsMap())
{
return false;
}
bool result = true;
for (auto it = node.begin(); it != node.end(); ++it)
{
try
{
rhs[it->first.as<Key>()] = it->second.as<T>();
}
catch (YAML::RepresentationException)
{
result = false;
auto logger = SurgSim::Framework::Logger::getLogger(SurgSim::DataStructures::Convert::serializeLogger);
SURGSIM_LOG(logger, WARNING) << __FUNCTION__ << ": Bad conversion";
}
}
return result;
}
template <class Value>
YAML::Node YAML::convert<std::unordered_set<Value>>::encode(const std::unordered_set<Value>& rhs)
{
Node node(NodeType::Sequence);
for (auto it = std::begin(rhs); it != std::end(rhs); ++it)
{
node.push_back(*it);
}
return node;
}
template <class Value>
bool YAML::convert<std::unordered_set<Value>>::decode(const Node& node, std::unordered_set<Value>& rhs) //NOLINT
{
if (!node.IsSequence())
{
return false;
}
bool result = true;
for (auto it = node.begin(); it != node.end(); ++it)
{
try
{
rhs.insert(it->as<Value>());
}
catch (YAML::RepresentationException)
{
result = false;
auto logger = SurgSim::Framework::Logger::getLogger(SurgSim::DataStructures::Convert::serializeLogger);
SURGSIM_LOG(logger, WARNING) << __FUNCTION__ << ": Bad conversion";
}
}
return result;
}
#endif // SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H
|