OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VariableList.h
Go to the documentation of this file.
1 /*
2  * opencog/atoms/VariableList.h
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 Free 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  * Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef _OPENCOG_VARIABLE_LIST_H
24 #define _OPENCOG_VARIABLE_LIST_H
25 
26 #include <map>
27 
29 #include <opencog/atomspace/Link.h>
30 #include <opencog/query/Pattern.h>
31 
32 namespace opencog
33 {
38 class VariableList : public Link
49 {
50 protected:
53 
54  // See VariableList.cc for comments
55  void get_vartype(const Handle&);
56 
57  // Validate the variable decls
58  void validate_vardecl(const Handle&);
59  void validate_vardecl(const HandleSeq&);
60 
61  VariableList(Type, const HandleSeq&,
64 
65  void build_index(void);
66  Handle substitute_nocheck(const Handle&, const HandleSeq&) const;
67 public:
68  VariableList(const HandleSeq& vardecls,
71 
73 
74  // Return the list of variables we are holding.
75  const Variables& get_variables(void) const { return _varlist; }
76 
77  // Return true if we are holding a single variable, and the handle
78  // given as the argument satisfies the type restrictions (if any).
79  // Else return false.
80  bool is_type(const Handle&) const;
81 
82  // Return true if the sequence is of the same length as the variable
83  // declarations we are holding, and if they satisfy all of the type
84  // restrictions (if any).
85  bool is_type(const HandleSeq&) const;
86 
87  // Given the tree `tree` containing variables in it, create and
88  // return a new tree with the indicated values `vals` substituted
89  // for the variables. The vals must pass the typecheck, else an
90  // exception is thrown.
91  Handle substitute(const Handle& tree, const HandleSeq& vals) const;
92 };
93 
94 typedef std::shared_ptr<VariableList> VariableListPtr;
95 static inline VariableListPtr VariableListCast(const Handle& h)
96  { AtomPtr a(h); return std::dynamic_pointer_cast<VariableList>(a); }
98  { return std::dynamic_pointer_cast<VariableList>(a); }
99 
100 // XXX temporary hack ...
101 #define createVariableList std::make_shared<VariableList>
102 
104 }
105 
106 #endif // _OPENCOG_VARIABLE_LIST_H
Variables _varlist
Unbundled variables and types for them.
Definition: VariableList.h:52
void validate_vardecl(const Handle &)
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
std::shared_ptr< Atom > AtomPtr
Definition: Handle.h:48
bool is_type(const Handle &) const
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::shared_ptr< AttentionValue > AttentionValuePtr
std::shared_ptr< VariableList > VariableListPtr
Definition: VariableList.h:94
void get_vartype(const Handle &)
Handle substitute_nocheck(const Handle &, const HandleSeq &) const
static TruthValuePtr DEFAULT_TV()
Definition: TruthValue.cc:52
static VariableListPtr VariableListCast(const Handle &h)
Definition: VariableList.h:95
Handle substitute(const Handle &tree, const HandleSeq &vals) const
static AttentionValuePtr DEFAULT_AV()
to be used as default attention value
VariableList(Type, const HandleSeq &, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
Definition: VariableList.cc:62
const Variables & get_variables(void) const
Definition: VariableList.h:75
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40