Refactored C++ code generation into four parts to make subclassing
easier