PIP 5.6.1
Platform-Independent Primitives
Files | Classes | Functions
Containers

Container classes and related helpers. More...

Files

file  picontainers.h
 Base macros for generic containers.
 
file  picontainersmodule.h
 Umbrella header for the Containers module.
 
file  pideque.h
 Declares PIDeque.
 
file  pimap.h
 Declares PIMap.
 
file  pipair.h
 Declares PIPair.
 
file  piqueue.h
 Declares PIQueue.
 
file  piset.h
 Declares PISet.
 
file  pistack.h
 Declares PIStack.
 
file  pivector.h
 Declares PIVector.
 
file  pivector2d.h
 Declares PIVector2D.
 

Classes

class  PIVector2D< T >
 2D array container.This class is used to store a 2D array of elements of any type as a single continuous block of memory (a plain PIVector). Elements can be accessed using the [][] operators, where the first index is the row and the second is the column. Rows can be manipulated as PIVector objects, allowing modification of individual elements or assignment of entire rows. You cannot directly add or remove elements to change the dimensions of the array after construction (use resize(), addRow(), removeRow(), removeColumn() instead), but you can modify the values of existing elements. More...
 
class  PIDeque< T >
 Sequence two-way linear container - dynamic size array of any type. More...
 
class  PIMap< Key, T >
 Map of unique keys and associated values. More...
 
class  PIMapIteratorConst< Key, T >
 Java-style iterator for PIMap. More...
 
class  PIMapIteratorConstReverse< Key, T >
 Java-style reverse iterator for PIMap. More...
 
class  PIMapIterator< Key, T >
 Java-style iterator for PIMap. More...
 
class  PIMapIteratorReverse< Key, T >
 Java-style reverse iterator for PIMap. More...
 
class  PIPair< Type0, Type1 >
 Class template that provides a way to store two heterogeneous objects as a single unit. More...
 
class  PIQueue< T >
 Queue container built on top of PIDeque. More...
 
class  PISet< T >
 Set of unique values. More...
 
class  PIStack< T >
 A container class inherited from the PIVector with stack functionality. More...
 
class  PIVector< T >
 Sequence linear container - dynamic size array of any type. More...
 

Functions

template<typename T >
PICout operator<< (PICout s, const PIVector2D< T > &v)
 Output operator for PIVector2D to PICout.
 
template<typename T >
PICout operator<< (PICout s, const PIVector2D< T > &v)
 Output operator for PIVector2D to PICout.
 

Detailed Description

Container classes and related helpers.

Building with CMake

find_package(PIP REQUIRED)
target_link_libraries([target] PIP)

Content

Class Description
PIVector Linear array, fast back insert
PIDeque Linear array, fast back and front insert
PIMap Dictionary container, key/value array
PISet Set container
PIStack Stack
PIQueue Queue
PIPair Pair
PIVector2D Linear 2D rectangle array

STL-Style Iterators

They are compatible with Qt's and STL's generic algorithms and are optimized for speed.

For each container class, there are two STL-style iterator types: one that provides read-only access and one that provides read-write access. Read-only iterators should be used wherever possible because they are faster than read-write iterators. Read-only iterator - const_iterator. Read-write iterator - iterator.

The API of the STL iterators is modelled on pointers in an array. For example, the ++ operator advances the iterator to the next item, and the * operator returns the item that the iterator points to. The iterator type is just a typedef for T *, and the const_iterator type is just a typedef for const T *. STL-style iterators point directly at items. The begin() function of a container returns an iterator that points to the first item in the container. The end() function of a container returns an iterator to the imaginary item one position past the last item in the container. end() marks an invalid position; it must never be dereferenced. It is typically used in a loop's break condition.

Example:

for (PIVector<int>::const_iterator i = v.begin(); i != v.end(); ++i) piCout << *i;
std::for_each(v.begin(), v.end(), [](int n){std::cout << n << ' ';});
Sequence linear container - dynamic size array of any type.
Definition: pivector.h:118
iterator begin()
Iterator to the first element.
Definition: pivector.h:553
#define piCout
Definition: picout.h:36

If the list is empty, begin() equals end(), so we never execute the loop.

iterators

The following table summarizes the STL-style iterators' API:

Expression Behavior
*i Returns the current item
++i Advances the iterator to the next item
i += n Advances the iterator by n items
--i Moves the iterator back by one item
i -= n Moves the iterator back by n items
i - j Returns the number of items between iterators i and j

The ++ and -- operators are available both as prefix (++i, --i) and postfix (i++, i--) operators. The prefix versions modify the iterators and return a reference to the modified iterator; the postfix versions take a copy of the iterator before they modify it, and return that copy. In expressions where the return value is ignored, we recommend that you use the prefix operators (++i, --i), as these are slightly faster. For non-const iterator types, the return value of the unary * operator can be used on the left side of the assignment operator.