Created
July 16, 2012 07:57
-
-
Save djsutherland/3121435 to your computer and use it in GitHub Desktop.
Test code for http://stackoverflow.com/q/11479139/344821
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.o | |
*.so | |
*.a | |
*.mex* | |
test_s.cpp | |
test | |
test_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXX=g++ | |
MEX=mex | |
MEX_EXT=mexmaci64 | |
CFLAGS=-I/usr/local/include | |
.PHONY: all clean run | |
all: test test_s test.$(MEX_EXT) test_s.$(MEX_EXT) | |
clean: | |
rm -f stubby.o libstubby.{a,so} test{,_s}{,.$(MEX_EXT)} test_s.cpp | |
run: all | |
./test | |
./test_s | |
echo | matlab -nosplash -nodesktop -r test | |
echo | matlab -nosplash -nodesktop -r test_s | |
test: test.cpp libstubby.so the_enum.hpp | |
$(CXX) $(CFLAGS) -o test test.cpp libstubby.so -DNO_MEX | |
test_s: test.cpp libstubby.a the_enum.hpp | |
$(CXX) $(CFLAGS) -o test_s test.cpp libstubby.a -DNO_MEX | |
test_s.cpp: | |
ln -sf test.cpp test_s.cpp | |
test.$(MEX_EXT): test_s.cpp libstubby.so the_enum.hpp | |
$(MEX) $(CFLAGS) test.cpp libstubby.so | |
test_s.$(MEX_EXT): test.cpp libstubby.a the_enum.hpp | |
$(MEX) $(CFLAGS) test_s.cpp libstubby.a | |
libstubby.so: stubby.cpp stubby.hpp the_enum.hpp | |
$(CXX) $(CFLAGS) -shared -o libstubby.so stubby.cpp | |
libstubby.a: stubby.o | |
ar rcs libstubby.a stubby.o | |
stubby.o: stubby.cpp stubby.hpp the_enum.hpp | |
$(CXX) $(CFLAGS) -c -o stubby.o stubby.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stubby.hpp" | |
#include <cstdio> | |
boost::any the_function() { | |
return boost::any(library::el_two); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _STUBBY_HPP | |
#define _STUBBY_HPP | |
#include <boost/any.hpp> | |
#include "the_enum.hpp" | |
boost::any the_function(); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stubby.hpp" | |
#include <boost/any.hpp> | |
#ifdef NO_MEX | |
#include <cstdio> | |
using std::printf; | |
int main() { | |
#else | |
#include "mex.h" | |
void mexFunction(int nlhs, mxArray **plhs, int nrhs, const mxArray **prsh) { | |
#endif | |
using library::the_enum_t; | |
boost::any val_any = the_function(); | |
printf("%s (equal: %d)\n", | |
val_any.type().name(), | |
val_any.type() == typeid(the_enum_t)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _THE_ENUM | |
#define _THE_ENUM | |
namespace library { | |
enum the_enum_t { el_one, el_two, el_three }; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment