InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2Vector< T, Allocator > Class Template Reference

#include <K2Vector.h>

Inheritance diagram for K2Vector< T, Allocator >:
K2Internals::K2VectorBase< T, Allocator >PMUnknownRefList

Public Member Functions

 K2Vector ()
 
 K2Vector (typename Allocator::size_type count, const T &value)
 
 K2Vector (const K2Vector &rhs)=default
 
 K2Vector (K2Vector &&rhs) noexcept=default
 
K2Vectoroperator= (const K2Vector &rhs)=default
 
K2Vectoroperator= (K2Vector &&rhs) noexcept=default
 
template<class InputIterator >
 K2Vector (InputIterator first, InputIterator last, const Allocator &a)
 
template<class InputIterator >
 K2Vector (InputIterator first, InputIterator last)
 
void swap (K2Vector &other) noexcept
 
- Public Member Functions inherited from K2Internals::K2VectorBase< T, Allocator >
 K2VectorBase (const Allocator &a=Allocator())
 
 K2VectorBase (size_type count, const T &value, const Allocator &a=Allocator())
 
template<class InputIterator >
 K2VectorBase (InputIterator first, InputIterator last, const Allocator &a)
 
template<class InputIterator >
 K2VectorBase (InputIterator first, InputIterator last)
 
void initialize (size_type count, const T &value)
 
void fill_assign (size_type, const T &)
 
void fill_insert (iterator, size_type, const T &)
 
 K2VectorBase (const K2VectorBase &rhs)
 
 K2VectorBase (K2VectorBase &&rhs) noexcept
 
void CopyConstructHelper (const K2VectorBase &rhs)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_type size () const
 
size_type max_size () const
 
size_type capacity () const
 
bool16 empty () const
 
allocator_type get_allocator () const
 
K2VectorBaseoperator= (const K2VectorBase &rhs)
 
K2VectorBaseoperator= (K2VectorBase &&rhs) noexcept
 
void reserve (size_type capacity)
 
template<class InputIter >
void assign (InputIter first, InputIter last)
 
void assign (size_type count, const T &u)
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
const_reference at (size_type i) const
 
reference at (size_type i)
 
reference front ()
 
const_reference front () const
 
reference back ()
 
const_reference back () const
 
void push_back (const T &x)
 
void pop_back ()
 
iterator insert (iterator position, const T &x)
 
void insert (iterator position, size_type n, const T &x)
 
template<class InputIter >
void insert (iterator pos, InputIter first, InputIter last)
 
iterator erase (iterator position)
 
iterator erase (iterator first, iterator last)
 
void swap (K2VectorBase &) noexcept
 
void clear ()
 
void resize (size_type newsize, const T &value)
 
void DoCleanup ()
 
size_type DoGetCapacity (size_type newLength)
 
void DoReset (pointer newData, size_type newLength, size_type newCap)
 

Static Public Member Functions

static Method ForceInstantiation (int n)
 

Additional Inherited Members

- Public Types inherited from K2Internals::K2VectorBase< T, Allocator >
typedef object_type data_type
 
typedef T value_type
 
typedef value_type * pointer
 
typedef const value_type * const_pointer
 
typedef value_type * iterator
 
typedef const value_type * const_iterator
 
typedef value_type & reference
 
typedef const value_type & const_reference
 
typedef uint32 size_type
 
typedef std::ptrdiff_t difference_type
 
typedef Allocator allocator_type
 
typedef K2Reverse_iterator
< iterator, value_type,
difference_type, pointer,
reference > 
reverse_iterator
 
typedef K2Reverse_iterator
< const_iterator, value_type,
difference_type, const_pointer,
const_reference > 
const_reverse_iterator
 

Detailed Description

template<class T, class Allocator = K2Allocator<T>>
class K2Vector< T, Allocator >

K2Vector is an implementation of STL's vector class.

Summary: There are three differences between K2Vector and std::vector:

1) the K2Vector(uint32) ctor reserves space instead of resizing the array;

2) a number of deprecated methods have been added for backward compatibility;

and 3) K2Vector distinguishes between base types (no copy constructor needed) and object types (need copy constructor) - for element copying performance reasons, using two typedefs that you can use in the public section of your data structures:

typedef object_type data_type;

and

typedef base_type datatype;

Which you choose depends upon whether your struct or class includes any data member that itself requires construction. If so then choose object_type; otherwise choose base_type. If you choose base_type, this naturally means that your object has become fragile because somebody later might extend your class by adding data members that require construction, yet they might forget to change the typedef. On the other hand, if object construction is not required then base_type is much faster.

So, why do we need to define our own vector class? The problem with the compiler provided STL implementations is that they are not interface classes and we have no control over the implementation. So, if an interface in Public returns a reference to a std::vector a plugin compiled with a different version of the compiler may experience difficulties since the internals of the vector may have changed.

Constructor & Destructor Documentation

template<class T, class Allocator = K2Allocator<T>>
K2Vector< T, Allocator >::K2Vector()
inlineexplicit

Default constructor. Creates an empty vector.

template<class T, class Allocator = K2Allocator<T>>
K2Vector< T, Allocator >::K2Vector(typename Allocator::size_type count,
const T & value 
)
inline

Constructs a vector initialized with <count> copies of element

.

Parameters
count[IN] - the number of copies of the specified element.
value[IN] - the element used for initialization.
template<class T, class Allocator = K2Allocator<T>>
K2Vector< T, Allocator >::K2Vector(const K2Vector< T, Allocator > & rhs)
default

Copy constructor. Creates a new vector as a copy of another vector of the same type (all elements are copied).

Parameters
rhs[IN] - the source vector to be copied.
template<class T, class Allocator = K2Allocator<T>>
template<class InputIterator >
K2Vector< T, Allocator >::K2Vector(InputIterator first,
InputIterator last,
const Allocator & a 
)
inline

Creates a vector that is initialized with all the elements of the range [first, last).

Parameters
first[IN] - iterator that points to the first element in the source sequence.
last[IN] - iterator that points AFTER the last element to be copied.
a[IN] - allocator to be used.
template<class T, class Allocator = K2Allocator<T>>
template<class InputIterator >
K2Vector< T, Allocator >::K2Vector(InputIterator first,
InputIterator last 
)
inline

Creates a vector that is initialized with all the elements of the range [first, last).

Parameters
first[IN] - iterator that points to the first element in the source sequence.
last[IN] - iterator that points AFTER the last element to be copied.