rapidyaml  0.12.0
parse and emit YAML, and do it fast
c4::yml::extra::string_vector Struct Reference

a string collection used by the event handler. More...

#include <string.hpp>

Public Types

enum  : id_type { sso_size = RYML_STRING_LIST_SSO_SIZE }
 

Public Member Functions

 string_vector ()
 
 ~string_vector () noexcept
 
 string_vector (string_vector const &that) RYML_NOEXCEPT
 
 string_vector (string_vector &&that) noexcept
 
string_vectoroperator= (string_vector const &that) RYML_NOEXCEPT
 
string_vectoroperator= (string_vector &&that) noexcept
 
void _free ()
 
id_type size () const noexcept
 
id_type capacity () const noexcept
 
void clear ()
 
void resize (id_type sz)
 
void reserve (id_type sz)
 
stringemplace_back ()
 
stringoperator[] (id_type i)
 
string const & operator[] (id_type i) const
 

Public Attributes

union {
   string   m_buf [sso_size]
 
   char   m_buf_bytes [sso_size *sizeof(string)]
 
}; 
 
stringm_arr
 
id_type m_size
 
id_type m_capacity
 

Detailed Description

a string collection used by the event handler.

using this instead of std::vector spares the dependency on the standard library.

Definition at line 268 of file string.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : id_type
Enumerator
sso_size 

Definition at line 270 of file string.hpp.

RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:244
#define RYML_STRING_LIST_SSO_SIZE
Definition: string.hpp:21

Constructor & Destructor Documentation

◆ string_vector() [1/3]

c4::yml::extra::string_vector::string_vector ( )
inline

Definition at line 281 of file string.hpp.

282  : m_arr(m_buf)
283  , m_size(0)
285  {}
string m_buf[sso_size]
Definition: string.hpp:272

◆ ~string_vector()

c4::yml::extra::string_vector::~string_vector ( )
inlinenoexcept

Definition at line 286 of file string.hpp.

287  {
288  _free();
289  }

References _free().

◆ string_vector() [2/3]

c4::yml::extra::string_vector::string_vector ( string_vector const &  that)
inline

Definition at line 291 of file string.hpp.

291  : string_vector()
292  {
293  reserve(that.m_size);
294  m_size = that.m_size;
295  for(id_type i = 0; i < that.m_size; ++i)
296  new ((void*)(m_arr+i)) string(that.m_arr[i]);
297  }
void reserve(id_type sz)
Definition: string.hpp:370

References m_arr, m_size, and reserve().

◆ string_vector() [3/3]

c4::yml::extra::string_vector::string_vector ( string_vector &&  that)
inlinenoexcept

Definition at line 299 of file string.hpp.

299  : string_vector()
300  {
301  reserve(that.m_size);
302  m_size = that.m_size;
303  for(id_type i = 0; i < that.m_size; ++i)
304  new ((void*)(m_arr+i)) string(std::move(that.m_arr[i]));
305  that.~string_vector();
306  }

References m_arr, m_size, and reserve().

Member Function Documentation

◆ operator=() [1/2]

string_vector& c4::yml::extra::string_vector::operator= ( string_vector const &  that)
inline

Definition at line 308 of file string.hpp.

309  {
310  _free();
311  reserve(that.m_size);
312  for(id_type i = 0; i < that.m_size; ++i)
313  m_arr[i].operator=(that.m_arr[i]);
314  m_size = that.m_size;
315  return *this;
316  }

References _free(), m_arr, m_size, and reserve().

◆ operator=() [2/2]

string_vector& c4::yml::extra::string_vector::operator= ( string_vector &&  that)
inlinenoexcept

Definition at line 318 of file string.hpp.

319  {
320  _free();
321  reserve(that.m_size);
322  for(id_type i = 0; i < that.m_size; ++i)
323  m_arr[i].operator=(std::move(that.m_arr[i]));
324  m_size = that.m_size;
325  that.~string_vector();
326  return *this;
327  }

References _free(), m_arr, m_size, and reserve().

◆ _free()

void c4::yml::extra::string_vector::_free ( )
inline

Definition at line 329 of file string.hpp.

330  {
331  _RYML_ASSERT_BASIC(m_arr != nullptr); // this structure cannot be memset() to zero
332  for(id_type i = 0; i < m_size; ++i)
333  m_arr[i].~string();
334  if(m_arr != m_buf)
335  {
336  _RYML_CB_FREE(get_callbacks(), m_arr, string, (size_t)m_capacity);
337  m_arr = m_buf;
339  }
340  _RYML_ASSERT_BASIC(m_capacity == sso_size);
341  m_size = 0;
342  }
Callbacks const & get_callbacks()
get the global callbacks
Definition: common.cpp:94

References c4::yml::get_callbacks(), m_arr, m_buf, m_capacity, m_size, and sso_size.

◆ size()

id_type c4::yml::extra::string_vector::size ( ) const
inlinenoexcept

Definition at line 346 of file string.hpp.

346 { return m_size; }

References m_size.

◆ capacity()

id_type c4::yml::extra::string_vector::capacity ( ) const
inlinenoexcept

Definition at line 347 of file string.hpp.

347 { return m_capacity; }

References m_capacity.

◆ clear()

void c4::yml::extra::string_vector::clear ( )
inline

Definition at line 349 of file string.hpp.

350  {
351  resize(0);
352  }
void resize(id_type sz)
Definition: string.hpp:354

References resize().

◆ resize()

void c4::yml::extra::string_vector::resize ( id_type  sz)
inline

Definition at line 354 of file string.hpp.

355  {
356  reserve(sz);
357  if(sz >= m_size)
358  {
359  for(id_type i = m_size; i < sz; ++i)
360  new ((void*)(m_arr + i)) string();
361  }
362  else
363  {
364  for(id_type i = sz; i < m_size; ++i)
365  m_arr[i].~string();
366  }
367  m_size = sz;
368  }

References m_arr, m_size, and reserve().

◆ reserve()

void c4::yml::extra::string_vector::reserve ( id_type  sz)
inline

Definition at line 370 of file string.hpp.

371  {
372  if(sz <= m_capacity)
373  return;
375  cap = cap > sz ? cap : sz;
376  if(cap <= sso_size)
377  return;
378  Callbacks cb = get_callbacks();
379  string *buf = (string*) _RYML_CB_ALLOC(cb, string, cap);
380  for(id_type i = 0; i < m_size; ++i)
381  new ((void*)(buf + i)) string(std::move(m_arr[i]));
382  if(m_arr != m_buf)
383  {
384  _RYML_CB_FREE(cb, m_arr, string, m_size);
385  }
386  m_arr = buf;
387  m_capacity = cap;
388  }

References c4::yml::get_callbacks(), m_arr, m_buf, m_capacity, m_size, c4::yml::extra::string::sso_size, and sso_size.

◆ emplace_back()

string& c4::yml::extra::string_vector::emplace_back ( )
inline

Definition at line 392 of file string.hpp.

393  {
394  _RYML_ASSERT_BASIC(m_size < m_capacity);
395  if(m_size == m_capacity)
396  reserve(m_size + 1);
397  string& ret = m_arr[m_size++];
398  new ((void*)&ret) string();
399  return ret;
400  }

References m_arr, m_capacity, m_size, and reserve().

◆ operator[]() [1/2]

string& c4::yml::extra::string_vector::operator[] ( id_type  i)
inline

Definition at line 401 of file string.hpp.

402  {
403  _RYML_ASSERT_BASIC(m_size <= m_capacity);
404  _RYML_ASSERT_BASIC(i < m_size);
405  return m_arr[i];
406  }

References m_arr, m_capacity, and m_size.

◆ operator[]() [2/2]

string const& c4::yml::extra::string_vector::operator[] ( id_type  i) const
inline

Definition at line 407 of file string.hpp.

408  {
409  _RYML_ASSERT_BASIC(m_size <= m_capacity);
410  _RYML_ASSERT_BASIC(i < m_size);
411  return m_arr[i];
412  }

References m_arr, m_capacity, and m_size.

Member Data Documentation

◆ m_buf

string c4::yml::extra::string_vector::m_buf[sso_size]

Definition at line 272 of file string.hpp.

◆ m_buf_bytes

char c4::yml::extra::string_vector::m_buf_bytes[sso_size *sizeof(string)]

Definition at line 273 of file string.hpp.

◆ 

union { ... }

◆ m_arr

string* c4::yml::extra::string_vector::m_arr

Definition at line 275 of file string.hpp.

◆ m_size

id_type c4::yml::extra::string_vector::m_size

Definition at line 276 of file string.hpp.

◆ m_capacity

id_type c4::yml::extra::string_vector::m_capacity

Definition at line 277 of file string.hpp.


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