OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FunctionLink.cc
Go to the documentation of this file.
1 /*
2  * opencog/atoms/reduct/FunctionLink.cc
3  *
4  * Copyright (C) 2015 Linas Vepstas
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License v3 as
9  * published by the Function Software Foundation and including the exceptions
10  * at http://opencog.org/wiki/Licenses
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program; if not, write to:
19  * Function Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include <opencog/atomspace/atom_types.h>
25 #include "FunctionLink.h"
26 
27 #include "AssignLink.h"
28 #include "DeleteLink.h"
29 #include "PlusLink.h"
30 #include "TimesLink.h"
31 
32 using namespace opencog;
33 
37  : FreeLink(t, oset, tv, av)
38 {
39  if (not classserver().isA(t, FUNCTION_LINK))
40  throw InvalidParamException(TRACE_INFO, "Expecting a FunctionLink");
41  init();
42 }
43 
47  : FreeLink(t, a, tv, av)
48 {
49  if (not classserver().isA(t, FUNCTION_LINK))
50  throw InvalidParamException(TRACE_INFO, "Expecting a FunctionLink");
51  init();
52 }
53 
57  : FreeLink(t, a, b, tv, av)
58 {
59  if (not classserver().isA(t, FUNCTION_LINK))
60  throw InvalidParamException(TRACE_INFO, "Expecting a FunctionLink");
61  init();
62 }
63 
65  : FreeLink(l)
66 {
67  Type tscope = l.getType();
68  if (not classserver().isA(tscope, FUNCTION_LINK))
69  throw InvalidParamException(TRACE_INFO, "Expecting a FunctionLink");
70  init();
71 }
72 
74 {
75  throw RuntimeException(TRACE_INFO, "Not executable: %s\n",
76  classserver().getTypeName(getType()).c_str());
77 }
78 
80 {
81  // If h is of the right form already, its just a matter of calling
82  // it. Otherwise, we have to create
84  if (NULL == flp)
85  throw RuntimeException(TRACE_INFO, "Not executable!");
86 
87  return flp->execute(as);
88 }
89 
91 {
92  if (NULL == lp)
93  throw RuntimeException(TRACE_INFO, "Not executable!");
94 
95  // If h is of the right form already, its just a matter of calling
96  // it. Otherwise, we have to create
98  if (flp) return lp;
99 
100  return LinkCast(factory(lp->getType(), lp->getOutgoingSet()));
101 }
102 
103 // Basic type factory.
105 {
106  if (ASSIGN_LINK == t)
107  return Handle(createAssignLink(seq));
108 
109  if (DELETE_LINK == t)
110  return Handle(createDeleteLink(seq));
111 
112  if (INSERT_LINK == t)
113  return Handle(createInsertLink(seq));
114 
115  if (PLUS_LINK == t)
116  return Handle(createPlusLink(seq));
117 
118  if (REMOVE_LINK == t)
119  return Handle(createRemoveLink(seq));
120 
121  if (TIMES_LINK == t)
122  return Handle(createTimesLink(seq));
123 
124  // XXX FIXME In principle, we should manufacture the
125  // ExecutionOutputLink as well. In practice, we can't, due to a
126  // circular shared library dependency between python and itself.
127  // (Python depends on ExecutionOutputLink and ExecutionOutputLink
128  // depends on python. Whoops!)
129  if (EXECUTION_OUTPUT_LINK == t)
130  // return Handle(createExecutionOutputLink(seq));
131  throw RuntimeException(TRACE_INFO, "Can't be a factory for this!");
132 
133  throw RuntimeException(TRACE_INFO, "Not executable!");
134 }
friend class Handle
Definition: Atom.h:79
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
#define createDeleteLink
Definition: DeleteLink.h:65
Type getType() const
Definition: Atom.h:197
#define createInsertLink
Definition: AssignLink.h:151
#define createTimesLink
Definition: TimesLink.h:71
std::shared_ptr< Link > LinkPtr
Definition: Atom.h:53
std::shared_ptr< FunctionLink > FunctionLinkPtr
Definition: FunctionLink.h:78
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
Definition: ClassServer.cc:159
#define createRemoveLink
Definition: AssignLink.h:175
static FunctionLinkPtr FunctionLinkCast(const Handle &h)
Definition: FunctionLink.h:79
#define createAssignLink
Definition: AssignLink.h:127
static LinkPtr LinkCast(const Handle &h)
Definition: Link.h:263
#define createPlusLink
Definition: PlusLink.h:71
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40