alternative Standard Libary  0.29.8
std::cow_string_storage< E, TAllocator > Template-Klassenreferenz

#include <cow_string_storage.hpp>

Öffentliche Typen

using value_type = E
 
using size_type = int
 
using allocator_type = TAllocator
 
using const_iterator = value_type *
 

Öffentliche Methoden

 cow_string_storage (const allocator_type &allocator)
 
 cow_string_storage (const value_type *str, const allocator_type &allocator)
 
 cow_string_storage (const value_type *str, size_type len, const allocator_type &allocator)
 
 ow_string_storage (size_type len, const allocator_type &allocator)
 
 cow_string_storage (const cow_string_storage &rhs, const allocator_type &allocator)
 
 ~cow_string_storage ()
 
cow_string_storageoperator= (const cow_string_storage &rhs)
 
void assign (const value_type *str, size_type len)
 
void resize (size_type len)
 
void append (const value_type *str, size_type len)
 
const value_typec_str () const
 
size_type length () const
 
const allocator_typeget_allocator () const
 
value_typereserve (size_type capacity_hint)
 
void clear ()
 
void resize (size_type size)
 

Statische öffentliche Attribute

static const unsigned long kGranularity = 32
 

Geschützte Methoden

bool invariant () const
 
void make_unique (size_type capacity_hint)
 
E * get_data ()
 

Ausführliche Beschreibung

template<typename E, class TAllocator>
class std::cow_string_storage< E, TAllocator >

Dokumentation der benutzerdefinierten Datentypen

◆ allocator_type

template<typename E , class TAllocator >
using std::cow_string_storage< E, TAllocator >::allocator_type = TAllocator

◆ const_iterator

template<typename E , class TAllocator >
using std::cow_string_storage< E, TAllocator >::const_iterator = value_type*

◆ size_type

template<typename E , class TAllocator >
using std::cow_string_storage< E, TAllocator >::size_type = int

◆ value_type

template<typename E , class TAllocator >
using std::cow_string_storage< E, TAllocator >::value_type = E

Beschreibung der Konstruktoren und Destruktoren

◆ cow_string_storage() [1/4]

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::cow_string_storage ( const allocator_type allocator)
inlineexplicit
79  : m_allocator(allocator)
80  {
81  construct_string(0);
82  }

◆ cow_string_storage() [2/4]

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::cow_string_storage ( const value_type str,
const allocator_type allocator 
)
inline
84  : m_allocator(allocator)
85  {
86  const int len = strlen(str);
87  construct_string(len);
88  Sys::MemCpy(m_data, str, len*sizeof(value_type));
89  assert(len < string_rep::kMaxCapacity);
90  get_rep()->size = static_cast<short>(len);
91  m_data[len] = 0;
92  }
E value_type
Definition: cow_string_storage.hpp:71
static const size_t kMaxCapacity
Definition: cow_string_storage.hpp:62
short size
Definition: cow_string_storage.hpp:58
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39
std::string str(T begin, T end)
Definition: utils.hpp:39

◆ cow_string_storage() [3/4]

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::cow_string_storage ( const value_type str,
size_type  len,
const allocator_type allocator 
)
inline
94  : m_allocator(allocator)
95  {
96  construct_string(len);
97  Sys::MemCpy(m_data, str, len*sizeof(value_type));
98  assert(len < string_rep::kMaxCapacity);
99  get_rep()->size = static_cast<short>(len);
100  m_data[len] = 0;
101  }
E value_type
Definition: cow_string_storage.hpp:71
static const size_t kMaxCapacity
Definition: cow_string_storage.hpp:62
short size
Definition: cow_string_storage.hpp:58
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39
std::string str(T begin, T end)
Definition: utils.hpp:39

◆ cow_string_storage() [4/4]

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::cow_string_storage ( const cow_string_storage< E, TAllocator > &  rhs,
const allocator_type allocator 
)
inline
111  : m_data(rhs.m_data), m_allocator(allocator)
112  {
113  if (rhs.is_dynamic())
114  {
115  get_rep()->add_ref();
116  }
117  else
118  {
119  const int len = rhs.length();
120  construct_string(len);
121  Sys::MemCpy(m_data, rhs.c_str(), len*sizeof(value_type));
122  assert(len < string_rep::kMaxCapacity);
123  get_rep()->size = static_cast<short>(len);
124  m_data[len] = 0;
125  }
126  }
E value_type
Definition: cow_string_storage.hpp:71
static const size_t kMaxCapacity
Definition: cow_string_storage.hpp:62
void add_ref()
Definition: cow_string_storage.hpp:40
short size
Definition: cow_string_storage.hpp:58
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39

◆ ~cow_string_storage()

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::~cow_string_storage ( )
inline
128  {
129  if (!is_dynamic())
130  RDE_ASSERT(get_rep()->refs == 1);
131  release_string();
132  }

Dokumentation der Elementfunktionen

◆ append()

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::append ( const value_type str,
size_type  len 
)
inline
166  {
167  const size_type prevLen = length();
168  const size_type newCapacity = prevLen + len;
169  make_unique(newCapacity);
170  string_rep* rep = get_rep();
171  assert(rep->capacity >= short(newCapacity));
172  const size_type newLen = prevLen + len;
173  assert(short(newLen) <= rep->capacity);
174  Sys::MemCpy(m_data + prevLen, str, len * sizeof(value_type));
175  m_data[newLen] = 0;
176  rep->size = short(newLen);
177  }
E value_type
Definition: cow_string_storage.hpp:71
int size_type
Definition: cow_string_storage.hpp:72
void make_unique(size_type capacity_hint)
Definition: cow_string_storage.hpp:217
size_type length() const
Definition: cow_string_storage.hpp:183
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39
std::string str(T begin, T end)
Definition: utils.hpp:39

◆ assign()

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::assign ( const value_type str,
size_type  len 
)
inline
145  {
146  assert(str != m_data);
147  release_string();
148  construct_string(len);
149  Sys::MemCpy(m_data, str, len*sizeof(value_type));
150  get_rep()->size = short(len);
151  m_data[len] = 0;
152  }
E value_type
Definition: cow_string_storage.hpp:71
short size
Definition: cow_string_storage.hpp:58
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39
std::string str(T begin, T end)
Definition: utils.hpp:39

◆ c_str()

template<typename E , class TAllocator >
const value_type* std::cow_string_storage< E, TAllocator >::c_str ( ) const
inline
180  {
181  return m_data;
182  }

◆ clear()

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::clear ( )
inline
195  {
196  resize(0);
197  }
void resize(size_type len)
Definition: cow_string_storage.hpp:153

◆ get_allocator()

template<typename E , class TAllocator >
const allocator_type& std::cow_string_storage< E, TAllocator >::get_allocator ( ) const
inline
187 { return m_allocator; }

◆ get_data()

template<typename E , class TAllocator >
E* std::cow_string_storage< E, TAllocator >::get_data ( )
inlineprotected
257 { return m_data; }

◆ invariant()

template<typename E , class TAllocator >
bool std::cow_string_storage< E, TAllocator >::invariant ( ) const
inlineprotected
208  {
209  assert(m_data);
210  string_rep* rep = get_rep();
211  assert(rep->refs >= 1);
212  assert(rep->size <= rep->capacity);
213  if (length() != 0)
214  assert(m_data[length()] == 0);
215  return true;
216  }
size_type length() const
Definition: cow_string_storage.hpp:183

◆ length()

template<typename E , class TAllocator >
size_type std::cow_string_storage< E, TAllocator >::length ( ) const
inline
184  {
185  return get_rep()->size;
186  }
short size
Definition: cow_string_storage.hpp:58

◆ make_unique()

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::make_unique ( size_type  capacity_hint)
inlineprotected
218  {
219  string_rep* rep = get_rep();
220  assert(rep->refs >= 1);
221 
222  if (capacity_hint != 0)
223  {
224  ++capacity_hint;
225  capacity_hint = (capacity_hint+kGranularity-1) & ~(kGranularity-1);
226  if (capacity_hint < kGranularity)
227  capacity_hint = kGranularity;
228  }
229  assert(capacity_hint < string_rep::kMaxCapacity);
230  // Reallocate string only if we truly need to make it unique
231  // (it's shared) or if our current buffer is too small.
232  if (rep->refs > 1 || short(capacity_hint) > rep->capacity)
233  {
234  if (capacity_hint > 0)
235  {
236  const size_type toAlloc = sizeof(string_rep) + sizeof(value_type)*capacity_hint;
237  void* newMem = m_allocator.allocate(toAlloc);
238  string_rep* newRep = reinterpret_cast<string_rep*>(newMem);
239  newRep->init(short(capacity_hint));
240  value_type* newData = reinterpret_cast<value_type*>(newRep + 1);
241  Sys::MemCpy(newData, m_data, rep->size*sizeof(value_type));
242  newRep->size = rep->size;
243  newData[rep->size] = 0;
244  release_string();
245  m_data = newData;
246  }
247  else
248  {
249  release_string();
250  string_rep* rep = reinterpret_cast<string_rep*>(m_buffer);
251  rep->init();
252  m_data = reinterpret_cast<value_type*>(rep + 1);
253  *m_data = 0;
254  }
255  }
256  }
static const unsigned long kGranularity
Definition: cow_string_storage.hpp:76
E value_type
Definition: cow_string_storage.hpp:71
static const size_t kMaxCapacity
Definition: cow_string_storage.hpp:62
int size_type
Definition: cow_string_storage.hpp:72
static void MemCpy(void *to, const void *from, size_t bytes)
Definition: PLATFORM.cpp:39

◆ operator=()

template<typename E , class TAllocator >
cow_string_storage& std::cow_string_storage< E, TAllocator >::operator= ( const cow_string_storage< E, TAllocator > &  rhs)
inline
134  {
135  if (m_data != rhs.m_data)
136  {
137  release_string();
138  m_data = rhs.m_data;
139  get_rep()->add_ref();
140  }
141  return *this;
142  }
void add_ref()
Definition: cow_string_storage.hpp:40

◆ ow_string_storage()

template<typename E , class TAllocator >
std::cow_string_storage< E, TAllocator >::ow_string_storage ( size_type  len,
const allocator_type allocator 
)
inline
103  : m_allocator(allocator)
104  {
105  construct_string(len);
106  assert(len < string_rep::kMaxCapacity);
107  get_rep()->size = static_cast<short>(len);
108  m_data[len] = 0;
109  }
static const size_t kMaxCapacity
Definition: cow_string_storage.hpp:62
short size
Definition: cow_string_storage.hpp:58

◆ reserve()

template<typename E , class TAllocator >
value_type* std::cow_string_storage< E, TAllocator >::reserve ( size_type  capacity_hint)
inline
190  {
191  make_unique(capacity_hint);
192  return m_data;
193  }
void make_unique(size_type capacity_hint)
Definition: cow_string_storage.hpp:217

◆ resize() [1/2]

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::resize ( size_type  len)
inline
154  {
155  const size_type prevLen = length();
156  const size_type newCapacity = len;
157  make_unique(newCapacity);
158  string_rep* rep = get_rep();
159  assert(rep->capacity >= short(newCapacity));
160  const size_type newLen = prevLen + len;
161  assert(short(newLen) <= rep->capacity);
162  m_data[newLen] = 0;
163  rep->size = short(newLen);
164  }
int size_type
Definition: cow_string_storage.hpp:72
void make_unique(size_type capacity_hint)
Definition: cow_string_storage.hpp:217
size_type length() const
Definition: cow_string_storage.hpp:183

◆ resize() [2/2]

template<typename E , class TAllocator >
void std::cow_string_storage< E, TAllocator >::resize ( size_type  size)
inline
199  {
200  string_rep* rep = get_rep();
201  make_unique(size);
202  rep->size = (short)size;
203  m_data[size] = 0;
204  }
void make_unique(size_type capacity_hint)
Definition: cow_string_storage.hpp:217

Dokumentation der Datenelemente

◆ kGranularity

template<typename E , class TAllocator >
const unsigned long std::cow_string_storage< E, TAllocator >::kGranularity = 32
static

Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei: