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

#include <Link.h>

+ Inheritance diagram for opencog::Link:
+ Collaboration diagram for opencog::Link:

Public Member Functions

 Link (Type t, const HandleSeq &oset, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 Link (Type t, const Handle &h, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 Link (Type t, const Handle &ha, const Handle &hb, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 Link (Type t, const Handle &ha, const Handle &hb, const Handle &hc, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 Link (Type t, const Handle &ha, const Handle &hb, const Handle &hc, const Handle &hd, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 Link (Link &l)
 
 ~Link ()
 
Arity getArity () const
 
const HandleSeqgetOutgoingSet () const
 
Handle getOutgoingAtom (Arity pos) const throw (RuntimeException)
 
template<class T >
bool foreach_outgoing (bool(T::*cb)(const Handle &), T *data)
 
std::string toString (std::string indent="")
 
std::string toShortString (std::string indent="")
 
bool isSource (Handle) const throw (InvalidParamException)
 
bool isSource (size_t) const throw (IndexErrorException, InvalidParamException)
 
bool isTarget (Handle) const throw (InvalidParamException)
 
bool isTarget (size_t) const throw (IndexErrorException, InvalidParamException)
 
virtual bool operator== (const Atom &) const
 
virtual bool operator!= (const Atom &) const
 
- Public Member Functions inherited from opencog::Atom
virtual ~Atom ()
 
Type getType () const
 
bool isType (Type t, bool subclass) const
 
Handle getHandle ()
 
AttentionValuePtr getAttentionValue ()
 
void setAttentionValue (AttentionValuePtr)
 Sets the AttentionValue object of the atom. More...
 
AttentionValue::sti_t getSTI ()
 Handy-dandy convenience getters for attention values. More...
 
AttentionValue::lti_t getLTI ()
 
AttentionValue::vlti_t getVLTI ()
 
void setSTI (AttentionValue::sti_t stiValue)
 
void setLTI (AttentionValue::lti_t ltiValue)
 
void incVLTI ()
 
void decVLTI ()
 
TruthValuePtr getTruthValue ()
 
void setTruthValue (TruthValuePtr)
 Sets the TruthValue object of the atom. More...
 
void merge (TruthValuePtr)
 
Handle tvmerge (TruthValuePtr tv)
 
size_t getIncomingSetSize ()
 Get the size of the incoming set. More...
 
IncomingSet getIncomingSet ()
 
template<typename OutputIterator >
OutputIterator getIncomingSet (OutputIterator result)
 
template<class T >
bool foreach_incoming (bool(T::*cb)(const Handle &), T *data)
 
template<typename OutputIterator >
OutputIterator getIncomingSetByType (OutputIterator result, Type type, bool subclass=false)
 
IncomingSet getIncomingSetByType (Type type, bool subclass=false)
 

Protected Attributes

HandleSeq _outgoing
 
- Protected Attributes inherited from opencog::Atom
UUID _uuid
 
AtomTable_atomTable
 
Type _type
 
char _flags
 
TruthValuePtr _truthValue
 
AttentionValuePtr _attentionValue
 
std::mutex _mtx
 
InSetPtr _incoming_set
 

Private Member Functions

void init (const HandleSeq &) throw (InvalidParamException)
 
void resort (void)
 
 Link (const Link &l)
 

Friends

class AtomTable
 

Additional Inherited Members

- Protected Types inherited from opencog::Atom
typedef std::shared_ptr< InSetInSetPtr
 
- Protected Member Functions inherited from opencog::Atom
 Atom (Type t, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
void keep_incoming_set ()
 
void drop_incoming_set ()
 
void insert_atom (LinkPtr)
 Add an atom to the incoming set. More...
 
void remove_atom (LinkPtr)
 Remove an atom from the incoming set. More...
 

Detailed Description

Nodes in OpenCog are connected to each other by links. Each link embodies one of the basic inter-node relationships. Links do not necessarily describe a binary relationship between two entities. Links may describe relationships between more than two entities at once. Finally, links describe relationships not only between nodes, but also higher-order relationships between links, and between nodes and links.

Definition at line 50 of file Link.h.

Constructor & Destructor Documentation

opencog::Link::Link ( const Link l)
inlineprivate

Definition at line 58 of file Link.h.

opencog::Link::Link ( Type  t,
const HandleSeq oset,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inline

Constructor for this class.

Parameters
Linktype.
Outgoingset, which is an array of the atom handles referenced by this link.
Linktruthvalue, which will be cloned before being stored in this Link.

Definition at line 77 of file Link.h.

References init().

opencog::Link::Link ( Type  t,
const Handle h,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inline

Definition at line 85 of file Link.h.

References init().

opencog::Link::Link ( Type  t,
const Handle ha,
const Handle hb,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inline

Definition at line 95 of file Link.h.

References init().

opencog::Link::Link ( Type  t,
const Handle ha,
const Handle hb,
const Handle hc,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inline

Definition at line 106 of file Link.h.

References init().

opencog::Link::Link ( Type  t,
const Handle ha,
const Handle hb,
const Handle hc,
const Handle hd,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inline

Definition at line 117 of file Link.h.

References init().

opencog::Link::Link ( Link l)
inline

Copy constructor, does NOT copy atom table membership! Cannot be const, because the get() functions can't be, because thread-safe locking required in the gets.

Definition at line 135 of file Link.h.

References getOutgoingSet(), and init().

Link::~Link ( )

Destructor for this class.

Definition at line 68 of file Link.cc.

References DPRINTF, and toString().

Member Function Documentation

template<class T >
bool opencog::Link::foreach_outgoing ( bool(T::*)(const Handle &)  cb,
T *  data 
)
inline

Invoke the callback on each atom in the outgoing set of handle h, until till one of them returns true, in which case, the loop stops and returns true. Otherwise the callback is called on all outgoings and false is returned.

Definition at line 183 of file Link.h.

References getOutgoingSet().

Arity opencog::Link::getArity ( ) const
inline

Definition at line 148 of file Link.h.

References _outgoing.

+ Here is the caller graph for this function:

Handle opencog::Link::getOutgoingAtom ( Arity  pos) const
throw (RuntimeException
)
inline

Returns a specific Handle in the outgoing set.

Parameters
Theposition of the handle in the array.
Returns
A specific handle in the outgoing set.

Definition at line 168 of file Link.h.

References _outgoing, and getArity().

const HandleSeq& opencog::Link::getOutgoingSet ( ) const
inline

Returns a const reference to the array containing this atom's outgoing set.

Returns
A const reference to this atom's outgoing set.

Definition at line 158 of file Link.h.

References _outgoing.

+ Here is the caller graph for this function:

void Link::init ( const HandleSeq )
throw (InvalidParamException
)
private

Definition at line 51 of file Link.cc.

References opencog::classserver().

+ Here is the caller graph for this function:

bool Link::isSource ( Handle  handle) const
throw (InvalidParamException
)

Returns whether a given handle is a source (the first outgoing if the link is ordered) of this link.

Parameters
Handleto be checked for being a link source.
Returns
Whether a given handle is a source of this link.

Definition at line 122 of file Link.cc.

References opencog::classserver().

bool Link::isSource ( size_t  i) const
throw (IndexErrorException,
InvalidParamException
)

Returns whether the element in a given position in the outgoing set of this link is a source (the first outgoing if the link is ordered).

Parameters
Positionin the outgoing set.
Returns
Whether the element in a given position in the outgoing set of this link is a source.

Definition at line 145 of file Link.cc.

References opencog::classserver().

bool Link::isTarget ( Handle  handle) const
throw (InvalidParamException
)

Returns whether a given handle is a target (any but the first if the link is ordered) of this link.

Parameters
Handleto be checked for being a link target.
Returns
Whether a given handle is a target of this link.

Definition at line 165 of file Link.cc.

References opencog::classserver().

bool Link::isTarget ( size_t  i) const
throw (IndexErrorException,
InvalidParamException
)

Returns whether the element in a given position in the outgoing set of this link is a target (any but the first if the link is ordered).

Parameters
Positionin the outgoing set.
Returns
Whether the element in a given position in the outgoing set of this link is a target.

Definition at line 193 of file Link.cc.

References opencog::classserver().

bool Link::operator!= ( const Atom other) const
virtual

Returns whether a given atom is different from the current link.

Parameters
Atomto be tested.
Returns
true if they are different, false otherwise.

Implements opencog::Atom.

Definition at line 226 of file Link.cc.

bool Link::operator== ( const Atom other) const
virtual

Returns whether a given atom is equal to the current link.

Parameters
Atomto be tested.
Returns
true if they are equal, false otherwise.

Implements opencog::Atom.

Definition at line 214 of file Link.cc.

References _outgoing, getArity(), and opencog::Atom::getType().

void Link::resort ( void  )
private

Definition at line 46 of file Link.cc.

References _outgoing.

std::string Link::toShortString ( std::string  indent = "")
virtual

Returns a short string representation of the link. Note that the TV is only represented by its mean and count so if it is a compositeTV only the primaryTV is printed.

Returns
A short string representation of the link.

Implements opencog::Atom.

Definition at line 73 of file Link.cc.

References _outgoing, opencog::Atom::_type, opencog::Atom::_uuid, opencog::classserver(), opencog::Atom::getTruthValue(), and opencog::ClassServer::getTypeName().

std::string Link::toString ( std::string  indent = "")
virtual

Returns a string representation of the link.

Returns
A string representation of the link.

Implements opencog::Atom.

Definition at line 94 of file Link.cc.

References _outgoing, opencog::Atom::_type, opencog::Atom::_uuid, BUFSZ, opencog::classserver(), opencog::Atom::getAttentionValue(), opencog::Atom::getLTI(), opencog::Atom::getSTI(), opencog::Atom::getTruthValue(), and opencog::Atom::getVLTI().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class AtomTable
friend

Definition at line 52 of file Link.h.

Member Data Documentation

HandleSeq opencog::Link::_outgoing
protected

Array holding actual outgoing set of the link. Should not change during atom lifespan.

Definition at line 65 of file Link.h.


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