![]() |
Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
|
Storage of named variables, and management of new, anonymous and unique variables. More...
#include <VariableIndex.hpp>
Public Member Functions | |
VariableIndex (const VariableIndex &)=delete | |
Copying this would be a very silly idea, so explicitly disallow it. | |
VariableIndex (const VariableIndex &&)=delete | |
VariableIndex & | operator= (const VariableIndex &)=delete |
VariableIndex & | operator= (const VariableIndex &&)=delete |
ID | get_next_index () const |
Straightforward access function. | |
ID | get_first_anon_variable () const |
Straightforward access function. | |
ID | get_highest_anon_variable () const |
Straightforward access function. | |
bool | get_all_names_added () const |
Straightforward access function. | |
size_t | get_num_backtracks () const |
Straightforward access function. | |
Variable * | add_named_var (const string &) |
Add a variable with the specified name to the index. | |
Variable * | add_anon_var () |
Add an anonymous variable. | |
Variable * | add_unique_var () |
Add a unique variable when converting to CNF. | |
Variable * | find_variable (const string &) |
Look up a variable by name. | |
void | set_all_names_added () |
Call this to indicate that only anonymous variables can now be created. | |
void | clear_substitutions () |
Undo all substitutions made, to anything, ever. | |
void | add_backtrack_point () |
Add a backtrack point. | |
ID | add_named_backtrack_point () |
Same as add_backtrack_point, but return an identifier allowing multiple levels of backtracking using backtrack_to_named_point. | |
void | backtrack () |
Backtrack to the last marker. | |
void | backtrack_to_named_point (ID) |
Backtrack, possibly multiple times, to the specified point. | |
void | reset () |
Get rid of all the markers used for backtracking. | |
Private Attributes | |
vector< Variable * > | vars |
All the variables made, named, unique and anonymous. | |
unordered_map< string, Variable * > | name_index |
Fast lookup of Variables by name. | |
ID | next_index |
Keep track of automatically generated Variable indices. | |
ID | next_unique_index |
When converting to CNF you need new, unique variables, but they need to be treated separately from anonymous variables. | |
ID | first_anon_variable |
Set after you've added all the named variables for the problem. | |
ID | highest_anon_variable |
Keep track of how many anonymous Variables you currently have available. | |
bool | all_names_added |
Set after you've added all the named variables for the problem. | |
vector< ID > | backtrack_points |
Backtrack points stored as indices in the vars vector. | |
Friends | |
ostream & | operator<< (ostream &, const VariableIndex &) |
Storage of named variables, and management of new, anonymous and unique variables.
Variables are only stored once, and I want backtracking to be easy while recycling old anonymous variables. You should only add named variables once, at the beginning of the process.
You should only make variables using this index. If you do then it takes care of allocation/deallocation for you.
Definition at line 61 of file VariableIndex.hpp.
VariableIndex::VariableIndex | ( | ) |
Definition at line 28 of file VariableIndex.cpp.
VariableIndex::~VariableIndex | ( | ) |
Definition at line 39 of file VariableIndex.cpp.
|
delete |
Copying this would be a very silly idea, so explicitly disallow it.
As usual, let the compiler be your friend.
Variable * VariableIndex::add_anon_var | ( | ) |
Add an anonymous variable.
Anonymous variables are recycled after backtracking. Also denies addition of new named variables if you didn't do that yourself. Anonymous variables do get names of the form "_next_index" but are not currently included in the map as they can be found by other means if you absolutely need to, which you shouldn't.
Definition at line 73 of file VariableIndex.cpp.
void VariableIndex::add_backtrack_point | ( | ) |
Add a backtrack point.
This is straightforward. All we have to do is remember a starting point so that all anonymous variables after that can easily be reused.
It is the responsibility of the user to insert and maintain an initial backtrack point at the first anonymous variable.
Definition at line 125 of file VariableIndex.cpp.
ID VariableIndex::add_named_backtrack_point | ( | ) |
Same as add_backtrack_point, but return an identifier allowing multiple levels of backtracking using backtrack_to_named_point.
Definition at line 129 of file VariableIndex.cpp.
Variable * VariableIndex::add_named_var | ( | const string & | name | ) |
Add a variable with the specified name to the index.
Only allow a named variable to be added once, and before any anonymous variables. If you add something twice you'll just get a pointer to the first copy.
name | Name of Variable to add. |
Definition at line 44 of file VariableIndex.cpp.
Variable * VariableIndex::add_unique_var | ( | ) |
Add a unique variable when converting to CNF.
Does not immediately deny addition of further named variables.
Definition at line 95 of file VariableIndex.cpp.
void VariableIndex::backtrack | ( | ) |
Backtrack to the last marker.
This is straightforward. Substitutions do not have to be undone here as that will happen if a variable is reused.
Definition at line 134 of file VariableIndex.cpp.
void VariableIndex::backtrack_to_named_point | ( | ID | id | ) |
Backtrack, possibly multiple times, to the specified point.
Definition at line 143 of file VariableIndex.cpp.
void VariableIndex::clear_substitutions | ( | ) |
Undo all substitutions made, to anything, ever.
Definition at line 68 of file VariableIndex.cpp.
Variable * VariableIndex::find_variable | ( | const string & | var_name | ) |
Look up a variable by name.
var_name | Name of Variable to find. |
Definition at line 102 of file VariableIndex.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void VariableIndex::reset | ( | ) |
Get rid of all the markers used for backtracking.
Clears all backtracking information.
Definition at line 151 of file VariableIndex.cpp.
void VariableIndex::set_all_names_added | ( | ) |
Call this to indicate that only anonymous variables can now be created.
Note: this also adds a backtrack point at the first (currently not created) anonymous variable.
Definition at line 63 of file VariableIndex.cpp.
|
friend |
Definition at line 158 of file VariableIndex.cpp.
|
private |
Set after you've added all the named variables for the problem.
Used to detect erronious addition of further named Variables.
Definition at line 102 of file VariableIndex.hpp.
|
private |
Backtrack points stored as indices in the vars vector.
Definition at line 107 of file VariableIndex.hpp.
|
private |
Set after you've added all the named variables for the problem.
Allows you to know where in vars the problem variables stop and the anonymous variables start.
Definition at line 89 of file VariableIndex.hpp.
|
private |
Keep track of how many anonymous Variables you currently have available.
Definition at line 94 of file VariableIndex.hpp.
|
private |
Fast lookup of Variables by name.
Definition at line 70 of file VariableIndex.hpp.
|
private |
Keep track of automatically generated Variable indices.
Definition at line 75 of file VariableIndex.hpp.
|
private |
When converting to CNF you need new, unique variables, but they need to be treated separately from anonymous variables.
Definition at line 81 of file VariableIndex.hpp.
|
private |
All the variables made, named, unique and anonymous.
Definition at line 66 of file VariableIndex.hpp.