Difference between revisions of "Documentation:BDL"

From The BABEL Development Site
(Data type alias (typedef))
(Constants (const))
Line 189: Line 189:
== Constants (const) ==
== Constants (const) ==
The way of defining constants in BDL is:
const <type> <const name> = <value>;
For example:
const float PI=3.14159265;
const char NUL='\0';
const string LAST_WORDS="My god, it's full of stars!";

Revision as of 17:46, 21 May 2009

BABEL Definition Language (BDL)

v. 120606

A data definition language for the BABEL development system.

System Engineering and Automation Department.

University of Málaga, Spain.


What is BDL?

BDL (Babel Definition Language) is the medium for specifying, in a programming-language independent fashion, some data types that a BABEL module needs. BDL has been implemented as a restricted subset of one of the most extended definition languages: the OMG CORBA IDL (www.omg.org).

Where the BDL types are used?

It is used currently for defining input/output parameters of services and for providing public definitions (data types that the module provides to other modules and to itself). You can use BDL types both in the "Public Definitions" of the module and in the specification of the input/output parameters of the services. You can compose your own types (using "typedef") based on BDL basic or composed types.

What the BDL types are used for?

You can use a variable of a BDL type in the following situations: A) Creating a local variable for the internal use of some logic of the module (auxiliary logic, service logic, start-up logic, etc.). B) Creating a global variable for the internal status of the module (accessible from any logic of the module). C) Using an already defined input/output parameter of a service.

How variables of the BDL types are used?

You should remember that BDL is not a programming language (only a specification for data), and thus, you cannot use directly any BDL type in your codification logics. Rather, BABEL translates automatically for you the BDL types into types understandable by the codification language you have chosen for your module (see for example the Using BDL in the C++ codification language section).

BABEL Definition Language (BDL)

Basic types

Numeric (octet, short, long, ...)

BDL includes the following basic numeric types:

  • octet : 8-bit, unsigned (0...2^8-1)
  • short : 16-bit, signed (-2^15...2^15-1)
  • unsigned short : 16-bit, unsigned (0...2^16-1)
  • long : 32-bit, signed (-2^31...2^31-1)
  • unsigned long : 32-bit, unsigned (0...2^32-1)
  • long long (*) : 64-bit, signed (-2^63...2^63-1)
  • unsigned long long (*) : 64-bit, unsigned (0...-2^64-1)
  • float : IEEE single-precision floating point numbers.
  • double : IEEE double-precision floating point numbers.

(*): The 64-bit integer types (long long and unsigned long long) could not be available in some implementations, being mapped in an undefined way, so its use should be avoided.

Alphanumeric (char)

BDL has only one basic alphanumeric type:

  • char : One unsigned 8-bits character.

There is also one composed alphanumeric type: string.

Others (boolean)

BDL includes one basic type for logical operations:

  • boolean : Stores a boolean value (TRUE or FALSE)

Composed types

Not-Repeated (struct)

BDL includes the following composed type that does not contain more than one occurrence of an object:

  • Structs: They are analogous to C structs, and can contain both basic and composed types fields. For example:

<cpp> struct MyStructName { short FieldOne; double FieldTwo; OtherStructName osn; } MyVarStruct; </cpp>

The union data type is not supported currently in BDL.

Repeated (sequence, array)

BDL includes the following composed types that can hold more than one occurrence of an object:

  • Sequences: An ordered list of elements of the same type (maybe composed). A maximum limit of elements can be specified, or not. For example:

<cpp> struct LimitedAccounts { string bankSortCode<10>; sequence<Account> accounts; // No maximum length of sequence. sequence<Account,50> accountsBis; // 50 is the maximum length of sequence. }; </cpp>

  • Arrays: Fixed-length indexed sets of elements of the same type (maybe composed). For example:

<cpp> struct SomeAccounts { string bankSortCode<10>; // string of length 10 Account accounts[10][2]; // array of dimensions 10x2 }; </cpp>

Others (enum, string)

BDL includes these other composed types:

  • Enumerated: The enumeration of several constants. No numeric equivalence should be assumed. For example:

<cpp> enum Currency {pound, dollar, yen, franc}; </cpp>

  • Strings: Sequences of characters of 8 bits each. They can be given a fixed maximum length. For example:

<cpp> struct MyStructName { string<10> MyString; // A string that can store no more than 10 characters string MyString2; // A string without maximum length } MyStructVar; </cpp>

Data type alias (typedef)

The typedef keyword has been introduced to define array data types, but it also can be used to define alias for already defined data types.

The syntax is:

<cpp> typedef < an already defined data type > < an alias for that type >; </cpp>

For example:

<cpp> struct MyStruct { long A; string B; };

typedef struct MyStruct MyAliasForMyStruct; typedef unsigned long MyAliasForUnsignedLong;

typedef sequence<short, 50> ShortListType; typedef sequence<long> LongListType;

typedef short ShortArrayType[50][10];

typedef enum MyCurrency {pound, dollar, yen, franc} OtherCurrency;

typedef string<10> MyStringType; typedef string MyString; </cpp>

Constants (const)

The way of defining constants in BDL is: <cpp> const <type> <const name> = <value>; </cpp>

For example:

<cpp> const float PI=3.14159265; const char NUL='\0'; const string LAST_WORDS="My god, it's full of stars!"; </cpp>