Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
agg::pod_bvector< T, S > Class Template Reference

#include <src/agg/agg_array.h>

+ Inheritance diagram for agg::pod_bvector< T, S >:

Public Types

enum  block_scale_e { block_shift = S , block_size = 1 << block_shift , block_mask = block_size - 1 }
 
typedef T value_type
 

Public Member Functions

 ~pod_bvector ()
 
 pod_bvector ()
 
 pod_bvector (unsigned block_ptr_inc)
 
 pod_bvector (const pod_bvector< T, S > &v)
 
const pod_bvector< T, S > & operator= (const pod_bvector< T, S > &v)
 
void remove_all ()
 
void clear ()
 
void free_all ()
 
void free_tail (unsigned size)
 
void add (const T &val)
 
void push_back (const T &val)
 
void modify_last (const T &val)
 
void remove_last ()
 
int allocate_continuous_block (unsigned num_elements)
 
void add_array (const T *ptr, unsigned num_elem)
 
template<class DataAccessor >
void add_data (DataAccessor &data)
 
void cut_at (unsigned size)
 
unsigned size () const
 
const T & operator[] (unsigned i) const
 
T & operator[] (unsigned i)
 
const T & at (unsigned i) const
 
T & at (unsigned i)
 
value_at (unsigned i) const
 
const T & curr (unsigned idx) const
 
T & curr (unsigned idx)
 
const T & prev (unsigned idx) const
 
T & prev (unsigned idx)
 
const T & next (unsigned idx) const
 
T & next (unsigned idx)
 
const T & last () const
 
T & last ()
 
unsigned byte_size () const
 
void serialize (int8u *ptr) const
 
void deserialize (const int8u *data, unsigned byte_size)
 
void deserialize (unsigned start, const T &empty_val, const int8u *data, unsigned byte_size)
 
template<class ByteAccessor >
void deserialize (ByteAccessor data)
 
template<class ByteAccessor >
void deserialize (unsigned start, const T &empty_val, ByteAccessor data)
 
const T * block (unsigned nb) const
 

Private Member Functions

void allocate_block (unsigned nb)
 
T * data_ptr ()
 

Private Attributes

unsigned m_size
 
unsigned m_num_blocks
 
unsigned m_max_blocks
 
T ** m_blocks
 
unsigned m_block_ptr_inc
 

Detailed Description

template<class T, unsigned S = 6>
class agg::pod_bvector< T, S >

Member Typedef Documentation

◆ value_type

template<class T , unsigned S = 6>
typedef T agg::pod_bvector< T, S >::value_type

Member Enumeration Documentation

◆ block_scale_e

template<class T , unsigned S = 6>
enum agg::pod_bvector::block_scale_e
Enumerator
block_shift 
block_size 
block_mask 
330 {
331 block_shift = S,
332 block_size = 1 << block_shift,
334 };
@ block_size
Definition agg_array.h:332
@ block_shift
Definition agg_array.h:331
@ block_mask
Definition agg_array.h:333

Constructor & Destructor Documentation

◆ ~pod_bvector()

template<class T , unsigned S>
agg::pod_bvector< T, S >::~pod_bvector
515 {
516 if(m_num_blocks)
517 {
518 T** blk = m_blocks + m_num_blocks - 1;
519 while(m_num_blocks--)
520 {
522 --blk;
523 }
524 }
526 }
T ** m_blocks
Definition agg_array.h:508
unsigned m_num_blocks
Definition agg_array.h:506
unsigned m_max_blocks
Definition agg_array.h:507
static void deallocate(T *ptr, unsigned)
Definition agg_basics.h:39

References agg::pod_allocator< T >::deallocate().

+ Here is the call graph for this function:

◆ pod_bvector() [1/3]

template<class T , unsigned S>
agg::pod_bvector< T, S >::pod_bvector
552 :
553 m_size(0),
554 m_num_blocks(0),
555 m_max_blocks(0),
556 m_blocks(0),
558 {
559 }
unsigned m_block_ptr_inc
Definition agg_array.h:509
unsigned m_size
Definition agg_array.h:505

◆ pod_bvector() [2/3]

template<class T , unsigned S>
agg::pod_bvector< T, S >::pod_bvector ( unsigned  block_ptr_inc)
564 :
565 m_size(0),
566 m_num_blocks(0),
567 m_max_blocks(0),
568 m_blocks(0),
569 m_block_ptr_inc(block_ptr_inc)
570 {
571 }

◆ pod_bvector() [3/3]

template<class T , unsigned S>
agg::pod_bvector< T, S >::pod_bvector ( const pod_bvector< T, S > &  v)
576 :
577 m_size(v.m_size),
578 m_num_blocks(v.m_num_blocks),
579 m_max_blocks(v.m_max_blocks),
580 m_blocks(v.m_max_blocks ?
581 pod_allocator<T*>::allocate(v.m_max_blocks) :
582 0),
584 {
585 unsigned i;
586 for(i = 0; i < v.m_num_blocks; ++i)
587 {
589 memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
590 }
591 }
static T * allocate(unsigned num)
Definition agg_basics.h:38

References agg::pod_allocator< T >::allocate(), agg::pod_bvector< T, S >::block_size, agg::pod_bvector< T, S >::m_blocks, and agg::pod_bvector< T, S >::m_num_blocks.

+ Here is the call graph for this function:

Member Function Documentation

◆ add()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::add ( const T &  val)
inline
655 {
656 *data_ptr() = val;
657 ++m_size;
658 }
T * data_ptr()
Definition agg_array.h:640

Referenced by agg::pod_bvector< T, S >::add_array(), agg::scanline32_p8::add_cell(), agg::scanline32_p8::add_cells(), agg::pod_bvector< T, S >::add_data(), agg::scanline32_p8::add_span(), agg::pod_bvector< T, S >::deserialize(), and agg::pod_bvector< T, S >::push_back().

+ Here is the caller graph for this function:

◆ add_array()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::add_array ( const T *  ptr,
unsigned  num_elem 
)
inline
358 {
359 while(num_elem--)
360 {
361 add(*ptr++);
362 }
363 }
void add(const T &val)
Definition agg_array.h:654

References agg::pod_bvector< T, S >::add().

+ Here is the call graph for this function:

◆ add_data()

template<class T , unsigned S = 6>
template<class DataAccessor >
void agg::pod_bvector< T, S >::add_data ( DataAccessor &  data)
inline
366 {
367 while(data.size())
368 {
369 add(*data);
370 ++data;
371 }
372 }
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References agg::pod_bvector< T, S >::add().

+ Here is the call graph for this function:

◆ allocate_block()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::allocate_block ( unsigned  nb)
private
616 {
617 if(nb >= m_max_blocks)
618 {
620
621 if(m_blocks)
622 {
623 memcpy(new_blocks,
624 m_blocks,
625 m_num_blocks * sizeof(T*));
626
628 }
629 m_blocks = new_blocks;
631 }
633 m_num_blocks++;
634 }

References agg::pod_allocator< T >::allocate(), and agg::pod_allocator< T >::deallocate().

+ Here is the call graph for this function:

◆ allocate_continuous_block()

template<class T , unsigned S>
int agg::pod_bvector< T, S >::allocate_continuous_block ( unsigned  num_elements)
681 {
682 if(num_elements < block_size)
683 {
684 data_ptr(); // Allocate initial block if necessary
685 unsigned rest = block_size - (m_size & block_mask);
686 unsigned index;
687 if(num_elements <= rest)
688 {
689 // The rest of the block is good, we can use it
690 //-----------------
691 index = m_size;
692 m_size += num_elements;
693 return index;
694 }
695
696 // New block
697 //---------------
698 m_size += rest;
699 data_ptr();
700 index = m_size;
701 m_size += num_elements;
702 return index;
703 }
704 return -1; // Impossible to allocate
705 }

◆ at() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::at ( unsigned  i)
inline

◆ at() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::at ( unsigned  i) const
inline

◆ block()

template<class T , unsigned S = 6>
const T * agg::pod_bvector< T, S >::block ( unsigned  nb) const
inline
499{ return m_blocks[nb]; }

References agg::pod_bvector< T, S >::m_blocks.

◆ byte_size()

template<class T , unsigned S>
unsigned agg::pod_bvector< T, S >::byte_size
711 {
712 return m_size * sizeof(T);
713 }

◆ clear()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::clear ( )
inline
347{ m_size = 0; }

References agg::pod_bvector< T, S >::m_size.

◆ curr() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::curr ( unsigned  idx)
inline
412 {
413 return (*this)[idx];
414 }

◆ curr() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::curr ( unsigned  idx) const
inline
407 {
408 return (*this)[idx];
409 }

◆ cut_at()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::cut_at ( unsigned  size)
inline
375 {
376 if(size < m_size) m_size = size;
377 }
unsigned size() const
Definition agg_array.h:379

References agg::pod_bvector< T, S >::m_size, and agg::pod_bvector< T, S >::size().

+ Here is the call graph for this function:

◆ data_ptr()

template<class T , unsigned S>
T * agg::pod_bvector< T, S >::data_ptr
inlineprivate
641 {
642 unsigned nb = m_size >> block_shift;
643 if(nb >= m_num_blocks)
644 {
645 allocate_block(nb);
646 }
647 return m_blocks[nb] + (m_size & block_mask);
648 }
void allocate_block(unsigned nb)
Definition agg_array.h:615

Referenced by agg::pod_bvector< T, S >::deserialize(), and agg::pod_bvector< T, S >::deserialize().

+ Here is the caller graph for this function:

◆ deserialize() [1/4]

template<class T , unsigned S = 6>
template<class ByteAccessor >
void agg::pod_bvector< T, S >::deserialize ( ByteAccessor  data)
inline
454 {
455 remove_all();
456 unsigned elem_size = data.size() / sizeof(T);
457
458 for(unsigned i = 0; i < elem_size; ++i)
459 {
460 int8u* ptr = (int8u*)data_ptr();
461 for(unsigned j = 0; j < sizeof(T); ++j)
462 {
463 *ptr++ = *data;
464 ++data;
465 }
466 ++m_size;
467 }
468 }
void remove_all()
Definition agg_array.h:346
AGG_INT8U int8u
Definition agg_basics.h:120

References agg::pod_bvector< T, S >::data_ptr(), agg::pod_bvector< T, S >::m_size, and agg::pod_bvector< T, S >::remove_all().

+ Here is the call graph for this function:

◆ deserialize() [2/4]

template<class T , unsigned S>
void agg::pod_bvector< T, S >::deserialize ( const int8u data,
unsigned  byte_size 
)
731 {
732 remove_all();
733 byte_size /= sizeof(T);
734 for(unsigned i = 0; i < byte_size; ++i)
735 {
736 T* ptr = data_ptr();
737 memcpy(ptr, data, sizeof(T));
738 ++m_size;
739 data += sizeof(T);
740 }
741 }
unsigned byte_size() const
Definition agg_array.h:710

◆ deserialize() [3/4]

template<class T , unsigned S = 6>
template<class ByteAccessor >
void agg::pod_bvector< T, S >::deserialize ( unsigned  start,
const T &  empty_val,
ByteAccessor  data 
)
inline
472 {
473 while(m_size < start)
474 {
475 add(empty_val);
476 }
477
478 unsigned elem_size = data.size() / sizeof(T);
479 for(unsigned i = 0; i < elem_size; ++i)
480 {
481 int8u* ptr;
482 if(start + i < m_size)
483 {
484 ptr = (int8u*)(&((*this)[start + i]));
485 }
486 else
487 {
488 ptr = (int8u*)data_ptr();
489 ++m_size;
490 }
491 for(unsigned j = 0; j < sizeof(T); ++j)
492 {
493 *ptr++ = *data;
494 ++data;
495 }
496 }
497 }

References agg::pod_bvector< T, S >::add(), agg::pod_bvector< T, S >::data_ptr(), and agg::pod_bvector< T, S >::m_size.

+ Here is the call graph for this function:

◆ deserialize() [4/4]

template<class T , unsigned S>
void agg::pod_bvector< T, S >::deserialize ( unsigned  start,
const T &  empty_val,
const int8u data,
unsigned  byte_size 
)
749 {
750 while(m_size < start)
751 {
752 add(empty_val);
753 }
754
755 byte_size /= sizeof(T);
756 for(unsigned i = 0; i < byte_size; ++i)
757 {
758 if(start + i < m_size)
759 {
760 memcpy(&((*this)[start + i]), data, sizeof(T));
761 }
762 else
763 {
764 T* ptr = data_ptr();
765 memcpy(ptr, data, sizeof(T));
766 ++m_size;
767 }
768 data += sizeof(T);
769 }
770 }

◆ free_all()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::free_all ( )
inline
348{ free_tail(0); }
void free_tail(unsigned size)
Definition agg_array.h:531

References agg::pod_bvector< T, S >::free_tail().

+ Here is the call graph for this function:

◆ free_tail()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::free_tail ( unsigned  size)
532 {
533 if(size < m_size)
534 {
535 unsigned nb = (size + block_mask) >> block_shift;
536 while(m_num_blocks > nb)
537 {
539 }
540 if(m_num_blocks == 0)
541 {
543 m_blocks = 0;
544 m_max_blocks = 0;
545 }
546 m_size = size;
547 }
548 }

References agg::pod_allocator< T >::deallocate().

Referenced by agg::pod_bvector< T, S >::free_all().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ last() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::last ( )
inline
442 {
443 return (*this)[m_size - 1];
444 }

References agg::pod_bvector< T, S >::m_size.

◆ last() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::last ( ) const
inline
437 {
438 return (*this)[m_size - 1];
439 }

References agg::pod_bvector< T, S >::m_size.

Referenced by agg::scanline32_p8::add_cell(), agg::scanline32_p8::add_cells(), and agg::scanline32_p8::add_span().

+ Here is the caller graph for this function:

◆ modify_last()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::modify_last ( const T &  val)
672 {
673 remove_last();
674 add(val);
675 }
void remove_last()
Definition agg_array.h:663

◆ next() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::next ( unsigned  idx)
inline
432 {
433 return (*this)[(idx + 1) % m_size];
434 }

References agg::pod_bvector< T, S >::m_size.

◆ next() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::next ( unsigned  idx) const
inline
427 {
428 return (*this)[(idx + 1) % m_size];
429 }

References agg::pod_bvector< T, S >::m_size.

◆ operator=()

template<class T , unsigned S>
const pod_bvector< T, S > & agg::pod_bvector< T, S >::operator= ( const pod_bvector< T, S > &  v)
598 {
599 unsigned i;
600 for(i = m_num_blocks; i < v.m_num_blocks; ++i)
601 {
603 }
604 for(i = 0; i < v.m_num_blocks; ++i)
605 {
606 memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
607 }
608 m_size = v.m_size;
609 return *this;
610 }

References agg::pod_bvector< T, S >::m_blocks, agg::pod_bvector< T, S >::m_num_blocks, and agg::pod_bvector< T, S >::m_size.

◆ operator[]() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::operator[] ( unsigned  i)
inline

◆ operator[]() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::operator[] ( unsigned  i) const
inline

◆ prev() [1/2]

template<class T , unsigned S = 6>
T & agg::pod_bvector< T, S >::prev ( unsigned  idx)
inline
422 {
423 return (*this)[(idx + m_size - 1) % m_size];
424 }

References agg::pod_bvector< T, S >::m_size.

◆ prev() [2/2]

template<class T , unsigned S = 6>
const T & agg::pod_bvector< T, S >::prev ( unsigned  idx) const
inline
417 {
418 return (*this)[(idx + m_size - 1) % m_size];
419 }

References agg::pod_bvector< T, S >::m_size.

◆ push_back()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::push_back ( const T &  val)
inline
351{ add(val); }

References agg::pod_bvector< T, S >::add().

+ Here is the call graph for this function:

◆ remove_all()

template<class T , unsigned S = 6>
void agg::pod_bvector< T, S >::remove_all ( )
inline
346{ m_size = 0; }

References agg::pod_bvector< T, S >::m_size.

Referenced by agg::pod_bvector< T, S >::deserialize(), agg::scanline32_p8::reset(), and agg::scanline32_p8::reset_spans().

+ Here is the caller graph for this function:

◆ remove_last()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::remove_last
inline
664 {
665 if(m_size) --m_size;
666 }

◆ serialize()

template<class T , unsigned S>
void agg::pod_bvector< T, S >::serialize ( int8u ptr) const
719 {
720 unsigned i;
721 for(i = 0; i < m_size; i++)
722 {
723 memcpy(ptr, &(*this)[i], sizeof(T));
724 ptr += sizeof(T);
725 }
726 }

◆ size()

template<class T , unsigned S = 6>
unsigned agg::pod_bvector< T, S >::size ( ) const
inline
379{ return m_size; }

References agg::pod_bvector< T, S >::m_size.

Referenced by agg::scanline32_p8::add_cell(), agg::scanline32_p8::add_cells(), agg::scanline32_p8::add_span(), agg::pod_bvector< T, S >::cut_at(), and agg::scanline32_p8::num_spans().

+ Here is the caller graph for this function:

◆ value_at()

template<class T , unsigned S = 6>
T agg::pod_bvector< T, S >::value_at ( unsigned  i) const
inline

Member Data Documentation

◆ m_block_ptr_inc

template<class T , unsigned S = 6>
unsigned agg::pod_bvector< T, S >::m_block_ptr_inc
private

◆ m_blocks

◆ m_max_blocks

template<class T , unsigned S = 6>
unsigned agg::pod_bvector< T, S >::m_max_blocks
private

◆ m_num_blocks

template<class T , unsigned S = 6>
unsigned agg::pod_bvector< T, S >::m_num_blocks
private

◆ m_size


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