OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BindLink.cc
Go to the documentation of this file.
1 /*
2  * BindLink.cc
3  *
4  * Copyright (C) 2009, 2014, 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 
28 
29 #include "BindLink.h"
30 
31 using namespace opencog;
32 
33 void BindLink::init(void)
34 {
37  common_init();
39  _pat.redex_name = "anonymous BindLink";
40 }
41 
44  : PatternLink(BIND_LINK, hseq, tv, av)
45 {
46  init();
47 }
48 
51  : PatternLink(t, hseq, tv, av)
52 {
53  init();
54 }
55 
57  : PatternLink(l)
58 {
59  Type t = l.getType();
60  if (not classserver().isA(t, BIND_LINK))
61  {
62  const std::string& tname = classserver().getTypeName(t);
63  throw InvalidParamException(TRACE_INFO,
64  "Expecting a BindLink, got %s", tname.c_str());
65  }
66 
67  init();
68 }
69 
70 /* ================================================================= */
79 {
80  size_t sz = oset.size();
81  if (3 < sz)
82  throw InvalidParamException(TRACE_INFO,
83  "Expecting an outgoing set size of at most two, got %d", sz);
84 
85  // If the outgoing set size is one, then there are no variable
86  // declarations; extract all free variables.
87  if (2 == sz)
88  {
89  _body = oset[0];
90  _implicand = oset[1];
91 
92  // Use the FreeLink class to find all the variables;
93  // Use the VariableList class for build the Variables struct.
94  FreeLink fl(oset[0]);
95  VariableList vl(fl.get_vars());
96  _varlist = vl.get_variables();
97  return;
98  }
99 
100  // If we are here, then the first outgoing set member should be
101  // a variable declaration.
102  _body = oset[1];
103  _implicand = oset[2];
104 
105  // Initialize _varlist with the scoped variables
106  init_scoped_variables(oset[0]);
107 }
108 
109 /* ===================== END OF FILE ===================== */
std::string redex_name
Definition: Pattern.h:94
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
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