OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Node.cc
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/Node.cc
3  *
4  * Copyright (C) 2008-2010 OpenCog Foundation
5  * Copyright (C) 2002-2007 Novamente LLC
6  * All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License v3 as
10  * published by the Free Software Foundation and including the exceptions
11  * at http://opencog.org/wiki/Licenses
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program; if not, write to:
20  * Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #include <stdio.h>
25 
27 #include <opencog/atomspace/Link.h>
28 #include <opencog/util/Logger.h>
29 
30 #include "Node.h"
31 
32 using namespace opencog;
33 
34 void Node::init(const std::string& cname)
35 {
36  if (not classserver().isA(_type, NODE))
37  {
38  throw InvalidParamException(TRACE_INFO,
39  "Node - Invalid node type '%d' %s.",
40  _type, classserver().getTypeName(_type).c_str());
41  }
42  _name = cname;
43 }
44 
45 std::string Node::toShortString(std::string indent)
46 {
47  std::string tmpname = _name;
48  if (_name == "")
49  tmpname = "#" + std::to_string(_uuid);
50 
51  std::string nam = indent +
52  "(" + classserver().getTypeName(_type) +
53  // + getTruthValue()->toString() + ")\n";
54  " \"" + tmpname + "\") ; [" +
55  std::to_string(_uuid) + "]\n";
56  return nam;
57 }
58 
59 std::string Node::toString(std::string indent)
60 {
61 #define BUFSZ 256
62  char buf[BUFSZ + _name.size()];
63  std::string tmpname = _name;
64  if (_name == "")
65  tmpname = "#" + std::to_string(_uuid);
66  snprintf(buf, BUFSZ, "(%s \"%s\" (av %d %d %d) %s) ; [%lu]\n",
67  classserver().getTypeName(_type).c_str(),
68  tmpname.c_str(),
69  (int)getAttentionValue()->getSTI(),
70  (int)getAttentionValue()->getLTI(),
71  (int)getAttentionValue()->getVLTI(),
72  getTruthValue()->toString().c_str(),
73  _uuid);
74  return indent + buf;
75 }
76 
77 bool Node::operator==(const Atom& other) const
78 {
79  return (getType() == other.getType()) and
80  (getName() == dynamic_cast<const Node&>(other).getName());
81 }
82 
83 bool Node::operator!=(const Atom& other) const
84 {
85  return not (*this == other);
86 }
AttentionValuePtr getAttentionValue()
Definition: Atom.cc:146
#define BUFSZ
UUID _uuid
Definition: Atom.h:93
std::string toString(std::string indent="")
Definition: Node.cc:59
Type getType() const
Definition: Atom.h:197
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
Definition: ClassServer.cc:159
virtual bool operator!=(const Atom &) const
Definition: Node.cc:83
std::string _name
Definition: Node.h:46
void init(const std::string &)
Definition: Node.cc:34
std::string toShortString(std::string indent="")
Definition: Node.cc:45
const std::string & getName() const
Definition: Node.h:87
const std::string & getTypeName(Type type)
Definition: ClassServer.cc:148
TruthValuePtr getTruthValue()
Definition: Atom.cc:104
Type _type
Definition: Atom.h:96
virtual bool operator==(const Atom &) const
Definition: Node.cc:77