OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Node.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/Node.h
3  *
4  * Copyright (C) 2002-2007 Novamente LLC
5  * All Rights Reserved
6  *
7  * Written by Thiago Maia <thiago@vettatech.com>
8  * Andre Senna <senna@vettalabs.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License v3 as
12  * published by the Free Software Foundation and including the exceptions
13  * at http://opencog.org/wiki/Licenses
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program; if not, write to:
22  * Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef _OPENCOG_NODE_H
27 #define _OPENCOG_NODE_H
28 
29 #include <opencog/util/oc_assert.h>
30 #include <opencog/atomspace/Atom.h>
31 
32 namespace opencog
33 {
42 class Node : public Atom
43 {
44 protected:
45  // properties
46  std::string _name;
47  void init(const std::string&);
48 
49  Node(const Node &l) : Atom(0)
50  { OC_ASSERT(false, "Node: bad use of copy ctor"); }
51 
52 public:
61  Node(Type t, const std::string& s,
64  : Atom(t,tv,av)
65  {
66  init(s);
67  }
68 
74  Node(Node &n)
75  : Atom(n.getType(),
76  n.getTruthValue()->clone(),
77  n.getAttentionValue()->clone())
78  {
79  init(n._name);
80  }
81 
87  inline const std::string& getName() const { return _name; }
88 
94  std::string toString(std::string indent = "");
95  std::string toShortString(std::string indent = "");
96 
102  virtual bool operator==(const Atom&) const;
103 
109  virtual bool operator!=(const Atom&) const;
110 };
111 
112 typedef std::shared_ptr<Node> NodePtr;
113 static inline NodePtr NodeCast(const Handle& h)
114  { AtomPtr a(h); return std::dynamic_pointer_cast<Node>(a); }
115 static inline NodePtr NodeCast(const AtomPtr& a)
116  { return std::dynamic_pointer_cast<Node>(a); }
117 
118 // XXX temporary hack ...
119 #define createNode std::make_shared<Node>
120 
122 } // namespace opencog
123 
124 #endif // _OPENCOG_NODE_H
AttentionValuePtr getAttentionValue()
Definition: Atom.cc:146
Node(Type t, const std::string &s, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
Definition: Node.h:61
std::shared_ptr< Atom > AtomPtr
Definition: Handle.h:48
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::shared_ptr< AttentionValue > AttentionValuePtr
Node(const Node &l)
Definition: Node.h:49
std::string toString(std::string indent="")
Definition: Node.cc:59
Type getType() const
Definition: Atom.h:197
static NodePtr NodeCast(const Handle &h)
Definition: Node.h:113
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
Node(Node &n)
Definition: Node.h:74
std::string toShortString(std::string indent="")
Definition: Node.cc:45
const std::string & getName() const
Definition: Node.h:87
static TruthValuePtr DEFAULT_TV()
Definition: TruthValue.cc:52
static AttentionValuePtr DEFAULT_AV()
to be used as default attention value
std::shared_ptr< Node > NodePtr
Definition: Node.h:112
TruthValuePtr getTruthValue()
Definition: Atom.cc:104
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
virtual bool operator==(const Atom &) const
Definition: Node.cc:77