add some const
This commit is contained in:
parent
5f8e2b75fa
commit
390d447d9b
2 changed files with 19 additions and 11 deletions
|
@ -17,9 +17,9 @@ extern "C" {
|
||||||
namespace ob {
|
namespace ob {
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
static void print_branch(BindingTree *first, std::string str)
|
static void print_branch(const BindingTree *first, std::string str)
|
||||||
{
|
{
|
||||||
BindingTree *p = first;
|
const BindingTree *p = first;
|
||||||
|
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->first_child)
|
if (p->first_child)
|
||||||
|
@ -95,7 +95,8 @@ static bool modvalue(const std::string &mod, unsigned int *val)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OBBindings::translate(const std::string &str, Binding &b, bool askey)
|
bool OBBindings::translate(const std::string &str, Binding &b,
|
||||||
|
bool askey) const
|
||||||
{
|
{
|
||||||
// parse out the base key name
|
// parse out the base key name
|
||||||
std::string::size_type keybegin = str.find_last_of('-');
|
std::string::size_type keybegin = str.find_last_of('-');
|
||||||
|
@ -138,7 +139,7 @@ static void destroytree(BindingTree *tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BindingTree *OBBindings::buildtree(const StringVect &keylist, int id)
|
BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const
|
||||||
{
|
{
|
||||||
if (keylist.empty()) return 0; // nothing in the list.. return 0
|
if (keylist.empty()) return 0; // nothing in the list.. return 0
|
||||||
|
|
||||||
|
@ -240,8 +241,10 @@ void OBBindings::assimilate(BindingTree *node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int OBBindings::find_key(BindingTree *search) {
|
int OBBindings::find_key(BindingTree *search) const {
|
||||||
BindingTree *a, *b;
|
BindingTree *a, *b;
|
||||||
|
print_branch(&_keytree, " Searching:");
|
||||||
|
print_branch(search, " for...");
|
||||||
a = _keytree.first_child;
|
a = _keytree.first_child;
|
||||||
b = search;
|
b = search;
|
||||||
while (a && b) {
|
while (a && b) {
|
||||||
|
@ -249,10 +252,14 @@ int OBBindings::find_key(BindingTree *search) {
|
||||||
a = a->next_sibling;
|
a = a->next_sibling;
|
||||||
} else {
|
} else {
|
||||||
if (a->chain == b->chain) {
|
if (a->chain == b->chain) {
|
||||||
if (!a->chain)
|
if (!a->chain) {
|
||||||
|
printf("Match found with %s\n", a->text.c_str());
|
||||||
return a->id; // found it! (return the actual id, not the search's)
|
return a->id; // found it! (return the actual id, not the search's)
|
||||||
} else
|
}
|
||||||
return -2; // the chain status' don't match (conflict!)
|
} else {
|
||||||
|
printf("Conflict found with %s\n", a->text.c_str());
|
||||||
|
return -2; // the chain status' don't match (conflict!)
|
||||||
|
}
|
||||||
b = b->first_child;
|
b = b->first_child;
|
||||||
a = a->first_child;
|
a = a->first_child;
|
||||||
}
|
}
|
||||||
|
@ -271,6 +278,7 @@ bool OBBindings::add_key(const StringVect &keylist, int id)
|
||||||
|
|
||||||
if (find_key(tree) != -1) {
|
if (find_key(tree) != -1) {
|
||||||
// conflicts with another binding
|
// conflicts with another binding
|
||||||
|
printf("Conflict\n");
|
||||||
destroytree(tree);
|
destroytree(tree);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,9 @@ private:
|
||||||
|
|
||||||
BindingTree *_mousetree; // this tree is a list. it has only siblings
|
BindingTree *_mousetree; // this tree is a list. it has only siblings
|
||||||
|
|
||||||
int find_key(BindingTree *search);
|
int find_key(BindingTree *search) const;
|
||||||
bool translate(const std::string &str, Binding &b, bool askey);
|
bool translate(const std::string &str, Binding &b, bool askey) const;
|
||||||
BindingTree *buildtree(const StringVect &keylist, int id);
|
BindingTree *buildtree(const StringVect &keylist, int id) const;
|
||||||
void OBBindings::assimilate(BindingTree *node);
|
void OBBindings::assimilate(BindingTree *node);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue