/** * @file mix_cc/shm/stl_builder.h * @brief 共享内存stl容器构造器 * @author Cat (null.null.null@qq.com) * @version 0.1 * @date 2021-05-07 * * Copyright: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #pragma once #include #include namespace mix_cc { namespace shm { /** * @brief 共享内存stl容器构造器基类 * @tparam ContainerType * @tparam T * @tparam Segment */ template class StlBuilder { public: typedef ScopedShmAlloc Allocator; typedef ContainerType Type; public: /** * @brief 创建共享stl容器 * @param shm 共享内存块 * @param container_name 容器名 * @return bip::offset_ptr& */ static bip::offset_ptr& construct( Segment* const shm, const std::string& container_name) { return shm->template construct(container_name.c_str())( Allocator(shm->get_segment_manager())); } /** * @brief 在指定内存块上查找共享内存容器 * @param shm 共享内存块 * @param container_name 容器名 * @return bip::offset_ptr& */ static bip::offset_ptr& find( Segment* const shm, const std::string& container_name) { return shm->template find(container_name.c_str())( Allocator(shm->get_segment_manager())); } /** * @brief 在指定内存块上查找共享内存容器,如果找不到,就创建新的容器 * @param shm 共享内存块 * @param container_name 容器名 * @return bip::offset_ptr& */ static bip::offset_ptr find_or_construct( Segment* const shm, const std::string& container_name) { return shm->template find_or_construct( container_name.c_str())(Allocator(shm->get_segment_manager())); } }; } // namespace shm } // namespace mix_cc