67 lines
2.4 KiB
C
67 lines
2.4 KiB
C
|
|
/**
|
||
|
|
* @file shm_header.h
|
||
|
|
* @brief 共享内存 map vector 容器的头文件
|
||
|
|
* @author your name (you@domain.com)
|
||
|
|
* @version 0.1
|
||
|
|
* @date 2023-10-18
|
||
|
|
*
|
||
|
|
* Copyright: Baosight Co. Ltd.
|
||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
#pragma once
|
||
|
|
#include <mix_cc/json.h>
|
||
|
|
#include <mix_cc/type/data_size.h>
|
||
|
|
#include <boost/container/string.hpp>
|
||
|
|
#include <boost/interprocess/allocators/node_allocator.hpp>
|
||
|
|
#include <boost/interprocess/containers/map.hpp>
|
||
|
|
#include <boost/interprocess/containers/string.hpp>
|
||
|
|
#include <boost/interprocess/containers/vector.hpp>
|
||
|
|
#include <boost/interprocess/managed_mapped_file.hpp>
|
||
|
|
#include <iostream>
|
||
|
|
#include <string>
|
||
|
|
namespace ShmHeader {
|
||
|
|
|
||
|
|
namespace bipc = ::boost::interprocess;
|
||
|
|
typedef bipc::managed_mapped_file managed_mapped_file_t; ///<映射文件
|
||
|
|
typedef bipc::managed_mapped_file::segment_manager mapped_segment_manager_t;
|
||
|
|
///< vector<int>
|
||
|
|
typedef bipc::node_allocator<int, mapped_segment_manager_t> vec_allocator_i;
|
||
|
|
typedef boost::container::vector<int, vec_allocator_i> vector_i;
|
||
|
|
///< vector<float>
|
||
|
|
typedef bipc::node_allocator<float, mapped_segment_manager_t> vec_allocator_f;
|
||
|
|
typedef boost::container::vector<float, vec_allocator_f> vector_f;
|
||
|
|
///< vector<double>
|
||
|
|
typedef bipc::node_allocator<double, mapped_segment_manager_t> vec_allocator_d;
|
||
|
|
typedef boost::container::vector<double, vec_allocator_d> vector_d;
|
||
|
|
///< vector<string>
|
||
|
|
typedef bipc::node_allocator<bipc::string, mapped_segment_manager_t>
|
||
|
|
vec_allocator_s;
|
||
|
|
typedef boost::container::vector<bipc::string, vec_allocator_s> vector_s;
|
||
|
|
///<万能 allocator
|
||
|
|
typedef bipc::node_allocator<void, mapped_segment_manager_t>
|
||
|
|
void_allocator; ///<万能 allocator
|
||
|
|
///< string
|
||
|
|
typedef bipc::node_allocator<char, mapped_segment_manager_t> char_allocator;
|
||
|
|
typedef bipc::basic_string<char, std::char_traits<char>, char_allocator>
|
||
|
|
char_string;
|
||
|
|
|
||
|
|
///< map 数据
|
||
|
|
template <class Key, class Value>
|
||
|
|
using MapPair = std::pair<Key, Value>;
|
||
|
|
///< map 分配器
|
||
|
|
template <class Key, class Value>
|
||
|
|
using AllocatorMap =
|
||
|
|
bipc::node_allocator<MapPair<Key, Value>, mapped_segment_manager_t>;
|
||
|
|
///< map的key排序
|
||
|
|
template <class Key>
|
||
|
|
using Mapless = std::less<Key>;
|
||
|
|
///< map
|
||
|
|
template <class Key, class Value>
|
||
|
|
using MapValue = bipc::map<Key, Value, Mapless<Key>, AllocatorMap<Key, Value>>;
|
||
|
|
///< map 迭代器
|
||
|
|
template <class Key, class Value>
|
||
|
|
using MapValueIter = MapValue<Key, Value>::iterator;
|
||
|
|
|
||
|
|
} // namespace ShmHeader
|