1 #ifndef DOZERG_POSIX_SHM_H_20130325 2 #define DOZERG_POSIX_SHM_H_20130325 10 #include "template.hh" 11 #include "posix_shm_file.hh" 12 #include "tools/system.hh" 13 #include "impl/posix_shm_impl.hh" 22 template<
typename T,
bool RO = false,
bool PF = true>
26 template<
typename T,
bool PF>
30 typedef NS_IMPL::CPosixShmImpl<__File> __Shm;
33 typedef const T & const_reference;
34 typedef const T * const_pointer;
35 static const int kModeDefault = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
37 static std::string ErrMsg(){
return tools::ErrorMsg(errno);}
41 bool valid()
const{
return shm_.valid();}
56 int init(
const std::string & filename,
size_t sz = 0,
void * address = NULL,
int mode = kModeDefault){
57 const int ret = shm_.init(filename,
sizeof(value_type) * sz, readonly_, address, mode);
60 sz_ = (sz ? sz : shm_.size() /
sizeof(value_type));
64 int init(
size_t sz,
void * address = NULL){
66 return shm_.init(
sizeof(value_type) * sz_, address);
75 bool setResident(
bool on){
return shm_.setResident(on);}
81 bool setDeleted(){
return shm_.setDeleted();}
84 void uninit(){
return shm_.uninit();}
86 size_t size()
const{
return sz_;}
88 const_pointer ptr()
const{
89 return reinterpret_cast<const_pointer
>(shm_.addr());
93 const_reference operator [](
size_t index)
const{
return ptr()[index];}
95 const_reference front()
const{
100 explicit CPosixShm(
bool readonly):readonly_(readonly){}
108 template<
typename T,
bool PF>
113 typedef T & reference;
119 return reinterpret_cast<pointer
>(__MyBase::shm_.addr());
123 using __MyBase::operator [];
124 reference operator [](
size_t index){
return ptr()[index];}
126 using __MyBase::front;
128 assert(__MyBase::valid());
Definition: posix_shm_file.hh:10
Definition: posix_shm.hh:27
Definition: posix_shm.hh:23