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

#include <Atom.h>

+ Inheritance diagram for opencog::Atom:
+ Collaboration diagram for opencog::Atom:

Classes

struct  InSet
 

Public Member Functions

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)
 
virtual std::string toString (std::string indent="")=0
 
virtual std::string toShortString (std::string indent="")=0
 
virtual bool operator== (const Atom &) const =0
 
virtual bool operator!= (const Atom &) const =0
 

Protected Types

typedef std::shared_ptr< InSetInSetPtr
 

Protected Member Functions

 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...
 

Protected Attributes

UUID _uuid
 
AtomTable_atomTable
 
Type _type
 
char _flags
 
TruthValuePtr _truthValue
 
AttentionValuePtr _attentionValue
 
std::mutex _mtx
 
InSetPtr _incoming_set
 

Private Member Functions

void setAtomTable (AtomTable *)
 Sets the AtomTable in which this Atom is inserted. More...
 
AtomTablegetAtomTable () const
 Returns the AtomTable in which this Atom is inserted. More...
 
bool isMarkedForRemoval () const
 
bool getFlag (int) const
 
void setFlag (int, bool)
 
void markForRemoval ()
 Marks the atom for removal. More...
 
void unsetRemovalFlag ()
 Unsets removal flag. More...
 
void chgVLTI (int unit)
 

Friends

class ::AtomUTest
 
class AtomStorage
 
class AtomTable
 
class ImportanceIndex
 
class Handle
 
class SavingLoading
 
class TLB
 
class CreateLink
 
class DeleteLink
 

Detailed Description

Atoms are the basic implementational unit in the system that represents nodes and links. In terms of inheritance, nodes and links are specialization of atoms, that is, they inherit all properties from atoms.

Definition at line 72 of file Atom.h.

Member Typedef Documentation

typedef std::shared_ptr<InSet> opencog::Atom::InSetPtr
protected

Definition at line 149 of file Atom.h.

Constructor & Destructor Documentation

opencog::Atom::Atom ( Type  t,
TruthValuePtr  tv = TruthValue::DEFAULT_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
inlineprotected

Constructor for this class. Protected; no user should call this directly. Only derived classes (Node, Link) can call this.

Parameters
Thetype of the atom.
Outgoingset of the atom, that is, the set of atoms this atom references. It must be an empty vector if the atom is a node.
ThetruthValue of the atom. note: This is not cloned as in setTruthValue.

Definition at line 121 of file Atom.h.

Atom::~Atom ( )
virtual

Member Function Documentation

void Atom::chgVLTI ( int  unit)
private

Change the Very-Long-Term Importance

Definition at line 196 of file Atom.cc.

References createAV, getAttentionValue(), and setAttentionValue().

+ Here is the caller graph for this function:

void opencog::Atom::decVLTI ( )
inline

Decrease the Very-Long-Term Importance by 1

Definition at line 268 of file Atom.h.

References chgVLTI().

+ Here is the caller graph for this function:

void Atom::drop_incoming_set ( )
protected

Stop tracking the incoming set for this atom. After this call, the incoming set for this atom can no longer be queried; it is erased.

Definition at line 279 of file Atom.cc.

References _incoming_set, and _mtx.

+ Here is the caller graph for this function:

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

Invoke the callback on each atom in the incoming set of handle h, until one of them returns true, in which case iteration stopsm and true is returned. Otherwise the callback is called on all incomings and false is returned.

Definition at line 329 of file Atom.h.

References getIncomingSet().

+ Here is the caller graph for this function:

AtomTable* opencog::Atom::getAtomTable ( ) const
inlineprivate

Returns the AtomTable in which this Atom is inserted.

Definition at line 90 of file Atom.h.

References _atomTable.

+ Here is the caller graph for this function:

AttentionValuePtr Atom::getAttentionValue ( )

Returns the AttentionValue object of the atom.

Returns
The pointer to the AttentionValue object of the atom.

Definition at line 146 of file Atom.cc.

References _attentionValue, and _mtx.

+ Here is the caller graph for this function:

bool Atom::getFlag ( int  flag) const
private

Returns an atom flag. A byte represents all flags. Each bit is one of them.

Parameters
Anint indicating which of the flags will be returned.
Returns
A boolean indicating if that flag is set or not.

Definition at line 213 of file Atom.cc.

References _flags.

Handle opencog::Atom::getHandle ( )
inline

Returns the handle of the atom.

Returns
The handle of the atom.

Definition at line 211 of file Atom.h.

References Handle.

+ Here is the caller graph for this function:

IncomingSet Atom::getIncomingSet ( )

Return the incoming set of this atom. The resulting incoming set consists of strong pointers, that is, to valid, non-null handles that were part of the incoming set at the time this call was made.

Definition at line 321 of file Atom.cc.

References _incoming_set, and _mtx.

+ Here is the caller graph for this function:

template<typename OutputIterator >
OutputIterator opencog::Atom::getIncomingSet ( OutputIterator  result)
inline

Place incoming set into STL container of Handles. Example usage: std::vector<Handle> hvect; atom->getIncomingSet(back_inserter(hvect)); The resulting vector hvect will contain only valid handles that were actually part of the incoming set at the time of the call to this function.

Definition at line 309 of file Atom.h.

References _incoming_set, _mtx, and python.bindlink::result.

template<typename OutputIterator >
OutputIterator opencog::Atom::getIncomingSetByType ( OutputIterator  result,
Type  type,
bool  subclass = false 
)
inline

Returns the set of atoms with a given target handle in their outgoing set (atom type and its subclasses optionally). That is, returns the incoming set of Handle h, with some optional filtering.

Parameters
Thehandle that must be in the outgoing set of the atom.
Theoptional type of the atom.
Whetheratom type subclasses should be considered.
Returns
The set of atoms of the given type with the given handle in their outgoing set.

Definition at line 353 of file Atom.h.

References _incoming_set, _mtx, and python.bindlink::result.

+ Here is the caller graph for this function:

IncomingSet Atom::getIncomingSetByType ( Type  type,
bool  subclass = false 
)

Functional version of getIncomingSetByType

Definition at line 337 of file Atom.cc.

References getIncomingSetByType(), and opencog::LinkCast().

size_t Atom::getIncomingSetSize ( )

Get the size of the incoming set.

Definition at line 310 of file Atom.cc.

References _incoming_set, and _mtx.

+ Here is the caller graph for this function:

AttentionValue::lti_t opencog::Atom::getLTI ( )
inline

Definition at line 231 of file Atom.h.

References getAttentionValue().

+ Here is the caller graph for this function:

AttentionValue::sti_t opencog::Atom::getSTI ( )
inline

Handy-dandy convenience getters for attention values.

Definition at line 226 of file Atom.h.

References getAttentionValue().

+ Here is the caller graph for this function:

TruthValuePtr Atom::getTruthValue ( )

Returns the TruthValue object of the atom.

Returns
The const referent to the TruthValue object of the atom.

Definition at line 104 of file Atom.cc.

References _mtx, and _truthValue.

+ Here is the caller graph for this function:

Type opencog::Atom::getType ( ) const
inline

Returns the type of the atom.

Returns
The type of the atom.

Definition at line 197 of file Atom.h.

References _type.

AttentionValue::vlti_t opencog::Atom::getVLTI ( )
inline

Definition at line 236 of file Atom.h.

References getAttentionValue().

+ Here is the caller graph for this function:

void opencog::Atom::incVLTI ( )
inline

Increase the Very-Long-Term Importance by 1

Definition at line 265 of file Atom.h.

References chgVLTI().

+ Here is the caller graph for this function:

void Atom::insert_atom ( LinkPtr  a)
protected

Add an atom to the incoming set.

Definition at line 289 of file Atom.cc.

References _incoming_set, and _mtx.

+ Here is the caller graph for this function:

bool Atom::isMarkedForRemoval ( ) const
private

Returns whether this atom is marked for removal.

Returns
Whether this atom is marked for removal.

Definition at line 208 of file Atom.cc.

References _flags, and MARKED_FOR_REMOVAL.

+ Here is the caller graph for this function:

bool opencog::Atom::isType ( Type  t,
bool  subclass 
) const
inline

Basic predicate

Definition at line 200 of file Atom.h.

References opencog::classserver(), getType(), and opencog::ClassServer::isA().

+ Here is the caller graph for this function:

void Atom::keep_incoming_set ( )
protected

Start tracking the incoming set for this atom. An atom can't know what it's incoming set is, until this method is called. If this atom is added to any links before this call is made, those links won't show up in the incoming set.

We don't automatically track incoming sets for two reasons: 1) std::set takes up 48 bytes 2) adding and remoiving uses up cpu cycles. Thus, if the incoming set isn't needed, then don't bother tracking it.

Definition at line 270 of file Atom.cc.

References _incoming_set.

void Atom::markForRemoval ( void  )
private

Marks the atom for removal.

Definition at line 232 of file Atom.cc.

References _flags, and MARKED_FOR_REMOVAL.

void Atom::merge ( TruthValuePtr  tvn)

merge truth value into this

Definition at line 122 of file Atom.cc.

References getTruthValue(), and setTruthValue().

+ Here is the caller graph for this function:

virtual bool opencog::Atom::operator!= ( const Atom ) const
pure virtual

Returns whether two atoms are different.

Returns
true if the atoms are different, false otherwise.

Implemented in opencog::Link, and opencog::Node.

virtual bool opencog::Atom::operator== ( const Atom ) const
pure virtual

Returns whether two atoms are equal.

Returns
true if the atoms are equal, false otherwise.

Implemented in opencog::Link, and opencog::Node.

void Atom::remove_atom ( LinkPtr  a)
protected

Remove an atom from the incoming set.

Definition at line 300 of file Atom.cc.

References _incoming_set, and _mtx.

+ Here is the caller graph for this function:

void Atom::setAtomTable ( AtomTable tb)
private

Sets the AtomTable in which this Atom is inserted.

Definition at line 239 of file Atom.cc.

References _atomTable, _uuid, opencog::Handle::UNDEFINED, and opencog::Handle::value().

void Atom::setAttentionValue ( AttentionValuePtr  av)
void Atom::setFlag ( int  flag,
bool  value 
)
private

Changes the value of the given flag.

Parameters
Anint indicating which of the flags will be set.
Aboolean indicating the new value of the flag.

Definition at line 218 of file Atom.cc.

References _flags.

void opencog::Atom::setLTI ( AttentionValue::lti_t  ltiValue)
inline

Change the Long-term Importance

Definition at line 254 of file Atom.h.

References createAV, getAttentionValue(), and setAttentionValue().

+ Here is the caller graph for this function:

void opencog::Atom::setSTI ( AttentionValue::sti_t  stiValue)
inline

Change the Short-Term Importance

Definition at line 242 of file Atom.h.

References createAV, getAttentionValue(), and setAttentionValue().

+ Here is the caller graph for this function:

void Atom::setTruthValue ( TruthValuePtr  newTV)

Sets the TruthValue object of the atom.

Definition at line 81 of file Atom.cc.

References _atomTable, _mtx, _truthValue, getHandle(), getTruthValue(), and opencog::AtomTable::TVChangedSignal().

+ Here is the caller graph for this function:

virtual std::string opencog::Atom::toShortString ( std::string  indent = "")
pure virtual

Implemented in opencog::Link, and opencog::Node.

+ Here is the caller graph for this function:

virtual std::string opencog::Atom::toString ( std::string  indent = "")
pure virtual

Returns a string representation of the node.

Returns
A string representation of the node. cannot be const, because observing the TV and AV requires a lock.

Implemented in opencog::Link, and opencog::Node.

+ Here is the caller graph for this function:

Handle opencog::Atom::tvmerge ( TruthValuePtr  tv)
inline

Merge truth value, return Handle for this. This allows oneliners such as: Handle h = atomSpace->addNode(FOO_NODE, "foo")->tvmerge(tv);

Definition at line 287 of file Atom.h.

References Handle, and merge().

void Atom::unsetRemovalFlag ( void  )
private

Unsets removal flag.

Definition at line 227 of file Atom.cc.

References _flags, and MARKED_FOR_REMOVAL.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ::AtomUTest
friend

Definition at line 75 of file Atom.h.

friend class AtomStorage
friend

Definition at line 76 of file Atom.h.

friend class AtomTable
friend

Definition at line 77 of file Atom.h.

friend class CreateLink
friend

Definition at line 82 of file Atom.h.

friend class DeleteLink
friend

Definition at line 83 of file Atom.h.

friend class Handle
friend

Definition at line 79 of file Atom.h.

friend class ImportanceIndex
friend

Definition at line 78 of file Atom.h.

friend class SavingLoading
friend

Definition at line 80 of file Atom.h.

friend class TLB
friend

Definition at line 81 of file Atom.h.

Member Data Documentation

AtomTable* opencog::Atom::_atomTable
protected

Definition at line 94 of file Atom.h.

AttentionValuePtr opencog::Atom::_attentionValue
protected

Definition at line 102 of file Atom.h.

char opencog::Atom::_flags
protected

Definition at line 99 of file Atom.h.

InSetPtr opencog::Atom::_incoming_set
protected

Definition at line 150 of file Atom.h.

std::mutex opencog::Atom::_mtx
protected

Definition at line 109 of file Atom.h.

TruthValuePtr opencog::Atom::_truthValue
protected

Definition at line 101 of file Atom.h.

Type opencog::Atom::_type
protected

Definition at line 96 of file Atom.h.

UUID opencog::Atom::_uuid
protected

Definition at line 93 of file Atom.h.


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