This class models a binary relation through the elements of any given set.
Internal classes not to be directly used by the user.
I.e. for each pair of elements (A,B) it assigns two values, f(A,B) and f(B,A). This class is useful when calling the base function is costly, since it acts like a proxy. It's also useful if the relationship values do not correspond with the return value of a function. Although it theoretically supports objects with non-trivial constructors or destructors (indicated by specifying "true" as the thrid parameter of the template instantiation), certain operations will cause memory leaks and may even cause undefined behaviour, so it's reccomended to use only basic types for the parameter U. The parameter T may be any complex object, however, like a smart pointer.
Definition at line 31 of file CBinaryRelation.h.
#include <mrpt/math/CBinaryRelation.h>
Public Types | |
typedef U(* | SimpleFunctionByReturnValue) (T, T) |
Simple function type, used to initialize chunks of the matrix. More... | |
typedef U(* | FunctionByReturnValue) (const T &, const T &) |
Function type which obtains the relation value by a return value. More... | |
typedef void(* | FunctionByReferencePass) (const T &, const T &, U &) |
Function type which obtains the relation value by reference pass. More... | |
typedef std::set< T >::const_iterator | const_iterator |
Constant iterator through the set elements. More... | |
typedef std::set< T >::const_reverse_iterator | const_reverse_iterator |
Constant reverse iterator through the set elements. More... | |
typedef CMatrixRowAccessor< U > | AccessorForFirstElement |
Accessor type to every value related to any element A, i.e., f(A,x). More... | |
typedef CMatrixColumnAccessor< U > | AccessorForSecondElement |
Accessor type to every value related to any element B, i.e., f(x,B). More... | |
typedef CConstMatrixRowAccessor< U > | ConstAccessorForFirstElement |
Const accessor type to every value related to any element A, i.e., f(A,x). More... | |
typedef CConstMatrixColumnAccessor< U > | ConstAccessorForSecondElement |
Const accessor type to every value related to any element B, i.e., f(x,B). More... | |
Public Member Functions | |
CBinaryRelation (const std::set< T > &els) | |
Default constructor, doesn't initialize the relation. More... | |
template<typename FunctionType > | |
CBinaryRelation (const std::set< T > &els, FunctionType fun) | |
Constructor which initializes the relation using a given function. More... | |
template<typename FunctionType > | |
void | initializeWith (FunctionType fun) |
Initialize the whole relation with a given function. More... | |
template<typename FunctionType > | |
void | initializeSymmetricallyWith (FunctionType fun) |
Initialize the whole relation with a given function, assuming that the relation is symmetrical. More... | |
void | setRelationValue (size_t e1, size_t e2, const U &newVal) |
Manually set a relationship value, given the indices. More... | |
const U & | getRelationValue (size_t e1, size_t e2) const |
Get a relation value, given the indices. More... | |
const U & | operator() (size_t e1, size_t e2) const |
U & | getRelationValue (size_t e1, size_t e2) |
Get a reference to a relation value given its indices, which allows both querying and setting the value. More... | |
U & | operator() (size_t e1, size_t e2) |
bool | setRelationValue (const T &t1, const T &t2, const U &newVal) |
Manually set a relationship value, given the elements. More... | |
U | getRelationValue (const T &t1, const T &t2) const |
Get a relation value, given the elements. More... | |
U & | getRelationValue (const T &t1, const T &t2) |
Get a reference to a relation value given the elements, which allows both querying and setting. More... | |
const_iterator | begin () const |
Gets an iterator to the starting point of the elements set. More... | |
const_iterator | end () const |
Gets an iterator to the ending point of the elements set. More... | |
const_reverse_iterator | rbegin () const |
Gets a reverse iterator to the ending point of the elements set. More... | |
const_reverse_iterator | rend () const |
Gets a reverse iterator to the starting point of the elements set. More... | |
T | operator[] (size_t i) const |
Operator for direct access to a element given its index. More... | |
AccessorForFirstElement | getRelationFrom (size_t i) |
Gets an accessor for every value related to an element A given its index, i.e., every f(A,x). More... | |
ConstAccessorForFirstElement | getRelationFrom (size_t i) const |
Gets a constant accessor for every value related to an element A given its index, i.e., every f(A,x). More... | |
AccessorForSecondElement | getRelationTo (size_t i) |
Gets an accessor for every value related to an element B given its index, i.e., every f(x,B). More... | |
ConstAccessorForSecondElement | getRelationTo (size_t i) const |
Gets a constant accessor for every value related to an element B given its index, i.e., every f(x,B). More... | |
AccessorForFirstElement | getRelationFrom (const T &t) |
Gets an iterable accessor for every value related to an element A, i.e., every f(A,x). More... | |
ConstAccessorForFirstElement | getRelationFrom (const T &t) const |
Gets an iterable constant accessor for every value related to an element A, i.e., every f(A,x). More... | |
void | getRelationFrom (size_t i, vector< U > &vec) |
void | getRelationFrom (const T &t, vector< U > &vec) |
AccessorForSecondElement | getRelationTo (const T &t) |
Gets an iterable accessor for every value related to an element B, i.e., every f(x,B). More... | |
ConstAccessorForSecondElement | getRelationTo (const T &t) const |
Gets an iterable constant accessor for every value related to an alement B, i.e., every f(x,B). More... | |
void | getRelationTo (size_t i, vector< U > &vec) |
void | getRelationTo (const T &t, vector< U > &vec) |
void | removeElementAt (size_t i) |
Removes an element at a concrete position. More... | |
bool | removeElement (const T &el) |
Removes an element. More... | |
size_t | removeElements (const std::set< T > &vals) |
Removes a set of elements. More... | |
void | removeElementsAt (const std::set< size_t > &poss) |
std::pair< bool, size_t > | insertElement (const T &el) |
Inserts an element. More... | |
template<typename FunctionType > | |
std::pair< bool, size_t > | insertElement (const T &el, FunctionType fun) |
Inserts an element and initializes its relationship values, even if it was already present. More... | |
size_t | insertElements (const std::set< T > &els) |
Inserts a set of elements into the relation. More... | |
template<typename FunctionType > | |
size_t | insertElements (const std::set< T > &els, FunctionType fun) |
Inserts a set of elements into the relation, initializing the actual relation with a given function. More... | |
void | setElements (const std::set< T > &newEls) |
Completely resets the relation, using a new set of elements. More... | |
size_t | size () const |
Returns the amount of elements present in the relation. More... | |
Private Types | |
typedef detail::MatrixWrapper< U, UIsObject >::MatrixType | MatrixType |
Matrix type used to store the actual relation. More... | |
Private Member Functions | |
template<typename FunctionType > | |
void | applyFunction (FunctionType fun, size_t e1, size_t e2, const T &T1, const T &T2) |
Template used to make the function interface independent from the function type. More... | |
Private Attributes | |
std::set< T > | elements |
Actual set of elements. More... | |
MatrixType | relation |
Matrix storing the relation. More... | |
typedef CMatrixRowAccessor<U> mrpt::math::CBinaryRelation< T, U, UIsObject >::AccessorForFirstElement |
Accessor type to every value related to any element A, i.e., f(A,x).
Definition at line 42 of file CBinaryRelation.h.
typedef CMatrixColumnAccessor<U> mrpt::math::CBinaryRelation< T, U, UIsObject >::AccessorForSecondElement |
Accessor type to every value related to any element B, i.e., f(x,B).
Definition at line 43 of file CBinaryRelation.h.
typedef std::set<T>::const_iterator mrpt::math::CBinaryRelation< T, U, UIsObject >::const_iterator |
Constant iterator through the set elements.
Definition at line 40 of file CBinaryRelation.h.
typedef std::set<T>::const_reverse_iterator mrpt::math::CBinaryRelation< T, U, UIsObject >::const_reverse_iterator |
Constant reverse iterator through the set elements.
Definition at line 41 of file CBinaryRelation.h.
typedef CConstMatrixRowAccessor<U> mrpt::math::CBinaryRelation< T, U, UIsObject >::ConstAccessorForFirstElement |
Const accessor type to every value related to any element A, i.e., f(A,x).
Definition at line 44 of file CBinaryRelation.h.
typedef CConstMatrixColumnAccessor<U> mrpt::math::CBinaryRelation< T, U, UIsObject >::ConstAccessorForSecondElement |
Const accessor type to every value related to any element B, i.e., f(x,B).
Definition at line 45 of file CBinaryRelation.h.
typedef void(* mrpt::math::CBinaryRelation< T, U, UIsObject >::FunctionByReferencePass) (const T &, const T &, U &) |
Function type which obtains the relation value by reference pass.
Definition at line 39 of file CBinaryRelation.h.
typedef U(* mrpt::math::CBinaryRelation< T, U, UIsObject >::FunctionByReturnValue) (const T &, const T &) |
Function type which obtains the relation value by a return value.
Definition at line 38 of file CBinaryRelation.h.
|
private |
Matrix type used to store the actual relation.
Definition at line 35 of file CBinaryRelation.h.
typedef U(* mrpt::math::CBinaryRelation< T, U, UIsObject >::SimpleFunctionByReturnValue) (T, T) |
Simple function type, used to initialize chunks of the matrix.
Definition at line 37 of file CBinaryRelation.h.
|
inlineexplicit |
Default constructor, doesn't initialize the relation.
Definition at line 62 of file CBinaryRelation.h.
|
inline |
Constructor which initializes the relation using a given function.
Definition at line 66 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeWith().
|
inlineprivate |
Template used to make the function interface independent from the function type.
(wrapper for the global method - needed to make this compile under GCC).
Definition at line 54 of file CBinaryRelation.h.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeSymmetricallyWith(), mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeWith(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements().
|
inline |
Gets an iterator to the starting point of the elements set.
Definition at line 150 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements().
|
inline |
Gets an iterator to the ending point of the elements set.
Definition at line 156 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements().
|
inline |
Gets an accessor for every value related to an element A given its index, i.e., every f(A,x).
This accessor is iterable.
Definition at line 183 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom().
|
inline |
Gets a constant accessor for every value related to an element A given its index, i.e., every f(A,x).
This accessor is iterable.
Definition at line 189 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
|
inline |
Gets an iterable accessor for every value related to an element A, i.e., every f(A,x).
A domain_error will be thrown if the element is not present.
Definition at line 207 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom().
|
inline |
Gets an iterable constant accessor for every value related to an element A, i.e., every f(A,x).
A domain_error will be thrown if the element is not present.
Definition at line 217 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom().
|
inline |
|
inline |
Definition at line 230 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom().
|
inline |
Gets an accessor for every value related to an element B given its index, i.e., every f(x,B).
This accessor is iterable.
Definition at line 195 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo().
|
inline |
Gets a constant accessor for every value related to an element B given its index, i.e., every f(x,B).
This accessor is fully iterable.
Definition at line 201 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
|
inline |
Gets an iterable accessor for every value related to an element B, i.e., every f(x,B).
A domain_error will be thrown if the element is not present.
Definition at line 239 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo().
|
inline |
Gets an iterable constant accessor for every value related to an alement B, i.e., every f(x,B).
A domain_error will be thrown if the element is not present.
Definition at line 249 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo().
|
inline |
|
inline |
Definition at line 262 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo().
|
inline |
Get a relation value, given the indices.
Definition at line 103 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::detail::applyFunction(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::operator()().
|
inline |
Get a reference to a relation value given its indices, which allows both querying and setting the value.
Definition at line 112 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
|
inline |
Get a relation value, given the elements.
Throws domain_error if any of the elements is not present.
Definition at line 131 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue().
|
inline |
Get a reference to a relation value given the elements, which allows both querying and setting.
Throws domain_error if any of the elements is not present.
Definition at line 141 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue().
|
inline |
Initialize the whole relation with a given function, assuming that the relation is symmetrical.
Definition at line 82 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::applyFunction(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
|
inline |
Initialize the whole relation with a given function.
Definition at line 72 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::applyFunction(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::CBinaryRelation().
|
inline |
Inserts an element.
If the element was present, returns false and its current position. If it wasn't, returns true and the position in which it was inserted.
Definition at line 314 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement().
|
inline |
Inserts an element and initializes its relationship values, even if it was already present.
Definition at line 327 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::applyFunction(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::operator[]().
|
inline |
Inserts a set of elements into the relation.
Does not initialize the actual relation.
Definition at line 340 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements().
|
inline |
Inserts a set of elements into the relation, initializing the actual relation with a given function.
Definition at line 366 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::applyFunction(), mrpt::math::CBinaryRelation< T, U, UIsObject >::begin(), mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::math::CBinaryRelation< T, U, UIsObject >::end(), mrpt::utils::find(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::operator[]().
|
inline |
Definition at line 106 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue().
|
inline |
Definition at line 115 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue().
|
inline |
Operator for direct access to a element given its index.
Definition at line 174 of file CBinaryRelation.h.
References ASSERT_BELOW_, and mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements().
|
inline |
Gets a reverse iterator to the ending point of the elements set.
Definition at line 162 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
|
inline |
Removes an element.
Returns false if the element was not present and thus could'nt be eliminated.
Definition at line 283 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementAt().
|
inline |
Removes an element at a concrete position.
Definition at line 271 of file CBinaryRelation.h.
References ASSERT_, mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElement().
|
inline |
Removes a set of elements.
Returns the number of elements which were actually erased.
Definition at line 293 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementsAt().
|
inline |
Definition at line 302 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElements().
|
inline |
Gets a reverse iterator to the starting point of the elements set.
Definition at line 168 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
|
inline |
Completely resets the relation, using a new set of elements.
Does not initialize the relation.
Definition at line 396 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, and mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
|
inline |
Manually set a relationship value, given the indices.
Definition at line 97 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::relation.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::setRelationValue().
|
inline |
Manually set a relationship value, given the elements.
Returns false if any of the elements is not present.
Definition at line 121 of file CBinaryRelation.h.
References mrpt::math::distance(), mrpt::math::CBinaryRelation< T, U, UIsObject >::elements, mrpt::utils::find(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::setRelationValue().
|
inline |
Returns the amount of elements present in the relation.
Definition at line 404 of file CBinaryRelation.h.
References mrpt::math::CBinaryRelation< T, U, UIsObject >::elements.
|
private |
Actual set of elements.
Definition at line 47 of file CBinaryRelation.h.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::begin(), mrpt::math::CBinaryRelation< T, U, UIsObject >::end(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue(), mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeSymmetricallyWith(), mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeWith(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements(), mrpt::math::CBinaryRelation< T, U, UIsObject >::operator[](), mrpt::math::CBinaryRelation< T, U, UIsObject >::rbegin(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElement(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementAt(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElements(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementsAt(), mrpt::math::CBinaryRelation< T, U, UIsObject >::rend(), mrpt::math::CBinaryRelation< T, U, UIsObject >::setElements(), mrpt::math::CBinaryRelation< T, U, UIsObject >::setRelationValue(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::size().
|
private |
Matrix storing the relation.
Definition at line 48 of file CBinaryRelation.h.
Referenced by mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationFrom(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationTo(), mrpt::math::CBinaryRelation< T, U, UIsObject >::getRelationValue(), mrpt::math::CBinaryRelation< T, U, UIsObject >::initializeSymmetricallyWith(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElement(), mrpt::math::CBinaryRelation< T, U, UIsObject >::insertElements(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementAt(), mrpt::math::CBinaryRelation< T, U, UIsObject >::removeElementsAt(), mrpt::math::CBinaryRelation< T, U, UIsObject >::setElements(), and mrpt::math::CBinaryRelation< T, U, UIsObject >::setRelationValue().
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |