T++ White Paper
Today, the demand for web applications is fastly growing up. The C++ language has been used to develop several types of applications, since those focused in comercial actitity, to those used in industrial and cientific activity.
T++ is a tool that provides the ability to develop web applications using C++, either to adapt existing desktop application to web environment, or to develop entirely new web applications.
Web application development
A web application is a dynamic extension of a web server . Web application development comprises the design and implementation of websites that deal with dynamic data. These websites are similar do conventional ones, but their content is dynamically, based on databases, or user-informed data, or in something else.
Web applications have their business logic residing in web servers, and users interact with web applications through a web browser:
Providing an web server extension means developing an execution engine that can generate dynamic response for users requests.
The user enters one application document ("screen"), that may be dinamically generated, usually formatted as a HTML document.
Based on other document(s) accessed by the user via HTTP, like other website, and in the data that the user may have informed, the application executes corresponding actions and generate an output document to the user.
The T++ approach for web application development
T++ implements the web server extension by using T++ documents in place of conventional ones. A T++ document is similar to a HTML document, except by the fact that the former can contain C++ expressions, statements and other constructions, which will be evaluated to generate the dynamic part of the response.
The figure below shows how an user interacts with a generic T++ application:
1 The user, using a web browser, makes a HTTP request to the web server hosting the T++ application
1 The web server, then, forwards the request to the T++ engine.
1 The T++ engine maps the request into an object.
1 If this object does not exist, or it is older than the corresponding document, it's rebuilt and loaded in memory.
1 The T++ engine then forwards the request processing to the corrsponding object. That object proccess its behavior and generates an output to the user.
1 The T++ engine takes the generated output and pass it to the web server.
1 The web server send the generated content back to the user.
T++ implements the web server extension by generating objects -- components -- from the documents, which will handle the requests for that documents. More detail about T++ implementation can be found in .
Developing T++ applications
T++ applications are build by creating one or more T++ documents. A T++ document looks like this:
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
6 #include <fstream>
7 #include <hash_map>
8 #include <algorithm>
11 ifstream in("/home/terceiro/public_html/tpp/data");
12 int x, y, minX, maxX, maxY, nData;
minX maxX = 0;
15 hash_map<int,int> histogram;
16 while (in >> x >> y, nData++, in)
19 histogram[x] = y;
21 if (nData <= 1)
24 maxY = y;
28 minX = min(minX, x);
29 maxX = max(maxX, x);
30 maxY = max(maxY, y);
36 <meta http-equiv="pragma" content="no-cache" />
37 <link rel="stylesheet" type="text/css" href="histogram.css" />
40 <div class="chart">
41 <h3>Histogram example application</h3>
42 <table class="histogram" align='center'>
45 for (int i = minX; i <= maxX; i++)
47 if (histogram[i] > 0)
50 <div class="frequency"
51 style="height: <%= (histogram[i] * 100)/maxY %>%;">
52 <%= histogram[i] %>
58 %><td><div class="nullFerquecy">0</div></td><%
63 <tr class="xAxis">
65 for (int i = minX; i <= maxX; i++)
67 %><td><%= i %></div></td><%
74 <div class="panel">
75 <a href="edit.tpp">Edit</a> the data.
How does T++ work?
When a user first accesses a T++ document, this document is translated into a C++ class source file; then, this class is compiled into a shared library; this shared library is then dynamicaly loaded by T++, and an instance of that class is extracted by calling a special function in the shared library; then, T++ forwards the requests for the original document to this instance, calling this service() method. This method -- generated from the content of the T++ document -- is responsible for generating the content that will be sent back to the user.
In subsequent requests, if the document is newer than the underlying class, the class is rebuilt the same way it was built for the first time, recompiled, and reloaded. This is required in order to the objects in memory reflect the T++ document's content.
Basic T++ document elements
T++ documents are built up with blocks. Each block can fit the following block types:
Declarations block. As shown in lines from 5 to 9, a declarations block is delimited by
%>. This type of block contains everything that need to be declared, like C++ #include and #define directives.
Code execution block. In the lines from 9 to 33 in the example above, we can see a code execution block. This type of block contains arbitrary C++ code, that is executed when the document is requested. Code execution blocks are delimited by
Member declaration block. This type of block declares members -- atributes, methods, and others -- for the generated class. Those members can be used in the document. Member declaration blocks are delimited by
Output generation block. This block type contains a C++ expression, which will be evaluated and written to the output when processing a request. An example of output generation block is shown in the above example at lines 52 ant 67.
Comment block. This block type contains programming language comments, and it is silently ignored.
Static content block. A static content block is everything else that is not one of the above. It contains content -- often HTML code -- that will be copied verbatim to the output.
Some improvements to T++ are planned:
Use of external libraries. This will be provide the use of anything ever developed for C++ in T++ applications.
Use of distributed components. This will provide the ability to easily use distributed components to build multi-tier web applications with T++.
Templating system. This will provide a way of writing "clean" T++ documents, instead of over-mixing up HTML(or whatever output format you use) and C++
 JavaServer pages technology - White Paper
 The Java WebServices Tutorial
 Antonio Soares de Azevedo Terceiro and Christina von Flach G. Chavez. _T++: a Tool for Web Application Development_. Accepted demonstration at OOPSLA'03.
Main.AntonioTerceiro - 29 Jul 2003