This class models a binary relation through the elements of any given set.
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.
#include <mrpt/math/CBinaryRelation.h>
Public Types | |
| typedef U(* | SimpleFunctionByReturnValue )(T, T) |
| Simple function type, used to initialize chunks of the matrix. | |
| typedef U(* | FunctionByReturnValue )(const T &, const T &) |
| Function type which obtains the relation value by a return value. | |
| typedef void(* | FunctionByReferencePass )(const T &, const T &, U &) |
| Function type which obtains the relation value by reference pass. | |
| typedef std::set< T > ::const_iterator | const_iterator |
| Constant iterator through the set elements. | |
| typedef std::set< T > ::const_reverse_iterator | const_reverse_iterator |
| Constant reverse iterator through the set elements. | |
| typedef CMatrixRowAccessor< U > | AccessorForFirstElement |
| Accessor type to every value related to any element A, i.e., f(A,x). | |
| typedef CMatrixColumnAccessor< U > | AccessorForSecondElement |
| Accessor type to every value related to any element B, i.e., f(x,B). | |
| typedef CConstMatrixRowAccessor< U > | ConstAccessorForFirstElement |
| Const accessor type to every value related to any element A, i.e., f(A,x). | |
| typedef CConstMatrixColumnAccessor< U > | ConstAccessorForSecondElement |
| Const accessor type to every value related to any element B, i.e., f(x,B). | |
Public Member Functions | |
| CBinaryRelation (const std::set< T > &els) | |
| Default constructor, doesn't initialize the relation. | |
| template<typename FunctionType > | |
| CBinaryRelation (const std::set< T > &els, FunctionType fun) | |
| Constructor which initializes the relation using a given function. | |
| template<typename FunctionType > | |
| void | initializeWith (FunctionType fun) |
| Initialize the whole relation with a given function. | |
| template<typename FunctionType > | |
| void | initializeSymmetricallyWith (FunctionType fun) |
| Initialize the whole relation with a given function, assuming that the relation is symmetrical. | |
| void | setRelationValue (size_t e1, size_t e2, const U &newVal) |
| Manually set a relationship value, given the indices. | |
| const U & | getRelationValue (size_t e1, size_t e2) const |
| Get a relation value, given the indices. | |
| 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. | |
| 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. | |
| U | getRelationValue (const T &t1, const T &t2) const |
| Get a relation value, given the elements. | |
| U & | getRelationValue (const T &t1, const T &t2) |
| Get a reference to a relation value given the elements, which allows both querying and setting. | |
| const_iterator | begin () const |
| Gets an iterator to the starting point of the elements set. | |
| const_iterator | end () const |
| Gets an iterator to the ending point of the elements set. | |
| const_reverse_iterator | rbegin () const |
| Gets a reverse iterator to the ending point of the elements set. | |
| const_reverse_iterator | rend () const |
| Gets a reverse iterator to the starting point of the elements set. | |
| T | operator[] (size_t i) const |
| Operator for direct access to a element given its index. | |
| 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). | |
| 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). | |
| 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). | |
| 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). | |
| AccessorForFirstElement | getRelationFrom (const T &t) |
| Gets an iterable accessor for every value related to an element A, i.e., every f(A,x). | |
| 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). | |
| 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). | |
| 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). | |
| 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. | |
| bool | removeElement (const T &el) |
| Removes an element. | |
| size_t | removeElements (const set< T > &vals) |
| Removes a set of elements. | |
| void | removeElementsAt (const set< size_t > &poss) |
| std::pair< bool, size_t > | insertElement (const T &el) |
| Inserts an element. | |
| 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. | |
| size_t | insertElements (const std::set< T > &els) |
| Inserts a set of elements into the relation. | |
| 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. | |
| void | setElements (const std::set< T > &newEls) |
| Completely resets the relation, using a new set of elements. | |
| size_t | size () const |
| Returns the amount of elements present in the relation. | |
Private Types | |
| typedef detail::MatrixWrapper < U, UIsObject >::MatrixType | MatrixType |
| Matrix type used to store the actual relation. | |
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. | |
Private Attributes | |
| std::set< T > | elements |
| Actual set of elements. | |
| MatrixType | relation |
| Matrix storing the relation. | |
Accessor type to every value related to any element A, i.e., f(A,x).
Definition at line 61 of file CBinaryRelation.h.
Accessor type to every value related to any element B, i.e., f(x,B).
Definition at line 62 of file CBinaryRelation.h.
Constant iterator through the set elements.
Definition at line 59 of file CBinaryRelation.h.
Constant reverse iterator through the set elements.
Definition at line 60 of file CBinaryRelation.h.
Const accessor type to every value related to any element A, i.e., f(A,x).
Definition at line 63 of file CBinaryRelation.h.
Const accessor type to every value related to any element B, i.e., f(x,B).
Definition at line 64 of file CBinaryRelation.h.
| typedef void(* mrpt::math::CBinaryRelation::FunctionByReferencePass)(const T &, const T &, U &) |
Function type which obtains the relation value by reference pass.
Definition at line 58 of file CBinaryRelation.h.
| typedef U(* mrpt::math::CBinaryRelation::FunctionByReturnValue)(const T &, const T &) |
Function type which obtains the relation value by a return value.
Definition at line 57 of file CBinaryRelation.h.
typedef detail::MatrixWrapper<U,UIsObject>::MatrixType mrpt::math::CBinaryRelation::MatrixType [private] |
Matrix type used to store the actual relation.
Definition at line 54 of file CBinaryRelation.h.
| typedef U(* mrpt::math::CBinaryRelation::SimpleFunctionByReturnValue)(T, T) |
Simple function type, used to initialize chunks of the matrix.
Definition at line 56 of file CBinaryRelation.h.
| mrpt::math::CBinaryRelation::CBinaryRelation | ( | const std::set< T > & | els | ) | [inline, explicit] |
Default constructor, doesn't initialize the relation.
Definition at line 81 of file CBinaryRelation.h.
| mrpt::math::CBinaryRelation::CBinaryRelation | ( | const std::set< T > & | els, |
| FunctionType | fun | ||
| ) | [inline] |
Constructor which initializes the relation using a given function.
Definition at line 85 of file CBinaryRelation.h.
References initializeWith().
| void mrpt::math::CBinaryRelation::applyFunction | ( | FunctionType | fun, |
| size_t | e1, | ||
| size_t | e2, | ||
| const T & | T1, | ||
| const T & | T2 | ||
| ) | [inline, private] |
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 73 of file CBinaryRelation.h.
Referenced by initializeWith(), initializeSymmetricallyWith(), insertElement(), and insertElements().
| const_iterator mrpt::math::CBinaryRelation::begin | ( | ) | const [inline] |
Gets an iterator to the starting point of the elements set.
Definition at line 169 of file CBinaryRelation.h.
References elements.
Referenced by insertElements().
| const_iterator mrpt::math::CBinaryRelation::end | ( | ) | const [inline] |
Gets an iterator to the ending point of the elements set.
Definition at line 175 of file CBinaryRelation.h.
References elements.
Referenced by insertElements().
| AccessorForFirstElement mrpt::math::CBinaryRelation::getRelationFrom | ( | size_t | i | ) | [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 202 of file CBinaryRelation.h.
References relation.
Referenced by getRelationFrom().
| ConstAccessorForFirstElement mrpt::math::CBinaryRelation::getRelationFrom | ( | size_t | i | ) | const [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 208 of file CBinaryRelation.h.
References relation.
| AccessorForFirstElement mrpt::math::CBinaryRelation::getRelationFrom | ( | const T & | t | ) | [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 226 of file CBinaryRelation.h.
References elements, getRelationFrom(), and mrpt::math::distance().
| ConstAccessorForFirstElement mrpt::math::CBinaryRelation::getRelationFrom | ( | const T & | t | ) | const [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 236 of file CBinaryRelation.h.
References elements, getRelationFrom(), and mrpt::math::distance().
| void mrpt::math::CBinaryRelation::getRelationFrom | ( | size_t | i, |
| vector< U > & | vec | ||
| ) | [inline] |
Definition at line 242 of file CBinaryRelation.h.
References elements, ASSERT_, relation, mrpt::math::CConstMatrixRowAccessor::begin(), and mrpt::math::CConstMatrixRowAccessor::end().
| void mrpt::math::CBinaryRelation::getRelationFrom | ( | const T & | t, |
| vector< U > & | vec | ||
| ) | [inline] |
Definition at line 249 of file CBinaryRelation.h.
References elements, getRelationFrom(), and mrpt::math::distance().
| AccessorForSecondElement mrpt::math::CBinaryRelation::getRelationTo | ( | size_t | i | ) | [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 214 of file CBinaryRelation.h.
References relation.
Referenced by getRelationTo().
| ConstAccessorForSecondElement mrpt::math::CBinaryRelation::getRelationTo | ( | size_t | i | ) | const [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 220 of file CBinaryRelation.h.
References relation.
| AccessorForSecondElement mrpt::math::CBinaryRelation::getRelationTo | ( | const T & | t | ) | [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 258 of file CBinaryRelation.h.
References elements, getRelationTo(), and mrpt::math::distance().
| ConstAccessorForSecondElement mrpt::math::CBinaryRelation::getRelationTo | ( | const T & | t | ) | const [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 268 of file CBinaryRelation.h.
References elements, getRelationTo(), and mrpt::math::distance().
| void mrpt::math::CBinaryRelation::getRelationTo | ( | size_t | i, |
| vector< U > & | vec | ||
| ) | [inline] |
Definition at line 274 of file CBinaryRelation.h.
References elements, ASSERT_, relation, mrpt::math::CConstMatrixColumnAccessor::begin(), and mrpt::math::CConstMatrixColumnAccessor::end().
| void mrpt::math::CBinaryRelation::getRelationTo | ( | const T & | t, |
| vector< U > & | vec | ||
| ) | [inline] |
Definition at line 281 of file CBinaryRelation.h.
References elements, getRelationTo(), and mrpt::math::distance().
| const U& mrpt::math::CBinaryRelation::getRelationValue | ( | size_t | e1, |
| size_t | e2 | ||
| ) | const [inline] |
Get a relation value, given the indices.
Definition at line 122 of file CBinaryRelation.h.
References relation.
Referenced by operator()(), and getRelationValue().
| U& mrpt::math::CBinaryRelation::getRelationValue | ( | size_t | e1, |
| size_t | e2 | ||
| ) | [inline] |
Get a reference to a relation value given its indices, which allows both querying and setting the value.
Definition at line 131 of file CBinaryRelation.h.
References relation.
| U mrpt::math::CBinaryRelation::getRelationValue | ( | const T & | t1, |
| const T & | t2 | ||
| ) | const [inline] |
Get a relation value, given the elements.
Throws domain_error if any of the elements is not present.
Definition at line 150 of file CBinaryRelation.h.
References elements, getRelationValue(), and mrpt::math::distance().
| U& mrpt::math::CBinaryRelation::getRelationValue | ( | const T & | t1, |
| const T & | t2 | ||
| ) | [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 160 of file CBinaryRelation.h.
References elements, getRelationValue(), and mrpt::math::distance().
| void mrpt::math::CBinaryRelation::initializeSymmetricallyWith | ( | FunctionType | fun | ) | [inline] |
Initialize the whole relation with a given function, assuming that the relation is symmetrical.
Definition at line 101 of file CBinaryRelation.h.
References elements, applyFunction(), and relation.
| void mrpt::math::CBinaryRelation::initializeWith | ( | FunctionType | fun | ) | [inline] |
Initialize the whole relation with a given function.
Definition at line 91 of file CBinaryRelation.h.
References elements, and applyFunction().
Referenced by CBinaryRelation().
| std::pair<bool,size_t> mrpt::math::CBinaryRelation::insertElement | ( | const T & | el | ) | [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 339 of file CBinaryRelation.h.
References elements, mrpt::math::distance(), and relation.
Referenced by insertElement().
| std::pair<bool,size_t> mrpt::math::CBinaryRelation::insertElement | ( | const T & | el, |
| FunctionType | fun | ||
| ) | [inline] |
Inserts an element and initializes its relationship values, even if it was already present.
Definition at line 352 of file CBinaryRelation.h.
References insertElement(), elements, operator[](), and applyFunction().
| size_t mrpt::math::CBinaryRelation::insertElements | ( | const std::set< T > & | els | ) | [inline] |
Inserts a set of elements into the relation.
Does not initialize the actual relation.
Definition at line 365 of file CBinaryRelation.h.
References elements, mrpt::math::distance(), and relation.
Referenced by insertElements().
| size_t mrpt::math::CBinaryRelation::insertElements | ( | const std::set< T > & | els, |
| FunctionType | fun | ||
| ) | [inline] |
Inserts a set of elements into the relation, initializing the actual relation with a given function.
Definition at line 391 of file CBinaryRelation.h.
References insertElements(), begin(), elements, end(), mrpt::math::distance(), operator[](), and applyFunction().
| const U& mrpt::math::CBinaryRelation::operator() | ( | size_t | e1, |
| size_t | e2 | ||
| ) | const [inline] |
Definition at line 125 of file CBinaryRelation.h.
References getRelationValue().
| U& mrpt::math::CBinaryRelation::operator() | ( | size_t | e1, |
| size_t | e2 | ||
| ) | [inline] |
Definition at line 134 of file CBinaryRelation.h.
References getRelationValue().
| T mrpt::math::CBinaryRelation::operator[] | ( | size_t | i | ) | const [inline] |
Operator for direct access to a element given its index.
Definition at line 193 of file CBinaryRelation.h.
References ASSERT_BELOW_, and elements.
Referenced by insertElement(), and insertElements().
| const_reverse_iterator mrpt::math::CBinaryRelation::rbegin | ( | ) | const [inline] |
Gets a reverse iterator to the ending point of the elements set.
Definition at line 181 of file CBinaryRelation.h.
References elements.
| bool mrpt::math::CBinaryRelation::removeElement | ( | const T & | el | ) | [inline] |
Removes an element.
Returns false if the element was not present and thus could'nt be eliminated.
Definition at line 302 of file CBinaryRelation.h.
References elements, removeElementAt(), and mrpt::math::distance().
| void mrpt::math::CBinaryRelation::removeElementAt | ( | size_t | i | ) | [inline] |
Removes an element at a concrete position.
Definition at line 290 of file CBinaryRelation.h.
References ASSERT_, elements, and relation.
Referenced by removeElement().
| size_t mrpt::math::CBinaryRelation::removeElements | ( | const set< T > & | vals | ) | [inline] |
Removes a set of elements.
Returns the number of elements which were actually erased.
Definition at line 312 of file CBinaryRelation.h.
References elements, mrpt::math::distance(), and removeElementsAt().
| void mrpt::math::CBinaryRelation::removeElementsAt | ( | const set< size_t > & | poss | ) | [inline] |
Definition at line 327 of file CBinaryRelation.h.
References relation, and elements.
Referenced by removeElements().
| const_reverse_iterator mrpt::math::CBinaryRelation::rend | ( | ) | const [inline] |
Gets a reverse iterator to the starting point of the elements set.
Definition at line 187 of file CBinaryRelation.h.
References elements.
| void mrpt::math::CBinaryRelation::setElements | ( | const std::set< T > & | newEls | ) | [inline] |
Completely resets the relation, using a new set of elements.
Does not initialize the relation.
Definition at line 421 of file CBinaryRelation.h.
| void mrpt::math::CBinaryRelation::setRelationValue | ( | size_t | e1, |
| size_t | e2, | ||
| const U & | newVal | ||
| ) | [inline] |
Manually set a relationship value, given the indices.
Definition at line 116 of file CBinaryRelation.h.
References relation.
Referenced by setRelationValue().
| bool mrpt::math::CBinaryRelation::setRelationValue | ( | const T & | t1, |
| const T & | t2, | ||
| const U & | newVal | ||
| ) | [inline] |
Manually set a relationship value, given the elements.
Returns false if any of the elements is not present.
Definition at line 140 of file CBinaryRelation.h.
References elements, setRelationValue(), and mrpt::math::distance().
| size_t mrpt::math::CBinaryRelation::size | ( | ) | const [inline] |
Returns the amount of elements present in the relation.
Definition at line 429 of file CBinaryRelation.h.
References elements.
std::set<T> mrpt::math::CBinaryRelation::elements [private] |
Actual set of elements.
Definition at line 66 of file CBinaryRelation.h.
Referenced by initializeWith(), initializeSymmetricallyWith(), setRelationValue(), getRelationValue(), begin(), end(), rbegin(), rend(), operator[](), getRelationFrom(), getRelationTo(), removeElementAt(), removeElement(), removeElements(), removeElementsAt(), insertElement(), insertElements(), setElements(), and size().
Matrix storing the relation.
Definition at line 67 of file CBinaryRelation.h.
Referenced by initializeSymmetricallyWith(), setRelationValue(), getRelationValue(), getRelationFrom(), getRelationTo(), removeElementAt(), removeElementsAt(), insertElement(), insertElements(), and setElements().
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |