Program Listing for File uuid.hpp
↰ Return to documentation for file (/tmp/ws/src/fuse/fuse_core/include/fuse_core/uuid.hpp
)
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2018, Locus Robotics
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FUSE_CORE__UUID_HPP_
#define FUSE_CORE__UUID_HPP_
#include <functional>
#include <string>
#include <boost/functional/hash.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <rclcpp/time.hpp>
namespace fuse_core
{
using UUID = boost::uuids::uuid;
namespace uuid
{
using boost::uuids::to_string;
using hash = boost::hash<UUID>;
constexpr UUID NIL = {{0}};
inline UUID from_string(const std::string & uuid_string)
{
return boost::uuids::string_generator()(uuid_string);
}
UUID generate();
inline UUID generate(const void * data, size_t byte_count)
{
return boost::uuids::name_generator(NIL)(data, byte_count);
}
inline UUID generate(const char * data)
{
return generate(data, std::strlen(data));
}
inline UUID generate(const std::string & data)
{
return generate(data.c_str(), data.length());
}
inline UUID generate(const std::string & namespace_string, const void * data, size_t byte_count)
{
return boost::uuids::name_generator(generate(namespace_string))(data, byte_count);
}
inline UUID generate(const std::string & namespace_string, const char * data)
{
return generate(namespace_string, data, std::strlen(data));
}
inline UUID generate(const std::string & namespace_string, const std::string & data)
{
return generate(namespace_string, data.c_str(), data.length());
}
UUID generate(const std::string & namespace_string, const rclcpp::Time & stamp);
UUID generate(const std::string & namespace_string, const rclcpp::Time & stamp, const UUID & id);
UUID generate(const std::string & namespace_string, const uint64_t & user_id);
} // namespace uuid
} // namespace fuse_core
namespace std
{
template<>
struct hash<fuse_core::UUID>
{
size_t operator()(const fuse_core::UUID & id) const
{
return boost::uuids::hash_value(id);
}
};
} // namespace std
#endif // FUSE_CORE__UUID_HPP_