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 [2]. 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 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:

T++ architecture

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 [3].

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"
 3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 5  <%#
 6  #include <fstream>
 7  #include <hash_map>
 8  #include <algorithm>
 9  %><%
11  ifstream in("/home/terceiro/public_html/tpp/data");
12  int x, y, minX, maxX, maxY, nData;
13  nData  minX  maxX = 0;
15  hash_map<int,int> histogram;
16  while (in >> x >> y, nData++,  in)
17	 {
19		histogram[x] = y;
21		if (nData <= 1)
22		  {
23			 minX  maxX  x;
24			 maxY = y;
25		  }
26		else
27		  {
28			 minX = min(minX, x);
29			 maxX = max(maxX, x);
30			 maxY = max(maxY, y);
31		  }
32	 }
33  %>
34  <html>
35	 <head>
36  	 <meta http-equiv="pragma" content="no-cache" />
37  	 <link rel="stylesheet" type="text/css" href="histogram.css" />
38    </head>
39	 <body>
40		<div class="chart">
41		  <h3>Histogram example application</h3>
42		  <table class="histogram" align='center'>
43			 <tr>
44				<%
45				for (int i = minX; i <= maxX; i++)
46				  {
47					 if (histogram[i] > 0)
48						{
49						  %><td>
50								<div class="frequency"
51  									style="height: <%= (histogram[i] * 100)/maxY  %>%;">
52									  <%= histogram[i] %>
53								</div>
54							 </td><%
55						}
56					 else
57						{
58						  %><td><div class="nullFerquecy">0</div></td><%
59						}
60				  }
61				%>
62			 </tr>
63			 <tr class="xAxis">
64				<%
65				for (int i = minX; i <= maxX; i++)
66				  {
67					 %><td><%= i %></div></td><%
68				  }
69				%>
70			 </tr>
71		  </table>
72		</div>
74		<div class="panel">
75		  <a href="edit.tpp">Edit</a> the data.
76		</div>
77	 </body>
78  </html>

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:

Looking ahead

Some improvements to T++ are planned:


[1] JavaServer pages technology - White Paper

[2] The Java WebServices Tutorial

[3] 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