29 #include <opencog/util/exceptions.h>
30 #include <opencog/util/Logger.h>
37 using namespace opencog;
51 void Link::init(
const std::vector<Handle>& outgoingVector)
52 throw (InvalidParamException)
55 throw InvalidParamException(TRACE_INFO,
56 "Link ctor: Atom type is not a Link: '%d' %s.",
60 _outgoing = outgoingVector;
75 std::stringstream answer;
76 std::string more_indent = indent +
" ";
84 if (h.operator->() != NULL)
85 answer << h->toShortString(more_indent);
87 answer << indent <<
"Undefined Atom!\n";
90 answer << indent <<
") ; [" <<
_uuid <<
"]\n";
97 std::string more_indent = indent +
" ";
99 static char buf[
BUFSZ];
101 snprintf(buf,
BUFSZ,
"(%s (av %d %d %d) %s\n",
107 answer = indent + buf;
111 if (h.operator->() != NULL)
112 answer += h->toString(more_indent);
114 answer += indent +
"Undefined Atom!\n";
117 answer += indent +
") ; [" +
118 std::to_string(
_uuid).c_str() +
"]\n";
127 Arity arity = getArity();
129 return arity > 0 && _outgoing[0] == handle;
130 }
else if (
classserver().isA(_type, UNORDERED_LINK)) {
133 for (
Arity i = 0; i < arity; i++) {
134 if (_outgoing[i] == handle) {
140 throw InvalidParamException(TRACE_INFO,
"Link::isSource(Handle) unknown link type %d", _type);
145 bool Link::isSource(
size_t i)
const throw (IndexErrorException, InvalidParamException)
148 if (i > getArity()) {
149 throw IndexErrorException(TRACE_INFO,
"Link::isSource(size_t) invalid index argument");
156 }
else if (
classserver().isA(_type, UNORDERED_LINK)) {
161 throw InvalidParamException(TRACE_INFO,
"Link::isSource(int) unknown link type %d", _type);
171 Arity arity = getArity();
173 for (
Arity i = 1; i < arity; i++) {
174 if (_outgoing[i] == handle) {
179 }
else if (
classserver().isA(_type, UNORDERED_LINK)) {
181 for (
Arity i = 0; i < arity; i++) {
182 if (_outgoing[i] == handle) {
188 throw InvalidParamException(TRACE_INFO,
"Link::isTarget(Handle) unknown link type %d", _type);
193 bool Link::isTarget(
size_t i)
const throw (IndexErrorException, InvalidParamException)
196 if (i > getArity()) {
197 throw IndexErrorException(TRACE_INFO,
"Link::istarget(int) invalid index argument");
204 }
else if (
classserver().isA(_type, UNORDERED_LINK)) {
209 throw InvalidParamException(TRACE_INFO,
"Link::isTarget(int) unkown link type");
217 const Link& olink =
dynamic_cast<const Link&
>(other);
220 if (arity != olink.
getArity())
return false;
221 for (
Arity i = 0; i < arity; i++)
228 return !(*
this == other);
AttentionValuePtr getAttentionValue()
virtual bool operator!=(const Atom &) const
std::string toShortString(std::string indent="")
AttentionValue::lti_t getLTI()
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
AttentionValue::vlti_t getVLTI()
bool isTarget(Handle) const
void init(const HandleSeq &)
std::string toString(std::string indent="")
bool isSource(Handle) const
bool operator()(const Handle &h1, const Handle &h2) const
const std::string & getTypeName(Type type)
TruthValuePtr getTruthValue()
AttentionValue::sti_t getSTI()
Handy-dandy convenience getters for attention values.
virtual bool operator==(const Atom &) const
unsigned short Arity
arity of Links, represented as short integer (16 bits)
static int compare(const Handle &h1, const Handle &h2)