Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
chainbase::shared_cow_string Class Reference

#include <shared_cow_string.hpp>

Inheritance diagram for chainbase::shared_cow_string:

Public Types

using allocator_type = bip::allocator<char, pinnable_mapped_file::segment_manager>
 
using iterator = const char*
 
using const_iterator = const char*
 

Public Member Functions

 shared_cow_string (const allocator_type &alloc)
 
template<typename Iter >
 shared_cow_string (Iter begin, Iter end, const allocator_type &alloc)
 
 shared_cow_string (const char *ptr, std::size_t size, const allocator_type &alloc)
 
 shared_cow_string (std::size_t size, boost::container::default_init_t, const allocator_type &alloc)
 
 shared_cow_string (const shared_cow_string &other)
 
 shared_cow_string (shared_cow_string &&other)
 
shared_cow_stringoperator= (const shared_cow_string &other)
 
shared_cow_stringoperator= (shared_cow_string &&other)
 
 ~shared_cow_string ()
 
void resize (std::size_t new_size, boost::container::default_init_t)
 
template<typename F >
void resize_and_fill (std::size_t new_size, F &&f)
 
void assign (const char *ptr, std::size_t size)
 
void assign (const unsigned char *ptr, std::size_t size)
 
const char * data () const
 
std::size_t size () const
 
const_iterator begin () const
 
const_iterator end () const
 
int compare (std::size_t start, std::size_t count, const char *other, std::size_t other_size) const
 
bool operator== (const shared_cow_string &rhs) const
 
bool operator!= (const shared_cow_string &rhs) const
 
const allocator_typeget_allocator () const
 

Detailed Description

Definition at line 18 of file shared_cow_string.hpp.

Member Typedef Documentation

◆ allocator_type

◆ const_iterator

Definition at line 27 of file shared_cow_string.hpp.

◆ iterator

Definition at line 26 of file shared_cow_string.hpp.

Constructor & Destructor Documentation

◆ shared_cow_string() [1/6]

chainbase::shared_cow_string::shared_cow_string ( const allocator_type & alloc)
inlineexplicit

Definition at line 28 of file shared_cow_string.hpp.

28: _data(nullptr), _alloc(alloc) {}

◆ shared_cow_string() [2/6]

template<typename Iter >
chainbase::shared_cow_string::shared_cow_string ( Iter begin,
Iter end,
const allocator_type & alloc )
inlineexplicit

Definition at line 30 of file shared_cow_string.hpp.

30 : shared_cow_string(alloc) {
31 std::size_t size = std::distance(begin, end);
32 impl* new_data = (impl*)&*_alloc.allocate(sizeof(impl) + size + 1);
33 new_data->reference_count = 1;
34 new_data->size = size;
35 std::copy(begin, end, new_data->data);
36 new_data->data[size] = '\0';
37 _data = new_data;
38 }
shared_cow_string(const allocator_type &alloc)
Here is the call graph for this function:

◆ shared_cow_string() [3/6]

chainbase::shared_cow_string::shared_cow_string ( const char * ptr,
std::size_t size,
const allocator_type & alloc )
inlineexplicit

Definition at line 39 of file shared_cow_string.hpp.

39 : shared_cow_string(alloc) {
40 impl* new_data = (impl*)&*_alloc.allocate(sizeof(impl) + size + 1);
41 new_data->reference_count = 1;
42 new_data->size = size;
43 std::memcpy(new_data->data, ptr, size);
44 new_data->data[size] = '\0';
45 _data = new_data;
46 }
Here is the call graph for this function:

◆ shared_cow_string() [4/6]

chainbase::shared_cow_string::shared_cow_string ( std::size_t size,
boost::container::default_init_t ,
const allocator_type & alloc )
inlineexplicit

Definition at line 47 of file shared_cow_string.hpp.

47 : shared_cow_string(alloc) {
48 impl* new_data = (impl*)&*_alloc.allocate(sizeof(impl) + size + 1);
49 new_data->reference_count = 1;
50 new_data->size = size;
51 new_data->data[size] = '\0';
52 _data = new_data;
53 }
Here is the call graph for this function:

◆ shared_cow_string() [5/6]

chainbase::shared_cow_string::shared_cow_string ( const shared_cow_string & other)
inline

Definition at line 54 of file shared_cow_string.hpp.

54 : _data(other._data), _alloc(other._alloc) {
55 if(_data != nullptr) {
56 ++_data->reference_count;
57 }
58 }

◆ shared_cow_string() [6/6]

chainbase::shared_cow_string::shared_cow_string ( shared_cow_string && other)
inline

Definition at line 59 of file shared_cow_string.hpp.

59 : _data(other._data), _alloc(other._alloc) {
60 other._data = nullptr;
61 }

◆ ~shared_cow_string()

chainbase::shared_cow_string::~shared_cow_string ( )
inline

Definition at line 74 of file shared_cow_string.hpp.

74 {
75 dec_refcount();
76 }

Member Function Documentation

◆ assign() [1/2]

void chainbase::shared_cow_string::assign ( const char * ptr,
std::size_t size )
inline

Definition at line 90 of file shared_cow_string.hpp.

90 {
91 impl* new_data = (impl*)&*_alloc.allocate(sizeof(impl) + size + 1);
92 new_data->reference_count = 1;
93 new_data->size = size;
94 if(size)
95 std::memcpy(new_data->data, ptr, size);
96 new_data->data[size] = '\0';
97 dec_refcount();
98 _data = new_data;
99 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign() [2/2]

void chainbase::shared_cow_string::assign ( const unsigned char * ptr,
std::size_t size )
inline

Definition at line 100 of file shared_cow_string.hpp.

100 {
101 assign((char*)ptr, size);
102 }
void assign(const char *ptr, std::size_t size)
Here is the call graph for this function:

◆ begin()

const_iterator chainbase::shared_cow_string::begin ( ) const
inline

Definition at line 111 of file shared_cow_string.hpp.

111{ return data(); }
Here is the call graph for this function:

◆ compare()

int chainbase::shared_cow_string::compare ( std::size_t start,
std::size_t count,
const char * other,
std::size_t other_size ) const
inline

Definition at line 116 of file shared_cow_string.hpp.

116 {
117 std::size_t sz = size();
118 if(start > sz) BOOST_THROW_EXCEPTION(std::out_of_range{"shared_cow_string::compare"});
119 count = std::min(count, sz - start);
120 std::size_t cmp_len = std::min(count, other_size);
121 const char* start_ptr = data() + start;
122 int result = std::char_traits<char>::compare(start_ptr, other, cmp_len);
123 if (result != 0) return result;
124 else if (count < other_size) return -1;
125 else if(count > other_size) return 1;
126 else return 0;
127 }
int * count
Here is the call graph for this function:

◆ data()

const char * chainbase::shared_cow_string::data ( ) const
inline

Definition at line 103 of file shared_cow_string.hpp.

103 {
104 if (_data) return _data->data;
105 else return nullptr;
106 }
Here is the caller graph for this function:

◆ end()

const_iterator chainbase::shared_cow_string::end ( ) const
inline

Definition at line 112 of file shared_cow_string.hpp.

112 {
113 if (_data) return _data->data + _data->size;
114 else return nullptr;
115 }

◆ get_allocator()

const allocator_type & chainbase::shared_cow_string::get_allocator ( ) const
inline

Definition at line 132 of file shared_cow_string.hpp.

132{ return _alloc; }
Here is the caller graph for this function:

◆ operator!=()

bool chainbase::shared_cow_string::operator!= ( const shared_cow_string & rhs) const
inline

Definition at line 131 of file shared_cow_string.hpp.

131{ return !(*this == rhs); }

◆ operator=() [1/2]

shared_cow_string & chainbase::shared_cow_string::operator= ( const shared_cow_string & other)
inline

Definition at line 62 of file shared_cow_string.hpp.

62 {
63 *this = shared_cow_string{other};
64 return *this;
65 }

◆ operator=() [2/2]

shared_cow_string & chainbase::shared_cow_string::operator= ( shared_cow_string && other)
inline

Definition at line 66 of file shared_cow_string.hpp.

66 {
67 if (this != &other) {
68 dec_refcount();
69 _data = other._data;
70 other._data = nullptr;
71 }
72 return *this;
73 }

◆ operator==()

bool chainbase::shared_cow_string::operator== ( const shared_cow_string & rhs) const
inline

Definition at line 128 of file shared_cow_string.hpp.

128 {
129 return size() == rhs.size() && std::memcmp(data(), rhs.data(), size()) == 0;
130 }
Here is the call graph for this function:

◆ resize()

void chainbase::shared_cow_string::resize ( std::size_t new_size,
boost::container::default_init_t  )
inline

Definition at line 77 of file shared_cow_string.hpp.

77 {
78 impl* new_data = (impl*)&*_alloc.allocate(sizeof(impl) + new_size + 1);
79 new_data->reference_count = 1;
80 new_data->size = new_size;
81 new_data->data[new_size] = '\0';
82 dec_refcount();
83 _data = new_data;
84 }
Here is the caller graph for this function:

◆ resize_and_fill()

template<typename F >
void chainbase::shared_cow_string::resize_and_fill ( std::size_t new_size,
F && f )
inline

Definition at line 86 of file shared_cow_string.hpp.

86 {
87 resize(new_size, boost::container::default_init);
88 static_cast<F&&>(f)(_data->data, new_size);
89 }
void resize(std::size_t new_size, boost::container::default_init_t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

std::size_t chainbase::shared_cow_string::size ( ) const
inline

Definition at line 107 of file shared_cow_string.hpp.

107 {
108 if (_data) return _data->size;
109 else return 0;
110 }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: