Program Listing for File uuid_ordering.hpp
↰ Return to documentation for file (/tmp/ws/src/fuse/fuse_constraints/include/fuse_constraints/uuid_ordering.hpp
)
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2019, 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_CONSTRAINTS__UUID_ORDERING_HPP_
#define FUSE_CONSTRAINTS__UUID_ORDERING_HPP_
#include <fuse_core/uuid.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/vector_of.hpp>
namespace fuse_constraints
{
class UuidOrdering
{
public:
UuidOrdering() = default;
UuidOrdering(std::initializer_list<fuse_core::UUID> uuid_list);
template<typename UuidConstIterator>
UuidOrdering(UuidConstIterator first, UuidConstIterator last);
bool empty() const;
size_t size() const;
bool exists(const unsigned int index) const;
bool exists(const fuse_core::UUID & uuid) const;
bool push_back(const fuse_core::UUID & uuid);
const fuse_core::UUID & operator[](const unsigned int index) const;
unsigned int operator[](const fuse_core::UUID & uuid);
const fuse_core::UUID & at(const unsigned int index) const;
unsigned int at(const fuse_core::UUID & uuid) const;
private:
using UuidOrderMapping = boost::bimaps::bimap<boost::bimaps::vector_of<unsigned int>,
boost::bimaps::unordered_set_of<fuse_core::UUID>>;
UuidOrderMapping order_;
};
template<typename UuidConstIterator>
UuidOrdering::UuidOrdering(UuidConstIterator first, UuidConstIterator last)
{
for (; first != last; ++first) {
order_.insert(order_.end(), UuidOrderMapping::value_type(order_.size(), *first));
}
}
} // namespace fuse_constraints
#endif // FUSE_CONSTRAINTS__UUID_ORDERING_HPP_