Chapter 5. Predefined Classes

Table of Contents

1. Primitive Classes
1.1. The ansi Class
1.2. The array Class
1.3. The file and folder Classes
1.4. The time Class
1.5. The db and search Classes
1.6. The error Class
2. Internet-Specific Classes

This chapter illustrates several of the predefined classes that the language makes available to the programmer. Biferno offers a large number of primitive classes describing the main data types used in the language in addition to specific classes representing arrays, files, dates and times. Very specialized classes are also available to support Internet protocols and to interact with databases.

A detailed reference for all methods and properties of Biferno predefined classes can be found in the "Biferno: Reference Guide" document (see Chapter 2, Documentation).

1. Primitive Classes

As common in programming languages, Biferno implements classes supporting the most commonly used data types.

boolean

The boolean class describes the Boolean values (i.e. true or false) resulting from expressions of the Boolean logic.

int

The int class describes positive or negative integer numbers (natural numbers) with values ranging from -2,147,483,647 to 2,147,483,648 (4 byte representation).

Numeric values can also be written in hexadecimal notation as follows:

<?
	a = 0xA8FF
?>
       
unsigned

The unsigned class describes positive integer numbers with values ranging from 0 to 4,294,967,295 (4 byte representation).

long

The long describes positive or negative integer numbers with values ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8 byte representation).

double

The double describes positive or negative real numbers with values ranging from 1.7E-308 to 1.7E+308 (8 byte representation).

All numerical classes support methods implementing the most commonly used mathematic and trigonometric functions.

string

The string class describes arbitrary length text strings. A string is represented as a sequence of characters enclosed in single or double quotes (e.g. "this is a string"). The string that contains no characters is called the null string, and is represented by "" or ''. If a string enclosed in double quotes contains the double quote character ", the latter has to be escaped by using the \ character (backslash), as in the string "<a href=\"page.bfr\">". Escaping double quotes is not necessary if the string is enclosed in single quotes, e.g. '<a href="page.bfr">' is correct. Similarly, if a string enclosed in single quotes contains the single quote character ', the latter has to be escaped by using a backslash. Escaping single quotes is not necessary if the string is enclosed in double quotes. The special characters tab, vertical tab, <CR> (carriage return) and <LF> (line feed) can be represented in a string as "\t", "\v", "\r", "\n". The "\" character itself must be escaped as "\\".

Finally, it is possible to write a string on multiple lines by using a backslash as the last character of the line before the line break (the line break inserted by our text editor will not appear in the resulting string). The same string can be written as

'string \ 
one'
	

or: 'string one'

char

The char class describes single characters. The read-only property ascii of the char class contains the decimal ASCII code of the character assigned to the object.

1.1. The ansi Class

This class contains many generally useful methods for string manipulation derived from the ANSI standard libraries, as well as a couple of methods for the generation of random numbers. The ansi class is a "static" class, which means that only method invocation is allowed. It is not to possible to create variables of the ansi class.

1.2. The array Class

The array class describes one-dimensional ordered lists of elements all belonging to the same class. We will see this class in further detail in Chapter 6, Arrays.

1.3. The file and folder Classes

The file and folder classes allow creating, reading, and modifying files and directories. We will see these classes in further detail in Chapter 13, File Management.

1.4. The time Class

The time class allows manipulating dates and times. We will see this class in further detail in Chapter 14, Date and Time Functionality.

1.5. The db and search Classes

The methods of these classes allow interaction with a database (often indicated with the DBMS acronym: DataBase Management System) via the SQL query language (SQL stands for Structured Query Language). The interface with the most common DBMS (Oracle, MySQL, PostgreSQL, etc.) is implemented via special-purpose native drivers or via ODBC. A number of native drivers are available and more are under development.

We will discuss these two classes in further detail in Chapter 15, Database Interaction.

1.6. The error Class

When Biferno executes a script, a global variable named err belonging to the error class is initialized. If a runtime error occurs, the err variable contains precise information on the nature of the error itself. We will describe the error class and error handling in Biferno in Chapter 16, Error Handling and Debugging.

2. Internet-Specific Classes

Biferno implements a number of classes providing support for Internet protocols (HTTP, SMTP), for data transfer between Web pages and for client-server interaction. Here we will only touch upon the characteristics of these classes. In the following we will demonstrate their use within an application.

multipart

The multipart class describes data captured in a HTML form in the "multipart/form-data" encoding when a file is uploaded from a Web page. Chapter 18, Passing Parameters between Pages illustrates how to use properties and methods of this class.

smtp

The smtp class allows managing and sending email messages using a Biferno script. We will discuss in Chapter 19, E-mail Handling the use of methods of this class.

header

The header class describes the header of the HTTP protocol. The methods of this class support reading and manipulating fields in the HTTP header. Properties and methods of this class are analyzed in detail in Chapter 20, HTTP Protocol Interaction.

httpPage

The httpPage class describes a Web page in the form used by the HTTP protocol during client-server communication. A HTTP page can be seen as a structured data packet composed by a header and a body. When a server sends such a packet in answer to a client request, the body of the packet contains the HTML code describing the content of the Web page, which will be visualized by the browser. In the query packet sent by the client to the server, the body can contain parameters transmitted via the HTTP protocol POST method. Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.

request

The request class describes a page request to the server. Its properties allow to obtain information such as the name of the requested file, its absolute path, which method was used for the request (POST or GET), the list of parameters (arguments) used in the invocation, etc. Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.

client

The client class allows to obtain information about the client, i.e. on the user that sent to the server a page request with extension ".bfr". Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.

serverInfo

The serverInfo class allows obtaining information on the Web server, such as the application name (e.g. Apache, IIS), the software version, the host domain name, the path of the server's root directory etc.

A detailed reference for all properties of this class can be found in the "Biferno: Reference Guide" document (see Chapter 2, Documentation.

cacheItem

The cacheItem class describes a Biferno cache element. We will discuss this class in more detail in Chapter 22, Cache Management.