OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <ForeachChaseLink.h>
Public Member Functions | |
bool | follow_link (const Handle &h, Type ltype, int from, int to, bool(T::*cb)(const Handle &), T *data) |
bool | follow_link_lh (const Handle &h, Type ltype, int from, int to, bool(T::*cb)(const Handle &, const Handle &), T *data) |
bool | follow_unordered_binary_link (const Handle &h, Type ltype, bool(T::*cb)(const Handle &), T *data) |
bool | follow_unordered_binary_link (const Handle &h, Type ltype, bool(T::*cb)(const Handle &, const Handle &), T *data) |
Private Member Functions | |
bool | do_follow_link (const Handle &h, Type ltype, int from, int to, T *data) |
bool | do_follow_unordered_binary_link (const Handle &h, Type ltype, T *data) |
bool | find_link_type (const Handle &link_h) |
bool | pursue_link (const Handle &h) |
bool | pursue_unordered_link (const Handle &h) |
Private Attributes | |
Type | link_type |
Handle | from_atom |
Handle | to_atom |
int | position_from |
int | position_to |
int | cnt |
bool(PrivateUseOnlyChaseLink::* | endpoint_matcher )(const Handle &) |
bool(T::* | user_callback )(const Handle &) |
bool(T::* | user_callback_lh )(const Handle &, const Handle &) |
T * | user_data |
This class is not meant for external use, it is meant to be a private utility for the use of the helper functions below. Unfortunately, C++ does not give any way of hiding this from the namespace. Too bad :-(
However, following this "private" definition are several public callback iterators, which are intended for general use.
This template class implements a foreach iterator that iterates over all atoms associated with a given atom via a certain link type. It does this by iterating over all links containing the given atom, and then invoking a callback for a corresponding atom in that link. Two utility methods are provided: follow a binary link in the foreward direction, and in the reverse direction.
If there is only one link of the given type, for the given atom, then the FollowLink clas provides an easier-to-use interface.
Example usage:
class MyClass { bool my_callback(const Handle& h) { printf("Hello world, found %ul\n", (unsigned long) h); }
void do_stuff_with_handle(Handle h) { PrivateUseOnlyChaseLink<MyClass> my_iter;
my_iter.follow_binary_link(h, INHERITANCE_LINK, MyClass::my_callback, this); } };
The above example invokes the callback "my_callback" on every handle that is at the far end of an inheritence link containing the input handle h.
Definition at line 91 of file ForeachChaseLink.h.
|
inlineprivate |
Definition at line 157 of file ForeachChaseLink.h.
References python.atom_type_names::data, opencog::PrivateUseOnlyChaseLink< T >::endpoint_matcher, opencog::PrivateUseOnlyChaseLink< T >::find_link_type(), opencog::Atom::foreach_incoming(), opencog::PrivateUseOnlyChaseLink< T >::from_atom, opencog::PrivateUseOnlyChaseLink< T >::link_type, opencog::PrivateUseOnlyChaseLink< T >::position_from, opencog::PrivateUseOnlyChaseLink< T >::position_to, opencog::PrivateUseOnlyChaseLink< T >::pursue_link(), opencog::PrivateUseOnlyChaseLink< T >::to_atom, opencog::Handle::UNDEFINED, and opencog::PrivateUseOnlyChaseLink< T >::user_data.
|
inlineprivate |
Definition at line 172 of file ForeachChaseLink.h.
References python.atom_type_names::data, opencog::PrivateUseOnlyChaseLink< T >::endpoint_matcher, opencog::PrivateUseOnlyChaseLink< T >::find_link_type(), opencog::Atom::foreach_incoming(), opencog::PrivateUseOnlyChaseLink< T >::from_atom, opencog::PrivateUseOnlyChaseLink< T >::link_type, opencog::PrivateUseOnlyChaseLink< T >::pursue_unordered_link(), opencog::PrivateUseOnlyChaseLink< T >::to_atom, opencog::Handle::UNDEFINED, and opencog::PrivateUseOnlyChaseLink< T >::user_data.
|
inlineprivate |
Check for link of the desired type, then loop over its outgoing set.
Definition at line 188 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::cnt, opencog::PrivateUseOnlyChaseLink< T >::endpoint_matcher, opencog::Atom::getType(), opencog::PrivateUseOnlyChaseLink< T >::link_type, opencog::LinkCast(), opencog::PrivateUseOnlyChaseLink< T >::to_atom, opencog::Handle::UNDEFINED, opencog::PrivateUseOnlyChaseLink< T >::user_callback, opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh, and opencog::PrivateUseOnlyChaseLink< T >::user_data.
|
inline |
follow_link – follow an ordered, binary link.
Look at the incoming set of the specified atom. Find all links of type link_type. Check to make sure that the input handle "h" occupies position "from" in the link. If it does, then invoke the callback, passing the handle in position "to" to the callback. The callback is called for each endpoint found.
The callback should return false to search for more matches, or return true to halt the search.
Definition at line 109 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::do_follow_link(), opencog::PrivateUseOnlyChaseLink< T >::user_callback, and opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh.
|
inline |
Same as above, except the callback is passed the handle of the link itself in the second arg.
Definition at line 121 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::do_follow_link(), opencog::PrivateUseOnlyChaseLink< T >::user_callback, and opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh.
|
inline |
Definition at line 129 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::do_follow_unordered_binary_link(), opencog::PrivateUseOnlyChaseLink< T >::user_callback, and opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh.
|
inline |
Definition at line 137 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::do_follow_unordered_binary_link(), opencog::PrivateUseOnlyChaseLink< T >::user_callback, and opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh.
|
inlineprivate |
Definition at line 209 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::cnt, opencog::PrivateUseOnlyChaseLink< T >::from_atom, opencog::PrivateUseOnlyChaseLink< T >::position_from, opencog::PrivateUseOnlyChaseLink< T >::position_to, opencog::PrivateUseOnlyChaseLink< T >::to_atom, and opencog::Handle::UNDEFINED.
|
inlineprivate |
Definition at line 233 of file ForeachChaseLink.h.
References opencog::PrivateUseOnlyChaseLink< T >::from_atom, and opencog::PrivateUseOnlyChaseLink< T >::to_atom.
|
private |
Definition at line 151 of file ForeachChaseLink.h.
|
private |
Definition at line 152 of file ForeachChaseLink.h.
|
private |
Definition at line 147 of file ForeachChaseLink.h.
|
private |
Definition at line 146 of file ForeachChaseLink.h.
|
private |
Definition at line 149 of file ForeachChaseLink.h.
|
private |
Definition at line 150 of file ForeachChaseLink.h.
|
private |
Definition at line 148 of file ForeachChaseLink.h.
|
private |
Definition at line 153 of file ForeachChaseLink.h.
|
private |
Definition at line 154 of file ForeachChaseLink.h.
|
private |
Definition at line 155 of file ForeachChaseLink.h.