Chapter 4. Using the C++ Binding

Table of Contents

Generating the specific C++ binding
A minimal client program
Compiling and running the application

We are now going to introduce the C++ binding through the same schema and examples as previously.

There are two ways to use the C++ binding:

We will only explain only the second way, as it is far more simple and pratical than the first one. For more information on the generic C++ binding, please refer to the C++ binding manual.

Writing a C++ program that can create, retrieve, modify and delete person instances that are stored in an EyeDB database involves the following steps:

This example is located in the examples/GettingStarted subdirectory.

Generating the specific C++ binding

To generate the specific C++ binding, run the eyedbodl tool as follow:

	    % eyedbodl --gencode=C++ --package=person schema.odl
	  

The --package option is mandatory: you may give any name you want, this name will be used as the prefix for generated files names. Without the --package option, the prefix used will be the name of the ODL file without its extension.

eyedbodl generates a few files, all prefixed by person, the most important being person.h and person.cc.

If you have a look to the file person.h, you will notice that the following classes have been generated:

  • the class person

  • the class personDatabase

  • the class Root

  • the class Address

  • the class Person

  • the class Employee

The first class, person, is the package class:

  
class person {
 public:
  static void init();
  static void release();
  static eyedb::Status updateSchema(eyedb::Database *db);
  static eyedb::Status updateSchema(eyedb::Schema *m);
};

	  

It is used to perform package initialization and schema update. Before any use of the person package, you need to call person::init.

The second class, personDatabase is used to open, close and manipulate objects within a database containing the person schema.

The open method has two purposes: the first one is to open the database, as the standard eyedb::Database will do; the second one is to check that the database schema is consistant with the generated runtime schema. Although it is possible to use the standard Database class to open a database containing the person schema, it is strongly recommended to use the personDatabase class.

The third class, Root, is the root class for all the generated classes. This class is useful to perform safe down-casting during object loading.

The three last classes, Address, Person and Employee are generated from the person.odl class specifications: for each attribute in the person.odl, a set of get and set methods is generated.

For instance, for the firstname attribute, the following methods are generated:

eyedb::Status setFirstname(const std::string &);
std::string getFirstname(eyedb::Bool *isnull = 0, eyedb::Status * = 0) const;
eyedb::Status setFirstname(unsigned int a0, char);
char getFirstname(unsigned int a0, eyedb::Bool *isnull = 0, eyedb::Status * = 0)  const;

	  

The two first methods manipulate the firstname attribute as a string while the two last ones manipulate each character within this string.

There are two set methods and two get methods.