libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
crn::Vector Class Reference

Data vector class. More...

#include <CRNVector.h>

+ Inheritance diagram for crn::Vector:
+ Collaboration diagram for crn::Vector:

Public Member Functions

 Vector ()
 Default constructor. More...
 
virtual ~Vector () override
 Destructor. More...
 
 Vector (const Vector &)
 
 Vector (Vector &&)=default
 
Vectoroperator= (const Vector &)
 
Vectoroperator= (Vector &&)=default
 
size_t Size () const noexcept
 Returns the number of data objects in the vector. More...
 
bool IsEmpty () const noexcept
 Tests if the vector is empty. More...
 
SObject & operator[] (size_t i)
 Returns an object from index (unsafe) More...
 
SCObject operator[] (size_t i) const
 Returns an object from index (unsafe) More...
 
SObject & At (size_t i)
 Returns an object from index (unsafe) More...
 
SCObject At (size_t i) const
 Returns an object from index (unsafe) More...
 
SObject & Front ()
 Returns a reference to the first element. More...
 
SCObject Front () const
 Returns a reference to the first element. More...
 
SObject & Back ()
 Returns a reference to the last element. More...
 
SCObject Back () const
 Returns a reference to the last element. More...
 
bool Contains (const SCObject &o) const
 Checks of the object is in the vector. More...
 
void PushBack (const SObject &d)
 Adds an object at the end of the vector. More...
 
void Insert (const SObject &d, size_t pos)
 Inserts an object at a given position. More...
 
void ReorderFrom (const std::vector< size_t > &from)
 Reorders the elements. More...
 
void ReorderTo (const std::vector< size_t > &to)
 Reorders the elements. More...
 
void PopBack ()
 Removes the last element. More...
 
void Remove (size_t index)
 Removes an element (safe) More...
 
void Remove (const SCObject &obj)
 Removes an element (safe) More...
 
void Clear () noexcept
 Empties the vector. More...
 
iterator begin ()
 Returns an iterator to the first element. More...
 
iterator end ()
 Returns a iterator to the end of the list. More...
 
const_iterator begin () const
 Returns a const iterator to the first element. More...
 
const_iterator end () const
 Returns a const iterator to the end of the list. More...
 
const_iterator cbegin () const
 Returns a const iterator to the first element. More...
 
const_iterator cend () const
 Returns a const iterator to the end of the list. More...
 
void Remove (iterator it)
 Removes element. More...
 
void Remove (iterator begin, iterator end)
 Removes elements. More...
 
template<class Predicate >
void RemoveIf (Predicate pred)
 Removes elements if predicate is true. More...
 
const_iterator Find (const SCObject &o) const
 Finds an object in the container. More...
 
iterator Find (const SCObject &o)
 Finds an object in the container. More...
 
template<typename T >
std::vector< std::shared_ptr< T > > ToStd ()
 Converts to a std::vector of pointers. More...
 
template<typename T >
std::vector< std::shared_ptr
< const T > > 
ToStd () const
 Converts to a std::vector of pointers. More...
 
std::vector< SObject > Std ()&&
 Gets the inner data. More...
 
void Swap (Vector &other) noexcept
 Swaps contents with another vector. More...
 
void ShrinkToFit ()
 Optimizes the memory usage. More...
 
void Deserialize (xml::Element &el)
 Reads from an XML node if applicable. More...
 
xml::Element Serialize (xml::Element &parent) const
 Dumps to an XML node if applicable. More...
 
 Vector (xml::Element &el)
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Detailed Description

Data vector class.

Author
Yann LEYDIER
Date
April 2007
Version
0.3

Definition at line 42 of file CRNVector.h.

Constructor & Destructor Documentation

Vector::Vector ( )
default

Default constructor.

Default constructor

Parameters
[in]protosthe mandatory protocols for the contents
Vector::~Vector ( )
overridevirtualdefault

Destructor.

Destructor

Vector::Vector ( const Vector other)

Definition at line 42 of file CRNVector.cpp.

crn::Vector::Vector ( Vector &&  )
default
crn::Vector::Vector ( xml::Element el)
inline

Definition at line 159 of file CRNVector.h.

Member Function Documentation

SObject& crn::Vector::At ( size_t  i)
inline

Returns an object from index (unsafe)

Definition at line 65 of file CRNVector.h.

SCObject crn::Vector::At ( size_t  i) const
inline

Returns an object from index (unsafe)

Definition at line 67 of file CRNVector.h.

SObject& crn::Vector::Back ( )
inline

Returns a reference to the last element.

Definition at line 74 of file CRNVector.h.

SCObject crn::Vector::Back ( ) const
inline

Returns a reference to the last element.

Definition at line 76 of file CRNVector.h.

iterator crn::Vector::begin ( )
inline

Returns an iterator to the first element.

Definition at line 100 of file CRNVector.h.

const_iterator crn::Vector::begin ( ) const
inline

Returns a const iterator to the first element.

Definition at line 104 of file CRNVector.h.

const_iterator crn::Vector::cbegin ( ) const
inline

Returns a const iterator to the first element.

Definition at line 108 of file CRNVector.h.

const_iterator crn::Vector::cend ( ) const
inline

Returns a const iterator to the end of the list.

Definition at line 110 of file CRNVector.h.

void crn::Vector::Clear ( )
inlinenoexcept

Empties the vector.

Definition at line 96 of file CRNVector.h.

bool Vector::Contains ( const SCObject &  o) const

Checks of the object is in the vector.

Checks of the object is in the vector

Parameters
[in]othe object to check
Returns
true if o is inside the container, false else

Definition at line 72 of file CRNVector.cpp.

void Vector::Deserialize ( xml::Element el)

Reads from an XML node if applicable.

Unsafe load

Exceptions
ExceptionProtocolthe content of the vector is not serializable
ExceptionInvalidArgumentnot a Vector
ExceptionRuntimeimpossible to read an XML element
ExceptionNotFoundunknown type
Parameters
[in]elthe element to load

Definition at line 267 of file CRNVector.cpp.

iterator crn::Vector::end ( )
inline

Returns a iterator to the end of the list.

Definition at line 102 of file CRNVector.h.

const_iterator crn::Vector::end ( ) const
inline

Returns a const iterator to the end of the list.

Definition at line 106 of file CRNVector.h.

Vector::const_iterator Vector::Find ( const SCObject &  o) const

Finds an object in the container.

Finds an object in the container

Parameters
[in]othe object to find
Returns
a const_iterator on the object or on end() if not found

Definition at line 86 of file CRNVector.cpp.

Vector::iterator Vector::Find ( const SCObject &  o)

Finds an object in the container.

Finds an object in the container

Parameters
[in]othe object to find
Returns
an iterator on the object or on end() if not found

Definition at line 100 of file CRNVector.cpp.

SObject& crn::Vector::Front ( )
inline

Returns a reference to the first element.

Definition at line 70 of file CRNVector.h.

SCObject crn::Vector::Front ( ) const
inline

Returns a reference to the first element.

Definition at line 72 of file CRNVector.h.

void Vector::Insert ( const SObject &  d,
size_t  pos 
)

Inserts an object at a given position.

Inserts an object at a given position

Exceptions
ExceptionProtocolobject has wrong protocols
ExceptionDomainindex out of bounds
Parameters
[in]dthe object to add
[in]posthe position

Definition at line 117 of file CRNVector.cpp.

bool crn::Vector::IsEmpty ( ) const
inlinenoexcept

Tests if the vector is empty.

Definition at line 58 of file CRNVector.h.

Vector & Vector::operator= ( const Vector other)

Definition at line 48 of file CRNVector.cpp.

Vector& crn::Vector::operator= ( Vector &&  )
default
SObject& crn::Vector::operator[] ( size_t  i)
inline

Returns an object from index (unsafe)

Definition at line 61 of file CRNVector.h.

SCObject crn::Vector::operator[] ( size_t  i) const
inline

Returns an object from index (unsafe)

Definition at line 63 of file CRNVector.h.

void crn::Vector::PopBack ( )
inline

Removes the last element.

Definition at line 90 of file CRNVector.h.

void Vector::PushBack ( const SObject &  d)

Adds an object at the end of the vector.

Adds an object at the end of the list

Parameters
[in]dthe object to add

Definition at line 61 of file CRNVector.cpp.

void Vector::Remove ( size_t  index)

Removes an element (safe)

Removes an element by index

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]indexthe index of the element to remove

Definition at line 213 of file CRNVector.cpp.

void Vector::Remove ( const SCObject &  obj)

Removes an element (safe)

Removes an element by pointer

Exceptions
ExceptionNotFoundobject not found.
Parameters
[in]objthe objet to remove

Definition at line 226 of file CRNVector.cpp.

void Vector::Remove ( iterator  it)

Removes element.

Removes element

Parameters
[in]itan iterator on the object to remove

Definition at line 241 of file CRNVector.cpp.

void Vector::Remove ( iterator  begin,
iterator  end 
)

Removes elements.

Removes elements

Parameters
[in]beginan iterator on the first object to remove
[in]endan iterator after the last object to remove

Definition at line 251 of file CRNVector.cpp.

template<class Predicate >
void crn::Vector::RemoveIf ( Predicate  pred)
inline

Removes elements if predicate is true.

Definition at line 117 of file CRNVector.h.

void Vector::ReorderFrom ( const std::vector< size_t > &  from)

Reorders the elements.

Reorders the elements

Exceptions
ExceptionDimensionchangeset is of wrong size
ExceptionLogicchangeset contains duplicates
ExceptionDomainchangeset contains values out of bounds
Parameters
[in]froma vector containing the previous index of each element

Definition at line 139 of file CRNVector.cpp.

void Vector::ReorderTo ( const std::vector< size_t > &  to)

Reorders the elements.

Reorders the elements

Exceptions
ExceptionDimensionchangeset is of wrong size
ExceptionLogicchangeset contains duplicates
ExceptionDomainchangeset contains values out of bounds
Parameters
[in]toa vector containing the new index of each element

Definition at line 177 of file CRNVector.cpp.

xml::Element Vector::Serialize ( xml::Element parent) const

Dumps to an XML node if applicable.

Unsafe save

Exceptions
ExceptionProtocolthe content of the vector is not serializable
Parameters
[in]parentthe parent element to which we will add the new element
Returns
The newly created element, nullptr if failed.

Definition at line 308 of file CRNVector.cpp.

void Vector::ShrinkToFit ( )

Optimizes the memory usage.

Optimizes the memory usage

Definition at line 332 of file CRNVector.cpp.

size_t crn::Vector::Size ( ) const
inlinenoexcept

Returns the number of data objects in the vector.

Definition at line 56 of file CRNVector.h.

std::vector<SObject> crn::Vector::Std ( )
inline

Gets the inner data.

Definition at line 141 of file CRNVector.h.

void Vector::Swap ( Vector other)
noexcept

Swaps contents with another vector.

Swaps contents with another vector

Parameters
[in]otherthe vector to swap with

Definition at line 326 of file CRNVector.cpp.

template<typename T >
std::vector<std::shared_ptr<T> > crn::Vector::ToStd ( )
inline

Converts to a std::vector of pointers.

Definition at line 125 of file CRNVector.h.

template<typename T >
std::vector<std::shared_ptr<const T> > crn::Vector::ToStd ( ) const
inline

Converts to a std::vector of pointers.

Definition at line 133 of file CRNVector.h.


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