1 #ifndef DOZERG_SYSV_SHM_H_20130301 2 #define DOZERG_SYSV_SHM_H_20130301 11 #include "tools/system.hh" 12 #include "impl/sysv_shm_impl.hh" 19 template<
typename T,
size_t N = 1,
bool RO = false>
23 template<
typename T,
size_t N>
26 typedef NS_IMPL::CSysvShmImpl __Shm;
29 typedef const T & const_reference;
30 typedef const T * const_pointer;
31 static const int kModeDefault = SHM_R | SHM_W;
32 static const size_t kSize = N;
34 static std::string ErrMsg(){
return tools::ErrorMsg(errno);}
38 bool valid()
const{
return shm_.valid();}
49 int init(
const std::string & pathname,
int projId,
void * address = NULL,
int mode = kModeDefault){
52 key_t key = ::ftok(pathname.c_str(), projId);
55 return init(key, address, mode);
57 int init(key_t key = IPC_PRIVATE,
void * address = NULL,
int mode = kModeDefault){
58 return shm_.init(key,
sizeof(value_type) * kSize, readonly_, address, mode);
67 bool setResident(
bool on){
return shm_.setResident(on);}
73 bool setDeleted(){
return shm_.setDeleted();}
76 void uninit(){
return shm_.uninit();}
78 size_t size()
const{
return kSize;}
80 const_pointer ptr()
const{
81 return reinterpret_cast<const_pointer
>(shm_.addr());
85 const_reference operator [](
size_t index)
const{
return ptr()[index];}
87 const_reference front()
const{
92 explicit CSysvShm(
bool readonly):readonly_(readonly){}
99 template<
typename T,
size_t N>
104 typedef T & reference;
110 return reinterpret_cast<pointer
>(__MyBase::shm_.addr());
114 using __MyBase::operator [];
115 reference operator [](
size_t index){
return ptr()[index];}
117 using __MyBase::front;
119 assert(__MyBase::valid());
Definition: sysv_shm.hh:20
Definition: sysv_shm.hh:24