OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DeleteLink.cc
Go to the documentation of this file.
1 /*
2  * DeleteLink.cc
3  *
4  * Copyright (C) 2015 Linas Vepstas
5  *
6  * Author: Linas Vepstas <linasvepstas@gmail.com> January 2009
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
11  * exceptions
12  * at http://opencog.org/wiki/Licenses
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public
20  * 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 
30 
31 #include "DeleteLink.h"
32 
33 using namespace opencog;
34 
35 void DeleteLink::init(void)
36 {
37  // The handleset must contain a free variable in it, somewhere.
38  // If it doesn't, then the entire Handleset should be deleted
39  // (removed from the atomspace). We can't do this at constructor
40  // time, because we don't know the atomspace yet. So we hack
41  // around this by thowing at construtor time.
42  //
43  if (0 == _varseq.size())
44  // throw DeleteException();
45  throw InvalidParamException(TRACE_INFO,
46  "Cannot create a fully grounded DeleteLink!");
47 }
48 
49 #if 0
50 /*****
51 Well, we cannot really implement this here; but this is what
52 it should actually do. We can't implement it here, because
53 fully-grounded DeleteLink's cannot exist.
54 ****/
56 {
57  const HandleSeq& oset = _outgoing;
58  for (const Handle& h : oset)
59  {
60  Type t = h->getType();
61  if (VARIABLE_NODE != t)
62  as->removeAtom(h, true);
63  }
64  return Handle::UNDEFINED;
65 }
66 #endif
67 
70  : FunctionLink(DELETE_LINK, oset, tv, av)
71 {
72  init();
73 }
74 
76  : FunctionLink(l)
77 {
78  // Type must be as expected
79  Type tscope = l.getType();
80  if (not classserver().isA(tscope, DELETE_LINK))
81  {
82  const std::string& tname = classserver().getTypeName(tscope);
83  throw InvalidParamException(TRACE_INFO,
84  "Expecting a DeleteLink, got %s", tname.c_str());
85  }
86 
87  init();
88 }
89 
90 /* ===================== END OF FILE ===================== */
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::shared_ptr< AttentionValue > AttentionValuePtr
Type getType() const
Definition: Atom.h:197
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
Definition: ClassServer.cc:159
static const Handle UNDEFINED
Definition: Handle.h:77
const std::string & getTypeName(Type type)
Definition: ClassServer.cc:148
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40