OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
opencog::PrivateUseOnlyChaseLink< T > Class Template Reference

#include <ForeachChaseLink.h>

+ Collaboration diagram for opencog::PrivateUseOnlyChaseLink< T >:

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
 

Detailed Description

template<typename T>
class opencog::PrivateUseOnlyChaseLink< T >

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.

Member Function Documentation

template<typename T>
bool opencog::PrivateUseOnlyChaseLink< T >::follow_link ( const Handle h,
Type  ltype,
int  from,
int  to,
bool(T::*)(const Handle &)  cb,
T *  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.

+ Here is the caller graph for this function:

template<typename T>
bool opencog::PrivateUseOnlyChaseLink< T >::follow_link_lh ( const Handle h,
Type  ltype,
int  from,
int  to,
bool(T::*)(const Handle &, const Handle &)  cb,
T *  data 
)
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.

+ Here is the caller graph for this function:

template<typename T>
bool opencog::PrivateUseOnlyChaseLink< T >::follow_unordered_binary_link ( const Handle h,
Type  ltype,
bool(T::*)(const Handle &)  cb,
T *  data 
)
inline
template<typename T>
bool opencog::PrivateUseOnlyChaseLink< T >::follow_unordered_binary_link ( const Handle h,
Type  ltype,
bool(T::*)(const Handle &, const Handle &)  cb,
T *  data 
)
inline
template<typename T>
bool opencog::PrivateUseOnlyChaseLink< T >::pursue_unordered_link ( const Handle h)
inlineprivate

Definition at line 233 of file ForeachChaseLink.h.

References opencog::PrivateUseOnlyChaseLink< T >::from_atom, and opencog::PrivateUseOnlyChaseLink< T >::to_atom.

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T>
int opencog::PrivateUseOnlyChaseLink< T >::cnt
private

Definition at line 151 of file ForeachChaseLink.h.

template<typename T>
bool(PrivateUseOnlyChaseLink::* opencog::PrivateUseOnlyChaseLink< T >::endpoint_matcher)(const Handle &)
private

Definition at line 152 of file ForeachChaseLink.h.

template<typename T>
Handle opencog::PrivateUseOnlyChaseLink< T >::from_atom
private

Definition at line 147 of file ForeachChaseLink.h.

template<typename T>
Type opencog::PrivateUseOnlyChaseLink< T >::link_type
private

Definition at line 146 of file ForeachChaseLink.h.

template<typename T>
int opencog::PrivateUseOnlyChaseLink< T >::position_from
private

Definition at line 149 of file ForeachChaseLink.h.

template<typename T>
int opencog::PrivateUseOnlyChaseLink< T >::position_to
private

Definition at line 150 of file ForeachChaseLink.h.

template<typename T>
Handle opencog::PrivateUseOnlyChaseLink< T >::to_atom
private

Definition at line 148 of file ForeachChaseLink.h.

template<typename T>
bool(T::* opencog::PrivateUseOnlyChaseLink< T >::user_callback)(const Handle &)
private

Definition at line 153 of file ForeachChaseLink.h.

template<typename T>
bool(T::* opencog::PrivateUseOnlyChaseLink< T >::user_callback_lh)(const Handle &, const Handle &)
private

Definition at line 154 of file ForeachChaseLink.h.

template<typename T>
T* opencog::PrivateUseOnlyChaseLink< T >::user_data
private

Definition at line 155 of file ForeachChaseLink.h.


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