forked from teamnwah/openmw-tes3coop
Cleaned up superflous functions in BSA archive. Started working on input system.
parent
86b78b18f4
commit
d5228c6f5f
@ -0,0 +1,2 @@
|
||||
*_test
|
||||
|
@ -0,0 +1,9 @@
|
||||
GCC=g++
|
||||
|
||||
all: funcbind_test
|
||||
|
||||
funcbind_test: funcbind_test.cpp
|
||||
$(GCC) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm *_test
|
@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/function.hpp>
|
||||
#include <assert.h>
|
||||
|
||||
typedef boost::function<void()> Action;
|
||||
|
||||
struct FuncBind
|
||||
{
|
||||
std::string name;
|
||||
Action action;
|
||||
};
|
||||
|
||||
class Binder
|
||||
{
|
||||
std::vector<FuncBind> bindings;
|
||||
|
||||
public:
|
||||
/**
|
||||
Initialize the struct by telling it how many functions you have
|
||||
to bind. The largest index you intend to use should be number-1.
|
||||
*/
|
||||
Binder(int number) : bindings(number) {}
|
||||
|
||||
void bind(int index, Action action, const std::string &name="")
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
fb.action = action;
|
||||
fb.name = name;
|
||||
}
|
||||
|
||||
void unbind(int index)
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
fb = FuncBind();
|
||||
}
|
||||
|
||||
void call(int index)
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
if(fb.action)
|
||||
{
|
||||
cout << "Calling '" << fb.name << "'\n";
|
||||
fb.action();
|
||||
}
|
||||
else
|
||||
cout << "No function\n";
|
||||
}
|
||||
};
|
||||
|
||||
void f1()
|
||||
{
|
||||
cout << "In f1()\n";
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
cout << "In f2()\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "This will test the function binding system\n";
|
||||
|
||||
Binder bnd(5);
|
||||
|
||||
bnd.bind(0, &f1, "This is action 1");
|
||||
bnd.bind(1, &f2);
|
||||
bnd.bind(2, &f1, "This is action 3");
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
cout << "\nCalling " << i << endl;
|
||||
bnd.call(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
This will test the function binding system
|
||||
|
||||
Calling 0
|
||||
Calling 'This is action 1'
|
||||
In f1()
|
||||
|
||||
Calling 1
|
||||
Calling ''
|
||||
In f2()
|
||||
|
||||
Calling 2
|
||||
Calling 'This is action 3'
|
||||
In f1()
|
||||
|
||||
Calling 3
|
||||
No function
|
||||
|
||||
Calling 4
|
||||
No function
|
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
make || exit
|
||||
|
||||
mkdir -p output
|
||||
|
||||
PROGS=*_test
|
||||
|
||||
for a in $PROGS; do
|
||||
if [ -f "output/$a.out" ]; then
|
||||
echo "Running $a:"
|
||||
./$a | diff output/$a.out -
|
||||
else
|
||||
echo "Creating $a.out"
|
||||
./$a > "output/$a.out"
|
||||
git add "output/$a.out"
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue