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
|
/************************************************************************
*
* Copyright (C) 2009-2023 IRCAD France
* Copyright (C) 2012-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "data/raw_buffer_tl.hpp"
#include "data/timeline/raw_buffer.hpp"
#include <data/exception.hpp>
#include <data/registry/macros.hpp>
#include <functional>
SIGHT_REGISTER_DATA(sight::data::raw_buffer_tl);
namespace sight::data
{
//------------------------------------------------------------------------------
void raw_buffer_tl::shallow_copy(const object::csptr& /*source*/)
{
SIGHT_FATAL("shallow_copy not implemented for : " + this->get_classname());
}
//------------------------------------------------------------------------------
void raw_buffer_tl::deep_copy(const object::csptr& _source, const std::unique_ptr<deep_copy_cache_t>& _cache)
{
const auto& other = std::dynamic_pointer_cast<const raw_buffer_tl>(_source);
SIGHT_THROW_EXCEPTION_IF(
exception(
"Unable to copy " + (_source ? _source->get_classname() : std::string("<NULL>"))
+ " to " + get_classname()
),
!bool(other)
);
this->clear_timeline();
this->alloc_pool_size(other->m_pool->get_requested_size());
for(const auto& elt : other->m_timeline)
{
SPTR(data::timeline::raw_buffer) tl_obj = this->create_buffer(elt.first);
tl_obj->deep_copy(*elt.second);
m_timeline.insert(timeline_t::value_type(elt.first, tl_obj));
}
base_class_t::deep_copy(other, _cache);
}
//------------------------------------------------------------------------------
CSPTR(data::timeline::raw_buffer) raw_buffer_tl::get_closest_buffer(
core::clock::type _timestamp,
timeline::direction_t _direction
) const
{
CSPTR(data::timeline::object) buffer = this->get_closest_object(_timestamp, _direction);
return std::dynamic_pointer_cast<const data::timeline::raw_buffer>(buffer);
}
//------------------------------------------------------------------------------
CSPTR(data::timeline::raw_buffer) raw_buffer_tl::get_buffer(core::clock::type _timestamp) const
{
CSPTR(data::timeline::object) buffer = this->get_object(_timestamp);
return std::dynamic_pointer_cast<const data::timeline::raw_buffer>(buffer);
}
//------------------------------------------------------------------------------
void raw_buffer_tl::init_pool_size(std::size_t _size)
{
this->alloc_pool_size(_size);
}
//------------------------------------------------------------------------------
SPTR(data::timeline::object) raw_buffer_tl::create_object(core::clock::type _timestamp)
{
return this->create_buffer(_timestamp);
}
//------------------------------------------------------------------------------
SPTR(data::timeline::raw_buffer) raw_buffer_tl::create_buffer(core::clock::type _timestamp)
{
return std::make_shared<data::timeline::raw_buffer>(
_timestamp,
reinterpret_cast<data::timeline::buffer::buffer_data_t>(m_pool->malloc()),
m_pool->get_requested_size(),
[object_ptr = m_pool](auto&& _p_h1, auto&& ...){object_ptr->free(std::forward<decltype(_p_h1)>(_p_h1));});
}
//------------------------------------------------------------------------------
bool raw_buffer_tl::is_object_valid(const CSPTR(data::timeline::object)& _obj) const
{
CSPTR(data::timeline::raw_buffer) src_obj =
std::dynamic_pointer_cast<const data::timeline::raw_buffer>(_obj);
return src_obj != nullptr;
}
//------------------------------------------------------------------------------
} // namespace sight::data
|