Chapter 3. The C++ Interface

Table of Contents

A quick sample

A quick sample

dumptpt.cxx

#include <libtpt/tpt.h>
#include <iostream>
#include <stdexcept>

// Dump the parsed template output straight to std::cout
void dumptemplate(const char* filename)
{
	try {
		// Instantiate a parser
		TPT::Parser p(filename);

		// Add an include path (only ./ searched by default)
		p.addincludepath("./include");

		// Parse the template directly to standard output
		if (p.run(std::cout))
		{
			// handle reporting of template errors
		}
	} catch(const std::exception& e) {
		std::cout << "EXCETPION: " << e.what() << std::endl;
	}
}