Initial import.

I don't really care how the C++ is done, but this maximizes code re-use while minimizing R interface changes.