Accessing generic attributes
Using generic attributes has a number of advantages, since the attribute appears according to the current settings in the application. Mainly, generic attributes are used for multilingual text. Setting a current type (language) for a generic attribute causes the attribute to locate the proper attribute value when reading an instance.
In principle, generic attributes are references and can be accessed as such as well. Since this may conflict with the current setting of the attribute within the instance, copy property handles should be created in order to refer to generic attributes as references.
The example below shows a simple way of accessing two languages for a book title by defining a simple access schema (property hierarchy). The both title properties for German and English are located automatically when a book has been selected in books, since the property path in the property definition contains a selector. Properties defined by means of selector paths will always create copy handles.
In the second example, a copy handle is created for title in order to access each language separately. When creating a property handle reference instead, which refers to the original property in the instance, changing the selected instance in the title property might conflict with the settings of the attribute type in the generic attribute (version 3 in the example below).
// printing books titles version 1:
Property books(database,"Books",Write);
// create copy handle for title because of selection in path expression
Value englich_title(books,"title('English')");
Value german_title(books,"title('German')");
books.get(0);
printf("English: %s;\nGerman: %s\n\n",englich_title.toString(),
german_title.toString());
// printing books titles version 2:
Property books(database,"Books",Write);
Dictionary &dict = database.dictionary();
// create copy handle for title because parent is passed by reference
Value title(books,"title");
books.get(0);
title.get("English"); // locate English title version
printf("English: %s;\n",title.toString());
title.get("German"); // locate German title version
printf("German: %s\n\n",title.toString());
// printing books titles version 3:
Property books(database,"Books",Write);
// create property handle for title, which refers to origin
// (pointer to books property9
Property title(&books,"title");
books.property("title").genericAttributeType("German"); // select German language
books.get(0);
// the next will cause a conflict with the generic attribute settings
title.get("English");
...