1 Component Definition Language (CDL) {#dev_guides__cdl}
2 ==============================
6 @section occt_cdl_0 DEPRECATION WARNING
8 Please note that CDL is considered as obsolete and is to be removed in one of future releases of OCCT.
10 @section occt_cdl_1 CDL and Application Architecture
12 CDL is the component definition language of the Open CASCADE Technology (**OCCT**) programming platform. Some components, which CDL allows you to create, are specific to OCCT application architecture. These and other components, which you can define using CDL include the following:
14 * Class (including enumeration, exception)
20 A **class** is the fundamental software component in object-oriented development. Because of a very large number of resources used in large-scale applications, the **class** itself is too small to be used as a basic management unit.
22 So, while the class is the basic data component defined in CDL, this language also provides a way to group classes, **enumerations**, and **exceptions** together – the **package**. A package groups together a number of classes, which have semantic links. For example, a geometry package would contain Point, Line, and Circle classes. A package can also contain enumerations, exceptions, and package methods. In practice, a class name is prefixed with the name of its package e.g. *Geom_Circle*.
24 Using the services described in the **packages**, you can construct an **executable**. You can also group together services provided by **packages**.
26 To save data in a file, you need to define persistent classes. Then, you group these classes in a schema, which provides the necessary read/write tools.
29 @image html /dev_guides/cdl/images/cdl_image003.png "Building an Open CASCADE Technology application"
30 @image latex /dev_guides/cdl/images/cdl_image003.png "Building an Open CASCADE Technology application"
32 @section occt_cdl_2 Introduction to CDL
33 @subsection occt_cdl_2_1 Purposes of the Language
35 You can use CDL to **define** **data** in the Open CASCADE Technology environment. CDL allows you to define various kinds of data types supporting the application architecture and development methodology, which you envision. CDL is neither an analysis formalism (e.g. Booch methodology) nor a data manipulation language (e.g. C++).
37 You use CDL in the **design** **phase** of a development process to define a set of software components which best model the concepts stated in the application specification.
39 @image html /dev_guides/cdl/images/cdl_image004.png "The Development Process"
40 @image latex /dev_guides/cdl/images/cdl_image004.png "The Development Process"
43 From a structural point of view, CDL is an object-oriented language. It is centered on the notion of the **class** - a data type, which represents an elementary concept. CDL offers various means of organizing classes, mostly under the fundamental form of **packages**. A package contains a set of classes, which share some semantic relationship. This greatly simplifies your task of managing individual classes when confronted with a very large number of them.
45 Once you have defined the classes and packages using CDL, you can implement their **methods** - i.e., their functionality - in one of the data manipulation languages supported by the OCCT environment (currently C++).
47 Even though you can describe classes directly in C++ and save them as header files (.hxx), to do so would forfeit all the advantages of using CDL. These are:
49 * Precise, complete, and easy-to-read description of the software components.
50 * Creation of a link with the database; object persistence forms part of the predefined environment of the language.
51 * Multi-language access to the services of an application engine – a specific architectural form created using the CDL tools, which serves as the motor of an application.
53 @subsection occt_cdl_2_2 Overview of CDL
55 CDL is an object-oriented language. In other words, it structures a system around data types rather than around the actions carried out on them. In this context, an **object** is an **instance** of a data type, and its definition determines how you can use it. Each data type is implemented by one or more classes, which make up the basic elements of the system.
57 @subsubsection occt_cdl_2_2_1 Classes
59 A class is an implementation of a **data type**. It defines its **behavior** and its **representation**.
61 The behavior of a class is its programming interface - the services offered by its **methods**. The representation of a class is its data structure - the **fields**, which store its data.
63 Every object is an **instance** of its class. For example, the object *p* of the data type *Point* is an instance of the class *Point*.
65 The class Point could be defined as in the example below:
68 class Point from GeomPack
69 ---Purpose: represents a point in 3D space.
77 The definition of this class comprises two sections:
79 * one starting with the keywords **is**
80 * one starting with the keyword **fields**.
82 The first section contains a list of methods available to the clients of the class. The second section defines the way in which instances are represented. Once this class has been compiled you could **instantiate** its data type in a C++ test program as in the example below:
91 @subsubsection occt_cdl_2_2_2 Categories of Types
93 You declare the variables of a **data manipulation language** as being of certain data types. These fall into two categories:
95 * Data types manipulated by handle (or reference)
96 * Data types manipulated by value
98 @image html /dev_guides/cdl/images/cdl_image005.png "Manipulation of data types"
99 @image latex /dev_guides/cdl/images/cdl_image005.png "Manipulation of data types"
101 As seen above, you implement data types using classes. However, classes not only define their data representation and methods available for their instances, but they also define how the instances will be manipulated:
102 * A data type manipulated by value contains the instance itself.
103 * A data type manipulated by handle contains a reference to the instance.
105 The most obvious examples of data types manipulated by value are the predefined **primitive types**: Boolean, Character, Integer, Real...
107 A variable of a data type manipulated by handle, which is not attached to an object, is said to be **null**. To reference an object, you need to instantiate the class with one of its constructors. This is done in C++ as in the following syntax:
110 Handle(myClass) m = new myClass;
114 @subsubsection occt_cdl_2_2_3 Persistence
116 An object is called **persistent** if it can be permanently stored. In other words, you can use the object again at a later date, both in the application, which created it, and in another application.
118 In order to make an object persistent, you need to declare it in CDL as inheriting from the **Persistent** class, or to have one of its parent classes inheriting from the *Persistent* class.
120 Note that the classes inheriting from the *Persistent* class are handled by reference.
124 class Watch inherits Persistent
127 In this example, building the application, you add the *Watch* class to the corresponding schema of data types.
128 If, running the application, you instantiate an object of the *Watch* class, you have the possibility of storing it in a file.
129 You cannot store objects instantiated from classes, which inherit from the *Storable* class. However, you can store them as fields of an object, which inherits from *Persistent*.
131 Note that the objects inheriting from Storable are handled by value.
136 class WatchSpring inherits Storable
137 //then this could be stored as a field of a Watch
139 class Watch inherits Persistent
142 name : ConstructorName;
143 powersource : WatchSpring;
147 @subsubsection occt_cdl_2_2_4 Packages
149 In large-scale long-term development the task of marshalling potentially thousands of classes is likely to quickly prove unmanageable. CDL introduces the notion of **package** of classes containing a set of classes, which have some semantic or syntactic relationship. For example, all classes representing a particular set of electronic components might make up a package called Diode.
151 As the package name prefixes the class name when implementing such class (in C++ for example), classes belonging to different packages can have the same name. For example, two packages, one dealing with finance and the other dealing with aircraft maneuvers, might both contain a class called *Bank*, without any possibility of confusion.
160 @subsubsection occt_cdl_2_2_5 Inheritance
162 The purpose of inheritance is to reduce development workload. The inheritance mechanisms allow you to declare a new class as already containing the characteristics of an existing class. This new class can then be rapidly specialized for a task at hand. This eliminates the necessity of developing each component “from scratch”.
164 For example, having already developed a class *BankAccount*, you can quickly specialize new classes - *SavingsAccount, LongTermDepositAccount, MoneyMarketAccount, RevolvingCreditAccount*, etc..
166 As a consequence, when two or more classes inherit from a parent (or ancestor) class, all these classes surely inherit the behavior of their parent (or ancestor). For example, if the parent class *BankAccount* contains the method *Print* that tells it to print itself out, then all its descendent classes offer the same service.
168 One way of ensuring the use of inheritance is to declare classes at the top of a hierarchy as being **deferred**. In such classes, the inherited methods are not implemented. This forces you to create a new class used to redefine the methods. In this way, you guarantee a certain minimum common behavior among descendent classes.
172 deferred class BankAccount inherits Persistent
176 name : AccountHolderName;
177 balance : CreditBalance;
181 @subsubsection occt_cdl_2_2_6 Genericity
183 You will often wish to model a certain type of behavior as a class. For example, you will need a list modeled as a class.
185 In order to be able to list different objects, the class *List* must be able to accept different data types as parameters. This is where genericity comes in: you first declare a list declared as the generic class *List*, willing to accept any data type (or only a particular set of acceptable data types). Then, when you want to make a list of a certain type of object, you instantiate the class *List* with the appropriate data type.
190 generic class NewList (Item)
197 Items may be of any type, an Integer or a Real for example.
199 When defining the package, add the following line:
202 class NewListOfInteger instantiates
206 @subsubsection occt_cdl_2_2_7 Exceptions
208 The behavior of any object is implemented by methods, which you define in its class declaration. The definition of these methods includes not only their signature (their programming interface) but also their domain of validity.
210 In CDL, this domain is expressed by **exceptions**. Exceptions are raised under various error conditions. This mechanism is a safeguard of software quality.
212 @subsubsection occt_cdl_2_2_8 Completeness
214 You use CDL to define data types. Such definitions are not considered complete unless they contain the required amount of structured commentary.
216 The compiler does not enforce this required degree of completeness, so it is the responsibility of the developer to ensure that all CDL codes are properly annotated.
218 Completeness is regarded as an essential component of long-term viability of a software component.
221 @subsection occt_cdl_2_3 Lexical Conventions
222 @subsubsection occt_cdl_2_3_1 Syntax notation
224 In this manual, CDL declarations are described using a simple variant of the Backus-Naur formalism. Note the following:
226 * Italicized words, which may also be hyphenated, denote syntactical categories, for example *declaration-of-a-non-generic-class* ;
227 * Keywords appear in bold type: **class** ;
228 * Brackets enclose optional elements:
230 identifier [from package-name]
232 * Curly braces enclose repeated elements. The element may appear zero or many times:
234 integer ::= digit{digit}
236 * Vertical bars separate alternatives:
238 passing-method ::= <b>[in] | out | in out </b>
240 * Two apostrophes enclose a character or a string of characters, which must appear:
242 exponent ::= ’E’[’+’]integer | ’E-’ integer
244 **NOTE** To introduce the ideas progressively, the examples presented in this manual may be incomplete, and thus not compilable by the CDL compiler.
247 @subsubsection occt_cdl_2_3_2 Lexical elements
249 A CDL source is composed of text from one or more compiled units. The text of each compiled unit is a string of separate lexical elements: **identifiers**, **keywords**, **constants**, and **separators**. The separators (blank spaces, end of line, format characters) are ignored by the CDL compiler, but these are often necessary for separating identifiers, keywords, and constants.
252 @subsubsection occt_cdl_2_3_3 Comments
254 With CDL, you cannot use the expression of all useful information about a development unit. In particular, certain information is more easily expressed in natural language. You can add such information to the CDL description of a data type.
256 Rubrics and free comments are to be differentiated:
258 **Free comments** are preceded by the characters “--” (two hyphens), and they terminate at the end of the line in which they appear.
264 Unlike rubrics, free comments can appear before or after any lexical element. The first written character of the comment itself *must not* be a hyphen. If a hyphen is necessary make sure it is preceded by a blank.
269 **Rubrics** are various types of comments attached to CDL components. A rubric is a comment made up of three hyphens, name of the rubric (without any intermediary space) and then a colon and a space. It is terminated by the beginning of the following rubric, or by the end of the commentary.
273 ---Purpose:This is an example of a
274 --rubric composed of a
275 --comment which extends to
279 The different categories of rubrics and the form of their content do not depend on the Component Description Language, but on the tool for which it is intended.
281 The use of commentary is generally governed by the internal programming standards of an enterprise. You are encouraged to use various well-defined rubrics, such as Purpose, Warning, Example, References, Keywords, etc.
283 These rubrics can be attached to:
292 @subsubsection occt_cdl_2_3_4 Identifiers
294 An identifier is an arbitrary chain of characters, either letters or digits, but it must begin with a letter.
296 The underscore “_” is considered to be a letter as long as it doesn’t appear at the beginning or the end of an identifier.
298 Capital and small letters are not equivalent (i.e. AB, Ab, aB, ab are four different identifiers).
301 @subsubsection occt_cdl_2_3_5 Keywords
303 The following is a list of keywords.
346 In a CDL file, the following characters are used as punctuation:
349 @subsubsection occt_cdl_2_3_6 Constants
351 There are three categories of constants:
357 #### Numeric Constants
359 There are two types of numeric constants: integer and real.
361 An **integer** constant consists of a string of digits, which may or may not be preceded by a sign. Integer constants express whole numbers.
367 A **real** constant may or may not be preceded by a sign, and consists of an integral part followed by a decimal point and a fractional part (either one or both parts may be null, but both parts must always be present). It may also be followed by the letter E to indicate that the following figures represent the exponent (also optionally signed).
371 5.0 0.0 -0.8E+3 5.67E-12
373 #### Literal Constants
375 Literal constants include individual characters and strings of characters.
377 An **individual character** constant is a single printable character enclosed by two apostrophes. (See the definition of the class Character in the Standard Package).
381 ‘B’ ‘y’ ‘&’ ‘*’ ‘’’ ‘‘
383 A **string** constant is composed of printable characters enclosed by quotation marks.
387 ’’G’’ ’’jjjj’’ ’’This is a character string, isn’t it?’’
389 The **quotation mark** can itself appear within a character string as long as it is preceded by a backslash.
393 ’’This film was originally called \’’Gone with the Tide\’’.’’
398 Named constants are sub-divided into two categories: Booleans and enumerations.
400 **Booleans** can be of two types: True or False.
402 An **enumeration** constant is an identifier, which appears in the description of an enumeration.
404 @section occt_cdl_3 Software Components
406 @subsection occt_cdl_3_1 Predefined Resources
407 @subsubsection occt_cdl_3_1_1 Primitive types
409 Primitive types are predefined in the language and they are **manipulated by value**.
411 Four of these primitives are known to the schema of the database because they inherit from the class **Storable**. In other words, they can be used in the implementation of persistent objects, either when contained in entities declared within the methods of the object, or when they form part of the internal representation of the object.
413 The primitives inheriting from **Storable** are the following:
415 * **Boolean** Is used to represent logical data. It has only two values: *True* and *False*.
416 * **Byte** 8-bit number.
417 * **Character** Designates any ASCII character.
418 * **ExtCharacter** Is an extended character.
419 * **Integer** Is an integer number.
420 * **Real** Denotes a real number (i.e. one with a whole and a fractional part, either of which may be null).
421 * **ShortReal** Real with a smaller choice of values and memory size.
423 There are also non-storable primitives. They are:
425 * **CString** Is used for literal constants.
426 * **ExtString** Is an extended string.
427 * **Address** Represents a byte address of undetermined size.
429 The services offered by each of these types are described in the Standard Package.
432 @subsubsection occt_cdl_3_1_2 Manipulating types by reference (by handle)
434 Two types are manipulated by handle:
436 * Types defined using classes inheriting from the **Persistent** class are storable in a file.
437 * Types defined using classes inheriting from the **Transient** class.
439 These types are not storable as such in a file.
441 @image html /dev_guides/cdl/images/cdl_image006.png "Manipulation of a data type by reference"
442 @image latex /dev_guides/cdl/images/cdl_image006.png "Manipulation of a data type by reference"
445 @subsubsection occt_cdl_3_1_3 Manipulating types by value
447 Types, which are manipulated by value, behave in a more direct fashion than those manipulated by handle. As a consequence, they can be expected to perform operations faster, but they cannot be stored independently in a file.
449 You can store types known to the schema (i.e. either primitives or inheriting from Storable) and manipulated by value inside a persistent object as part of the representation. This is the only way for you to store objects “manipulated by value” in a file.
451 @image html /dev_guides/cdl/images/cdl_image007.png "Manipulation of a data type by value"
452 @image latex /dev_guides/cdl/images/cdl_image007.png "Manipulation of a data type by value"
454 Three types are manipulated by value:
458 * Types defined by classes not inheriting from Persistent or Transient, whether directly or not
460 @subsubsection occt_cdl_3_1_4 Summary of properties
463 Here is a summary of how various data types are handled and their storability:
465 | | Manipulated by handle | Manipulated by value |
466 | :---- | :---- | :---- |
467 | storable | Persistent | Primitive, Storable (storable if nested in a persistent class) |
468 | temporary | Transient | Other |
473 @subsection occt_cdl_3_2 Classes
475 @subsubsection occt_cdl_3_2_1 Class declaration
477 The class is the main system for creating data types under CDL. By analyzing any CDL-based software, you find that classes are the modular units that make up packages. When you describe a new class, you introduce a new data type.
479 Whatever the category of the described type (manipulated by value, Storable or not, manipulated by handle, Persistent or not) the structure of the class definition remains the same. The syntax below illustrates it:
482 -- declaration-of-a-simple-class ::=
483 class class-name from package-name
484 [uses data-type { ’,’ data-type } ]
485 [raises exception-name { ’,’ exception-name} ]
487 end [ class-name ] ’;’
488 data-type ::= enumeration-name | class-name |
489 exception-name | primitive-type
490 package-name ::= identifier
491 class-name ::= identifier
494 [declaration-of-fields]
495 [declaration-of-friends]
497 Class name becomes a new data type, which you can use inside its own definition. Other types appearing in the definition must either be primitive types, previously declared classes, exceptions, or enumerations.
499 Apart from the types defined in the Standard Package, which are **implicitly visible** everywhere, you need to declare the data types after the keyword **uses**. This concerns both the class behavior and its internal representation.
501 **Exceptions** are declared after the word **raises**.
505 class Line from GeomPack
506 usesPoint, Direction, Transformation
507 raisesNullDirection, IdenticalPoints
508 is-- class definition follows here
509 -- using Point, Direction and
510 -- Transformation objects,and the
511 -- NullDirection and Identical-
512 -- -Points exceptions.
516 The elements, which make up the definition of a class, are divided into four parts:
519 * the internal representation
520 * the friend methods and friend classes.
522 @image html /dev_guides/cdl/images/cdl_image009.png "Contents of a class"
523 @image latex /dev_guides/cdl/images/cdl_image009.png "Contents of a class"
525 @subsubsection occt_cdl_3_2_2 Categories of classes
527 Classes fall into three categories:
532 #### Deferred classes
534 The principal characteristic of a **deferred class** is that you cannot instantiate it. Its purpose is to provide a given behavior shared by a hierarchy of classes and dependent on the implementation of the descendents. This allows guaranteeing a certain base of inherited behavior common to all classes based on a particular deferred class. Deferred classes are declared as in the following syntax:
537 -- declaration-of-a-deferred-class ::= deferred class class-name
538 [inherits class-name {’,’ class-name}]
539 [uses data-type {’,’ data-type}]
540 [raises exception-name {’,’ exception-name}]
544 Please, note that a deferred class does not have to contain a constructor
546 <h4>Generic classes</h4>
548 The principal characteristic of a **generic class** is that it offers a set of functional behavior to manipulate other data types. To instantiate a generic class you need to pass a data type in argument. Generic classes are declared as in the following syntax:
551 -- declaration-of-a-generic-class ::= [deferred] generic class class-name ’(’generic-type {’,’generic-type}’)’
552 [inheritsclass-name {’,’ class-name}]
553 [usesdata-type {’,’ data-type}]
554 [raisesexception-name {’,’ exception-name}]
555 [{[visibility] declaration-of-a-class}]
558 generic-type ::= identifier as type-constraint
559 identifier ::= letter{[underscore]alphanumeric}
560 type-constraint ::= any | class-name [’(’data-type {’,’ data-type}’)’]
564 @subsection occt_cdl_3_3 Packages
566 @subsubsection occt_cdl_3_3_1 Package declaration
568 **Packages** are used to group classes, which have some logical coherence. For example, the Standard Package groups together all the predefined resources of the language. In its simplest form, a package contains the declaration of all data types, which it introduces. You may also use a package to offer public methods and hide its internal classes by declaring them private.
573 -- package-declaration ::= package package-name
574 [uses package-name {’,’ package-name}]
575 is package-definition
576 end [package-name]’;’
577 -- package-name ::= identifier
578 -- package-definition ::=
581 -- type-declaration ::=
582 [private] declaration-of-an-enumeration | [private] declaration-of-a-class | declaration-of-an-exception
583 -- package-method ::= identifier [simple-formal-part][returned-type -declaration]
588 The data types described in a package *may* include one or more of the following data types:
592 * Pointers to other object classes.
594 Inside a package, two data types *cannot* have the same name.
596 You declare data types before using them in the definition of other data types.
598 When two classes are **mutually recursive**, one of the two must be first declared in an incomplete fashion.
600 Grouped behind the keyword **uses** are the names of all the packages containing definitions of classes of which the newly introduced data types are clients.
602 The methods you declare in a package do not belong to any particular class. **Package methods** must carry a name different from the data types contained in the package. Like any other method, they can be overloaded. With the exception of the keyword **me** and the visibility (a package method can *only* be either public or private) package methods are described in the same way as **instance methods**.
604 @image html /dev_guides/cdl/images/cdl_image010.png "Contents of a package"
605 @image latex /dev_guides/cdl/images/cdl_image010.png "Contents of a package"
608 The example of the package below includes some of the basic data structures:
615 exception NoSuchObject inherits Failure;
616 exception NoMoreObject inherits Failure;
617 generic class SingleList;
622 Note that the class *Set* is declared after the declarations of the *NoSuchObject* and *NoMoreObject* exceptions and the *SingleList* class of which Set is a client. In the same way, the classes *Failure*, *Persistent*, and the exception *NoSuchObject* are defined before they are used. They are defined in the *Standard* package, which appears after the keyword **uses**.
624 @subsubsection occt_cdl_3_3_2 Name space
626 The **name space** or **scope** of a class extends from the beginning of its declaration up to the end of the package in which it appears.
628 Sometimes, two classes, which come from separate packages, are both visible to a third package and carry the same name. For example, there might be two different classes both called “Window” in a screen generator package and in an architectural package. As a client of a data type, you can find yourself in the position of having to remove the ambiguity over the origin of this type; you do this by means of the keyword **from**.
632 -- class-name ::= identifier [from package-name]
633 -- exception-name ::= identifier [from package-name]
634 -- enumeration-name ::= identifier [from package-name]
637 You can use the keyword **from** everywhere the name of a class, exception, or enumeration appears. As a consequence, as a client of the class “Window” you could write wherever necessary:
640 Window from ScreenGenerator
642 Window from ArchitecturalFeatures
645 **Note** that within the description of a package the keyword **from** must be used when referencing any data type that is not defined in this package.
647 Here is a further example:
655 -- class definition using Point from AppropriatePackage wherever Point appears
659 @subsubsection occt_cdl_3_3_3 Declaration of classes
661 You cannot describe a package in one single file. You need to describe it in different units and send them separately to the CDL compiler. Each compilation unit can contain the declaration of a class or of a package. When you describe a class in a unit different than that, which describes its package, you need to specify which package the class belongs to. You do this using the keyword **from**.
663 If the **from** clause appears in the **uses** clause of the package, it does not need to be repeated elsewhere.
665 The following example takes the package “Collection” which was presented above, but this time it is divided into three compilation units.
668 -- First compilation unit, the package “Collection” :
673 exception NoMoreObject inherits Failure from Standard;
674 exception NoSuchObject inherits Failure from Standard;
675 generic class SingleList;
676 generic class Set, Node, Iterator;
678 -- Second compilation unit, the class “SingleList” :
679 generic class SingleList from Collection (Item as
682 Persistent from Standard
684 NoSuchObject from Collection
686 -- definition of the SingleList class
688 -- Third compilation unit, the class “Set” :
689 generic class Set from Collection (Item as Storable)
691 Persistent from Standard;
693 NoSuchObject from Collection,
694 NoMoreObject from Collection
695 private class Node instantiates SingleList
696 from Collection (Item);
701 It is not explicitly stated that the *Node* class belongs to the *Collection* package. In fact any nested class necessarily belongs to the package of the class, which encompasses it.
703 Note that a package can hide certain classes (just as it can hide methods) by declaring them **private**. To make a class private, you prefix its description with the keyword **private**. In the example of the *Collection* package, the *SingleList* class serves only to implement the *Set* class. It is recommended to make it private. You write this as in the following syntax:
712 generic class Set, Node, Iterator;
713 private generic class SingleList;
714 exception NoMoreObject inherits Failure from Standard;
720 @subsection occt_cdl_3_4 Other Data Types
722 The other data types are:
729 @subsubsection occt_cdl_3_4_1 Enumerations
731 The **enumerated types** are the second type, which is manipulated by value. Unlike the primitive types they are extensible because they are defined by the user under the form of enumerations. An enumeration is an ordered sequence of named whole constant values called enumeration constants.
735 declaration-of-an-enumeration ::=
736 enumeration enumeration-name
737 is identifier {’,’ identifier}
738 [end [enumeration-name]]’;’
739 enumeration-name ::= identifier
741 The declaration of an enumeration creates an enumerated type. An object of this type can successively take the value of any one of the constants cited in the list.
745 enumeration MagnitudeSign is Negative, Null, Positive;
748 Inside a package, two enumeration constants cannot have the same name, even if they belong to different enumerated types.
758 enumeration AmericanPresidents is
761 Ford, -- Error: ‘Ford’ already defined
766 @subsubsection occt_cdl_3_4_2 Imports
768 An **imported type** is one of which which has not been defined in CDL. It is up to the supplier of this data type to ensure compatibility with the CDL language by providing services which allow CDL to recognize the imported data type.
770 The CDL syntax for declaring an imported type is:
772 declaration-of-an-imported-type::=[private] imported typename ;
775 Let us try to define an imported type:
777 * In the *MyPack.cdl* file, you declare the imported type:
785 * In the *MyPack_MyImport.hxx* file, you write the following C++ code:
787 #ifndef _MyPack_MyImport_HeaderFile
788 #define _MyPack_MyImport_HeaderFile
789 #include Standard_Type.hxx
790 typedef unsigned long MyPack_MyImport;
791 extern const Handle(Standard_Type)& TYPE
794 * In the *MyPack_MyImport.cxx* file, you write the following C++ code:
796 #ifndef _MyPack_MyImport_HeaderFile
797 #include MyPack_MyImport.hxx
799 const Handle(Standard_Type)& TYPE (MyPack_MyImport)
801 static Handle(Standard_Type) _aType =
802 new Standard_Type (“MyPack_MyImport”,sizeof
808 Then, add the names of these two files <i>(MyPack_MyImport.hxx, MyPack_MyImport.cxx)</i> to a file called FILES in the src subdirectory of the package. If the file does not exist you must create it.
811 @subsubsection occt_cdl_3_4_3 Aliases
813 An **alias** is an extra name for a type, which is already known. It is declared as in the following syntax:
816 declaration-of-an-alias::= [private] alias type1 is type2 [from apackage] ;
823 -- Defined as a quantity of matter.
824 -- Gives rise to the inertial and
825 -- gravitational properties of a body.
826 -- It is measured in kilograms.
829 Having defined *Mass* as a type of *Real*, you can use either *Mass* or *Real* to type an argument when defining a method.
832 @subsubsection occt_cdl_3_4_4 Exceptions
834 In the model recommended by CDL, the principal characteristic of errors is that they are treated in a different place from the place where they appear. In other words, the methods recovering and those raising a given exception are written independently from each other.
836 Subsequently this poses the problem of communication between the two programs. The principle adopted consists in viewing the exception as both a class and an object. The exception class (by means of one of its instances) is used to take control of an exception, which has been raised.
838 Consequently, error conditions are defined by means of **classes of exceptions**. Exception classes are arranged hierarchically so as to be able to recover them in groups. They are all descendents of a single root class called *Failure*, and it is at the level of this class that the behavior linked to the raising of exceptions is implemented.
840 declaration-of-an-exception ::=exception exception-name inherits exception-name
843 All exceptions share identical behavior, that of the class *Failure*. Here are some examples of exception classes:
845 exception NumericError inherits Failure;
846 exception Overflow inherits NumericError;
847 exception Underflow inherits NumericError;
850 The use of exceptions as a means to interrupt the normal execution of one program and then take control of another one depends on the programming language used to implement the methods. See the following chapter <a href="#occt_cdl_4">“Defining the Software Components”</a> on page 32.
853 @subsection occt_cdl_3_5 Schemas
855 The purpose of a **schema** is to list persistent data types, which will be stored in files by the application. A schema groups together persistent packages. A persistent package is one, which contains at least one persistent class.
858 declaration-of-a-schema ::=
861 {package PackageName;}
869 ---Purpose: Defines the Bicycle schema.
871 package FrameComponents;
872 package WheelComponents;
877 **Note** that it is unnecessary to specify all the dependencies of the packages. It is sufficient to specify the highest level ones. The others on which they depend are automatically supplied.
879 @subsection occt_cdl_3_6 Executables
881 The purpose of an **executable** is to make an executable program without a front-end. It can be used to test more than one package at a time. An executable is written in a .cdl file as a set of packages.
884 definition-of-an-executable ::=
885 executable ExecutableName
888 executable ExecutablePart
889 [uses [Identifier as external]
890 [{’,’ Identifier as external}]
891 [UnitName as library]
892 [{’,’ UnitName as library}]
894 {FileName [as C++|c|fortran|object];}
902 executable MyExecUnit
904 -- Describes the executable MyExecUnit
914 -- several binaries can be specified in one .cdl file.
922 @section occt_cdl_4 Defining the Software Components
924 @subsection occt_cdl_4_1 Behavior
926 The behavior of an object class is defined by a list of **methods**, which are either **functions** or **procedures**. Functions return an object, whereas procedures only communicate by passing arguments. In both cases, when the transmitted object is an instance manipulated by a handle, its identifier is passed. There are three categories of methods:
928 * **Object constructor** Creates an instance of the described class. A class will have one or more object constructors with various arguments or none.
929 * **Instance method** Operates on the instance which owns it.
930 * **Class method** Does not work on individual instances, only on the class itself.
932 @subsubsection occt_cdl_4_11 Object Constructors
934 A constructor is a function, which allows the **creation of instances** of the class it describes.
937 constructor-declaration ::=
938 Create [ simple-formal-part ] declaration-ofconstructed-type
939 [ exception-declarations ]
940 simple-formal-part ::=
941 ’(’ initialization-parameter {’;’ initialization parameter}’)’
942 initialization-parameter ::=
943 identifier {’,’ identifier} ’:’ parameter-access datatype
944 [ ’=’ initial-value ]
946 mutable | [ immutable ]
948 numeric-constant | literal-constant | named-constant
949 declaration-of-constructed-type ::=
950 returns [ mutable ] class-name
953 The name of the constructors is fixed: “Create”. The object returned by a constructor is always of the type of the described class. If that type is manipulated by a handle, you *must* declare it as **mutable**, in which case the content of the instance it references is accessible for further modification.
955 For example, the constructor of the class “Point”
957 Create (X, Y, Z : Real)
958 returns mutable Point;
961 With the exception of the types predefined by the language, all types of initialization parameters *must* appear in the **uses** clause of the class of which the constructor is a member.
963 When an initialization parameter is of a type which is manipulated by a handle, an access right *must* be associated with it so as to express if the internal representation of the referenced object is modifiable (**mutable**) or not (**immutable**). The default option is **immutable**. Let, for example, take the constructor of the persistent class “Line”.
966 Create (P : mutable Point; D : mutable Direction)
967 returns mutable Line;
970 In the above example “P” and “D” must be mutable because the constructor stores them in the internal representation of the created line, which is mutable itself. An alternative would be to accept immutable initialization parameters and then copy them into the constructor in a mutable form.
972 The parameters of a native type can have a default value: this is expressed by assigning a constant of the same type to the parameter concerned. Parameters, which have a default value, may not be present when the call to the constructor is made, in which case they take the value specified in the declaration. For this reason, they must all be grouped at the end of the list. Let, for example, take the constructor of the persistent class “Vector”.
975 Create (D : mutable Direction; M : Real = 1.0)
976 returns mutable Vector;
979 A class can have many constructors (in this case, you say they are **overloaded**) provided that they differ in their syntax and that the presence of parameters having default values does not create ambiguities.
981 The restrictions on their use are expressed by a list of **exceptions** against which each constructor is protected.
983 Each class must have at least one constructor to be able to create objects of its type.
985 @subsubsection occt_cdl_4_1_2 Instance Methods
987 An instance method is a function or procedure, which applies to any instance of the class, which describes it.
991 declaration-of-an-instance-method ::= identifier formal-part-of-instance-method
992 [ declaration-of-returned-type ]
993 [ exception-declaration ]
994 formal-part-of-instance-method ::= ’(’ me [’:’ passing-mode parameter-access ] {’;’ parameter}’)’
995 parameter ::= identifier {’,’ identifier} ’:’ passing-mode
997 data-type [ ’=’ initial-value ]
998 passing-mode ::= [ in ] | out | in out
999 parameter-access ::= mutable | [immutable]
1000 declaration-of-returned-type ::= returns return-access data-type
1001 return-access ::= mutable |[ immutable ]| any
1004 The name **me** denotes the object to which the method is applied: you call this the “principal object” of the method. The passing mode expresses whether the direct content of the principal object or a parameter is either:
1007 * created and returned
1008 * read then updated and returned by the method.
1010 Remember that the direct content of an argument of a type which is manipulated by value contains the internal representation of the object itself. Thus, when the argument is of this type, **out** and **in out** mean that the content of the object will undergo a modification. When the method is a function (as is the case for constructors), all the arguments must be **in** (read). This is the default mode.
1012 In case of an argument of a type manipulated by a handle, the direct content being an object identifier, the passing mode addresses itself to the handle, and no longer to the internal representation of the object, the modification of which is controlled by the access right. An argument of this type declared **mutable** may see its internal representation modified. If declared **immutable**, it is protected. When a parameter is both **in out** and **mutable**, the identifiers passed and returned denote two distinct modifiable objects.
1014 When the returned object is manipulated by a handle it can be declared modifiable or not, or indeterminate (**any**). To return an object with an indeterminate access right means that the method transmits the identifier without changing its state and that the method has no right to alter the access right. This functionality is particularly useful in the case of collections; temporarily storing an object in a structure and unable to modify its state.
1016 With the exception of the types predefined by the language, all types of parameters and returned objects, whether manipulated by a handle or by value, *must* appear in the **uses** clause of the class of which the method is a member.
1017 As is the case for constructors, some parameters can have a default value, provided that they are of primitive or enumerated type. They are passed in the **in** mode, and they are found at the end of the list of arguments.
1019 Overloading of instance methods and use of exceptions and post-conditions is allowed and respects the same rules than constructors.
1021 Note the overloading of “Coord” in the following example of instance methods associated with the persistent class “Point”:
1024 Coord (me; X, Y, Z : out Real);
1025 ---Purpose: returns the coordinates of me
1027 Coord (me; i : Integer) returns Real;
1028 ---Purpose: returns the abscissa (i=1), the
1029 -- ordinate (i=2) or the value (i=3) of me
1031 SetCoord (me : mutable; X, Y, Z : Real);
1032 ---Purpose: modifies the coordinates of me
1034 Distance (me; P : Point) returns Real
1035 ---Purpose: returns the distance to a point
1038 In all these cases, **me** is implicitly an object of type *Point*. Only “SetCoord” is able to modify the internal representation of a point.
1040 @subsubsection occt_cdl_4_1_3 Class Methods
1042 A class method is a function or procedure relative to the class it describes, but does not apply to a particular instance of the class.
1045 declaration-of-a-class-method ::= identifier formal-part-of-class-method
1046 [ declaration-of-returned-type ]
1047 [ exception-declaration ]
1048 formal-part-of-class-method ::= ’(’ myclass {’;’ parameter}’)’
1051 The first parameter **myclass** indicates that the method does not apply to a previously created instance, but to the class itself. The rest of the syntax is identical to that of the instance methods. In particular, access rights (**mutable**, **immutable**, **any**) and the argument passing mode (**in**, **out**, **in out**) must remain unchanged. With the exception of the types predefined by the language, all types of parameters must appear in the **uses** clause of the class of which the method is a member. Overloading of class methods and the use of exceptions and post-conditions is allowed, and it follows the same rules as for constructors and instance methods.
1053 Examples of class methods associated with the class “Real”:
1056 First (myclass) returns Real;
1057 ---Purpose: returns lower limit of reals
1059 Last (myclass) returns Real;
1060 ---Purpose: returns upper limit of reals
1063 @subsubsection occt_cdl_4_1_4 Package Methods
1065 Package methods are methods which are members of a package. They are frequently used for library or application initialization, or for offering an application programming interface to the sources to the package. They are sometimes methods used for development purposes but which are not made available to final end-users of the package.
1068 package-method ::= identifier [simple-formal-part][returned-type-declaration]
1069 [exception-declaration]
1073 @subsubsection occt_cdl_4_1_5 Sensitivity to Overloading
1075 When there is more than one method of a class, several methods share the same name but have different syntax, you say the method is overloaded.
1077 In order that the methods can be considered distinct, they must differ either in the number of parameters, or one of their parameters must be of a different type. In particular, you *cannot* overload a method if you merely modify it as follows:
1079 * The type of the returned object when the method behaves as a function
1080 * The name or the mode of passing a parameter (**in**, **out**, or **in out**)
1081 * The mutability of passed objects (**mutable**, **immutable**, **any**)
1082 * Default value of a parameter.
1084 @subsection occt_cdl_4_2 Internal Representation
1086 Each object contains its own state in a private space in the memory. This state consists of a set of **fields**, which include or reference other objects.
1090 declaration-of-the-internal-representation-of-a-class ::= fields field {field}
1091 field ::= identifier {’,’ identifier} ’:’ data-type [’[’integer {’,’integer}’]’]’;’
1094 A copy of all the defined fields exists locally in each instance of the class. This group of fields will be initialized by the class constructors when the object is instantiated.
1096 Fields *must not* have the same name as any method of the class in which they appear. When the field type is followed by a list of integer constants between square brackets, the data will take the form of a multi-dimensional array containing objects of this type.
1098 The following example shows two equivalent ways of describing three fields of the “Real” type:
1108 Depending on their type, Object fields have one of the two forms. When the field is of the “manipulated by handle” type, it corresponds to an identifier. In this case, the contents of the object can be shared by other objects or by a handle in a program. When the field is of a “manipulated by value” type, it contains the value of the object. In this case you say the object is **embedded**.
1110 @subsection occt_cdl_4_3 Exceptions
1112 Exceptions describe exceptional situations, which can arise during the execution of a method. With the raising of an exception, the normal course of program execution is interrupted. The actions carried out in response to this situation are called treatment of exception.
1114 exception-treatment ::= raises exception-name {’,’ exception-name}
1116 Each exception name corresponds to a class of exceptions previously defined as being susceptible to being raised by the method under which it appears. Exception classes must all appear in the **raises** clause of the class of which the method is a member. The class of exceptions is analogous to the class of objects described in this manual.
1118 Take for example the method which returns the x, y, or z coordinate of a point.
1121 Coord (me; i : Integer) returns Real
1123 -- Returns the abscissa (i=1)
1124 -- the ordinate (i=2)
1125 -- or the value (i=3)
1128 -- if i is not equal to 1, 2, or 3.
1132 Instance methods are likely to raise certain exceptions called **systematic exceptions** which do not have to appear. They are:
1134 * *NullObject* - raised when the principal object does not exist.
1135 * *ImmutableObject* - raised when a method tries to modify an immutable principal object.
1136 * *TypeMismatch* - raised if an argument typed by association is of an unsuitable type.
1138 These exceptions are described in the Standard Package (System Toolkits).
1141 @subsection occt_cdl_4_4 Inheritance
1143 @subsubsection occt_cdl_4_4_1 Overview
1145 The notion of inheritance comes from a development strategy according to which you begin by modeling data in the most general fashion. Then you specialize it more and more so as to correspond to more and more precise cases.
1147 For example, to develop a basic geometry, you can first of all consider the group of geometric objects, and then differentiate the points, vectors, and curves. You can specialize the latter into conic sections, and then decompose them into circles, ellipses, and hyperbolas. Then, the class of conics is considered as a sub-class of curves, and a super-class of circles.
1149 A sub-class has at least the behavior of its super-classes. Thus, a circle could be viewed as a conic, a curve, or even as a geometric object. In each case, the applicable methods belong to the level where you view the class. In this case, you say that the sub-class inherits the behavior from its super-classes.
1154 declaration-of-a-sub-class ::= class class-name
1156 [uses data-type {’,’ data-type}]
1157 [raises exception-name {’,’ exception-name}]
1162 A class cannot inherit one of its descendent classes; nor can it inherit a native type. All the classes of a system can be described in a non-cyclic diagram called the **inheritance graph**.
1164 The definition of a sub-class is identical to that of a simple class. Note that a super-class must not appear in the **uses** clause of the sub-class, even if it appears in the definition of the sub-class. The behavior of a sub-class includes as a minimum all instance methods and protected methods of its super-classes.
1166 **Note** that constructors and class methods are never inherited.
1168 @subsubsection occt_cdl_4_4_2 Redefining methods
1170 Certain inherited methods can be redefined.
1175 declaration-of-a-redefined-method ::= identifier formal-part-of-instance-method [returnedtype- declaration]
1176 [declaration-of-exceptions]
1177 is redefined [visibility]’;’
1180 A redefined method must conform to the syntax described in the super-class where it appears. The exceptions contained in the super-class can be renewed, and others may be added as long as they inherit from an ancestor class.
1182 The redefined attribute can be applied neither to a constructor, nor to a class method, since neither of them can be inherited. If the redefined method is private or protected, the visibility must be exactly repeated in the redefinition. For further details on visibility, refer to <a href="#occt_cdl_4_6"> Visibility </a> section.
1187 SquareDistance (me; P : Point) returns Real
1188 is redefined private;
1191 With regards to the internal representation, all fields defined in the super-classes are, by default, inherited, but they can also be redefined.
1193 @subsubsection occt_cdl_4_4_3 Non-redefinable methods
1195 Instance methods, which are declared virtual are redefinable in descendent classes, and you can force this redefinition by making a method **deferred**. For more details, see the next section.
1200 declaration-of-a-non-redefinable-method ::= identifier formal-part-of-instance-method [returnedtype- declaration]
1201 [declaration-of-exceptions]
1202 is virtual [visibility]’;’
1205 All methods are static by default. To enable redefinition in all the child classes, add **is virtual** when declaring the method.
1207 You must also be able to forbid redefinition. A redefinable method can become non-redefinable if you declare: **is redefined static**.
1210 @subsubsection occt_cdl_4_4_4 Deferred Classes and Methods
1212 The presence of certain classes in the inheritance graph can be justified purely by their ability to force certain behavior on other classes, in other words, to make other classes provide various services.
1214 The CDL language allows you to describe a class, which introduces methods without implementing them, so as to force its descendent classes to define them. These are called **deferred classes**; the non-implemented methods are also termed **deferred methods**.
1219 declaration-of-a-deferred-class ::= deferred class class-name
1220 [inherits class-name [uses data-type {’,’ data-type}]
1221 [raises exception-name {’,’ exception-name}]
1224 declaration-of-a-deferred-method ::= identifier formal-part-of-instance-method [returnedtype- declaration]
1225 [declaration-of-exceptions]
1226 is deferred [visibility]’;’
1229 Only instance methods can be deferred.
1231 It is sufficient for a class to contain one deferred method for it to be a deferred class. It can contain any number of deferred methods (or none).
1233 A deferred class may still have an internal representation but one or more **non-protected** constructors would be necessary to initialize them. The constructors must be visible in the sub-classes.
1235 The constructors of a deferred class are called **Initialize** (not **Create**). They are **protected** by default, and do not return any object. You cannot create an object of a deferred class type.
1236 For example, consider the class *Point*, and its declaration as deferred.
1240 deferred class Point inherits Geometry is
1242 ---Purpose: Initializes the point.
1243 Coord (me; X, Y, Z : out Real)
1244 ---Purpose: Returns the coordinates
1246 SetCoord (me : mutable; X, Y, Z : Real)
1247 ---Purpose: Modifies the coordinates
1249 Distance (me; P : Point) returns Real;
1250 ---Purpose: Returns the distance from the point P
1254 Notice that the function *Distance* is not deferred. Although this class contains no representation, this method is programmable by calling *Coord*.
1256 In a sub-class of a deferred class, all deferred methods, which have been inherited, must be implemented, then redeclared (the attribute **redefined** is useless for this purpose), unless the sub-class is itself deferred.
1258 A non-deferred method can be redefined as a deferred one, in which case it will be declared as follows: **is redefined deferred**.
1260 The notion of deferred class is very useful. The advantage of introducing it, as was previously shown in the deferred class *Point*, is that the corresponding resources will be available even before being implemented. Later, you can add different representations to Point (for example, spherical or Cartesian coordinates) without having to modify client programs.
1262 Thanks to the possibility of redefining methods, this approach does not have any negative impact on performance: a method implemented at the level of a deferred class can be reprogrammed in one of its sub-classes while taking into account the data representation.
1264 @subsubsection occt_cdl_4_4_5 Declaration by Association
1266 At the heart of a class hierarchy, object identifiers are compatible in the ascendant sense. Since the *Conic* class is descended from the *Curve* class, an identifier of type *Curve* can reference an object of type *Conic* (remember that the behavior of *Curve* is applicable to *Conic*). In other words, you can assign a reference to a *Conic* to an identifier of type *Curve*, but not vice versa.
1268 For example, once the classes have been compiled you could write a C++ test program in which you instantiate a Conic but reference it with a handle to a Curve:
1270 Handle(Curve) c = new Conic
1272 This same rule applies to parameters of methods; that is to say, you can call a method with identifiers corresponding to a sub-type of that specified in its declaration. To illustrate this, let us go back to the “Distance” method of the “Point” class:
1275 Distance (me; P : point) returns Real;
1277 Conforming to the rule of type compatibility, you could make a call to the method “Distance” with reference to an object from a class descended from “Point”. Consequently, if “SphericPoint” is a sub-class of “Point” and therefore inherits this method, it will be possible to calculate the distance between two “SphericPoint”, or between a “SphericPoint” and a “Point”, without having to redefine the method.
1279 On the other hand, sometimes you may want to force two parameters to be exactly of the same type, and thus not apply the rule of type compatibility. To do this, you need to associate the type of the concerned parameters in the method declaration.
1282 association-typing ::= like associated-parameter
1283 associated-parameter ::= me | identifier
1286 Note that identifier is the name of a parameter, which appears first in the formal part of the declaration of the method.
1289 You can use this technique, which consists in declaring by association, to declare a method that will exchange the content of two objects, or a method, which copies another object:
1292 Swap (me : mutable; With : mutable like me);
1293 DeepCopy (me) returns mutable like me;
1296 Make sure not to write the Swap method as in the syntax below:
1300 Swap (me : mutable; With : mutable Point);
1303 In this case **me** may be a CartesianPoint or a SphericalPoint, while *With* can only be a Point.
1305 @subsubsection occt_cdl_4_4_6 Redefinition of Fields
1307 The creation of a hierarchy of classes should be viewed as a means to specialize their behavior, (e.g. a circle is more specialized than a conic section). The more you specialize the object classes, the more it is justified to call into question the inherited fields in order to obtain greater optimization. So, in the description of the internal representation of a sub-class, it is possible not to inherit all of the fields of the super-classes. You then say the fields have been redefined.
1310 redefinition-of-the-representation-of-a-class ::= redefined redefinition-of-a-field {’,’ redefinition-of-a-
1312 redefinition-of-a-field ::= [field-name] from [class] class-name
1315 Redefinition of fields can only be done in classes manipulated by a handle.
1317 This declaration appears at the beginning of the definition of the internal representation of the sub-class, which breaks the field inheritance. The non-inherited fields are all those which come from the class specified behind the rubric **from**.
1320 @subsection occt_cdl_4_5 Genericity
1322 @subsubsection occt_cdl_4_5_1 Overview
1324 Inheritance is a powerful mechanism for extending a system, but it does not always allow you to avoid code duplication, particularly in the case where two classes differ only in the type of objects they manipulate (you certainly encounter this phenomenon in all basic structures). In such cases, it is convenient to send arbitrary parameters representing types to a class. Such a class is called a **generic class**. Its parameters are the generic types of the class.
1326 Generic classes are implemented in two steps. You first declare the generic class to establish the model, and then instantiate this class by giving information about the generic types.
1328 @subsubsection occt_cdl_4_5_2 Declaration of a Generic Class
1330 The syntax is as follows:
1333 declaration-of-a-generic-class ::= [deferred] generic class class-name ’(’generic-type {’,’generic-type}’)’
1334 [inherits class-name
1335 [uses data-type {’,’ data-type}]
1336 [raises exception-name {’,’ exception-name}]
1339 generic-type ::= identifier as type-constraint
1340 type-constraint ::= any | class-name [’(’data-type {’,’data-type}’)’]
1343 The names of generic types become new types, which are usable in the definition of a class, both in its behavior (methods) and its representation (fields). The generic type is only visible inside the generic class introducing it. As a result, it is possible to have another generic class using the same generic type within the same package.
1345 When you specify the type constraint under the form of a class name, you impose a minimum set of behavior on the manipulated object.
1347 This shows that the generic type has as a minimum the services defined in the class. This can be any kind of a previously defined class, including another generic class, in which case you state exactly with what types they are instantiated.
1349 When the generic type is constrained by the attribute **any**, the generic class is intended to be used for any type at all, and thus corresponds to classes whether manipulated by a handle or by value.
1351 No class can inherit from a generic class.
1353 A generic class can be a deferred class. A generic class can also accept a deferred class as its argument. In both these cases any class instantiated from it will also be deferred. The resulting class can then be inherited by another class.
1355 Below is a partial example of a generic class: a persistent singly linked list.
1358 generic class SingleList (Item as Storable)
1362 Create returns mutable SingleList;
1363 ---Purpose: Creates an empty list
1364 IsEmpty (me) returns Boolean;
1365 ---Purpose: Returns true if the list me is empty
1366 SwapTail (me : mutable; S : in out mutable
1368 ---Purpose: Exchanges the tail of list me with S
1369 -- Exception NoSuchObject raised when me is empty
1370 raises NoSuchObject;
1371 Value (me) returns Item
1372 ---Purpose: Returns first element of the list me
1373 -- Exception NoSuchObject raised when me is empty
1374 raises NoSuchObject;
1375 Tail (me) returns mutable SingleList
1376 ---Purpose: Returns the tail of the list me
1377 -- Exception NoSuchObject raised when me is empty
1378 raises NoSuchObject;
1385 Even though no object of the type “SingleList” IS created, the class contains a constructor. This class constitutes a model, which will be recopied at instantiation time to create a new class which will generate objects. The constructor will then be required.
1389 generic class Sequence(Item as any, Node as
1396 In the above example, there are two generic types: *Item* and *Node*. The first imposes no restriction. The second must at least have available the services of the class *SingleList* instantiated with the type with which *Sequence* will itself be instantiated.
1398 In the incomplete declaration of a generic class, the keyword **generic** must appear.
1402 generic class SingleList;
1403 generic class Sequence;
1406 @subsubsection occt_cdl_4_5_3 Instantiation of a Generic Class
1408 The syntax is as follows:
1411 instantiation-of-a-generic-class ::= [deferred] class class-name
1412 instantiates class-name ’(’data-type {’,’ data-type}’);’
1415 Instantiation is said to be **static**. In other words, it must take place before any use can be made of the type of the instantiated class. Each data type is associated term by term with those declared at the definition of the generic class. These latter ones, when they are not of the type **any**, restrict instantiation to those classes, which have a behavior at least equal to that of the class specified in the type constraint, including constructors. Note that this is not guaranteed by inheritance itself.
1417 For example, let’s instantiate the class *Sequence* for the type *Point*:
1420 class SingleListOfPoint instantiates SingleList(Point);
1421 class Sequence instantiates
1422 Sequence(Point,SingleListOfPoint);
1425 The instantiation of a generic deferred class is a deferred class (the **deferred** attribute must be present during instantiation). An instantiated class cannot be declared in an incomplete fashion.
1427 @subsubsection occt_cdl_4_5_4 Nested Generic Classes
1429 It often happens that many classes are linked by a common generic type. This is the case when a base structure provides an iterator, for example, in the class *Graph*. A graph is made up of arcs, which join together the nodes, which reference objects of any type. This type is generic both for the graph and for the node. In this context, it is necessary to make sure that the group of linked generic classes is indeed instantiated for the same type of object. So as to group the instantiation, CDL allows the declaration of certain classes to be nested.
1434 declaration-of-a-generic-class ::= [deferred] generic class class-name ’(’generic-type{’,’generic-type}’)’
1435 [inherits class-name {’,’ class-name}]
1436 [uses data-type {’,’ data-type}]
1437 [raises exception-name {’,’ exception-name}]
1438 [{[visibility] class-declaration}]
1441 class-declaration ::= incomplete-declaration-of-a-class | declaration-of-a-non-generic-class | instantiation-of-a-generic-class
1444 **Nested classes**, even though they are described as non-generic classes, are generic by construction, being inside the class of which they are a part. As a consequence, the generic types introduced by the **encompassing class** can be used in the definition of the nested class. This is true even if the generic type is only used in a nested class. The generic types still must appear as an argument of the encompassing class. All other types used by a nested class must appear in its **uses** or **raises** clauses, just as if it were an independent class.
1446 Nested classes are, by default, **public**. In other words, they can be used by the clients of the encompassing class. On the other hand, when one of the nested classes is declared **private** or **protected**, this class must not appear in any of the public methods of the other classes. It cannot be used in a protected field because then it could be used in a sub-class, which implies it would not be private.
1448 The following example shows how to write the Set class with its iterator.
1451 generic class Set (Item as Storable)
1453 private class Node instantiates SingleList (Item);
1456 raises NoSuchObject, NoMoreObject
1458 Create (S : Set) returns mutable Iterator;
1459 ---Purpose: Creates an iterator on the group S
1460 More (me) returns Boolean;
1461 ---Purpose: Returns true if there are still elements
1463 Next (me) raises NoMoreObject;
1464 ---Purpose: Passes to the following element
1465 Value (me) returns any Item raises NoSuchObject;
1466 ---Purpose: Returns the current element
1471 Create returns mutable Set;
1472 ---Purpose: Creates an empty group
1473 IsEmpty (me) returns Boolean;
1474 ---Purpose: Returns true if the group is empty
1475 Add (me : mutable; T : Item);
1476 ---Purpose: Adds an item to the group me
1477 Remove (me : mutable; T : item) raises
1479 ---Purpose: Removes an item from the group me
1486 Note that in their fields, both “Set” and “Iterator” are clients of another class, “Node”. This last can be effectively declared **private** for it only appears in fields which are themselves private.
1488 The instantiation of a generic class containing nested classes remains unchanged. The same declaration is used to instantiate the encompassing class and the nested classes. These latter will have their name suffixed by the name supplied at instantiation, separated by “Of”. For example, you instantiate the class “Set” described above for the type “Point” as follows:
1491 class SetOfPoint instantiates Set(Point);
1493 In doing so, you implicitly describe the classes “NodeOfSetOfPoint” and “IteratorOfSetOfPoint”, which are respectively the result of the concatenation of “Node” and “Iterator” with “Of” then “SetOfPoint”.
1495 Note that in the incomplete declaration of an encompassing class, all the names of the nested classes *must* appear behind that of the encompassing class.
1498 incomplete-declaration-of-a-generic-class ::= [deferred] generic class-name {’,’ class-name};
1501 For example, an incomplete declaration of the above class “Set” would be as in the example below:
1504 generic class Set, Node, Iterator;
1507 Only the encompassing class can be deferred. In the above example only the class “Set” can be deferred.
1511 @subsection occt_cdl_4_6 Visibility
1513 @subsubsection occt_cdl_4_6_1 Overview
1515 A field, method, class, or package method is only available for use if it is **visible**.
1516 Each of these components has a default visibility, which can be explicitly modified during class or package declaration. The three possible states of visibility are:
1521 @subsubsection occt_cdl_4_6_2 Visibility of Fields
1523 A field is **private**. It can never be public - this would destroy the whole concept of data encapsulation. The attribute **private** is redundant when it is applied to a field. This means that a field is only visible to methods within its own class.
1524 A field can be declared **protected**, which means that it becomes visible in subclasses of its own class. Its contents can be modified by methods in subclasses.
1527 field ::= identifier {’,’ identifier} ’:’ data-type
1528 [’[’integer{’,’integer}’]’]
1536 Phi, Delta, Gamma : AngularMomenta [3]
1540 @subsubsection occt_cdl_4_6_3 Visibility of Methods
1542 Methods act on fields. Only methods belonging to a class can act on the fields of the class; this stems from the principle of object encapsulation. Methods can be characterized in three ways: by default, methods are **public**. Methods can be declared **private** or **protected** to restrict their usage.
1544 * **Public** methods are the default and generally the most common. They describe the behavior of a class or a package, and they are callable by any part of a program.
1545 * **Private** methods exist only for the internal structuring of their class or their package. Private class methods can only be called by methods belonging to the same class. Private package methods can only be called by all methods belonging to the same package and its classes.
1546 * **Protected** methods are private methods, which are also callable from the interior of descendent classes.
1548 If you want to restrict the usage of a method, you associate with it a visibility as follows :
1550 -- declaration-of-the-visibility ::= is visibility
1551 visibility ::= private | protected
1554 The declaration of the visibility of a method appears at the end of its definition, before the final semi-colon. The attribute **private** indicates that the method will only be visible to the behavior of the class of which the method is a member; **protected** will propagate the visibility among the sub-classes of this class.
1556 For example, add to the class “Line” an internal method allowing the calculation of the perpendicular distance to the power of two, from the line to a point.
1559 SquareDistance (me; P : Point) returns Real
1563 @subsubsection occt_cdl_4_6_4 Visibility of Classes, Exceptions and Enumerations
1565 The visibility of a class is the facility to be able to use this class in the definition of another class. The visibility of a class extends from the beginning of its declaration up to the end of the package in which it appears. You have seen that the keyword **uses** allows extension of this visibility to other packages.
1567 As was explained in the section on “<a href="#occt_cdl_3_3_2">Name Space</a>”, any ambiguity, which arises from having two classes with the same name coming from different packages, is dealt with by the use of the keyword **from**.
1569 A class declared **private** is only available within its own package.
1571 @subsubsection occt_cdl_4_6_5 Friend Classes and Methods
1573 In certain cases, methods need to have direct access to the private or protected parts of classes of which they are clients. Such a method is called a **friend** of the class, which is accessed. For example, you declare a method to be a friend when a service can only be obtained via the use of another non-descendent class, or perhaps when this will help to improve performance.
1575 Classes can also be declared friends of other classes. In this case all the methods of the friend class will have access to the fields and methods of the host class. The right is **not reciprocal**.
1577 Friend classes or methods are declared inside the class, which reveals its private and protected data or methods to them. This helps in managing the continuing evolution of a class, helping to recognize and to avoid the creation of side effects.
1581 declaration-of-friends ::= friends friend {’,’friend}
1582 friend ::= identifier from [class] class-name [formal-part] |
1583 -- Defining the Software Components 67
1584 identifier from [package] package-name [formal-part] | class] class-name
1585 formal-part ::= simple-formal-part | formal-part-of-instance-method | formal-part-of-class-method
1588 The formal part must be present if the method contains one; thus this can be overloaded without necessarily propagating the friend relationship among its homonyms. The keyword **class** allows you to avoid certain ambiguities. For example, it removes any confusion between “method M from class C” and “method M from package P”.
1590 As an example, take a method, which calculates the perpendicular distance between a line and a point. Suppose this method needs to access the fields of the point. In the class “Point” you would write:
1593 friends Distance from Line (me; P : Point)
1596 A method can be a friend to many classes. The class to which the method belongs does not need to appear in the **uses** clause of other classes of which it is a friend.
1598 When the methods of a class are all friends of another class, you can establish the friendship at the level of the class.
1601 | | Public | Private | Protected |
1602 | :---- | :---- | :---- | :----- |
1603 | Field | Does not exist | **Default** - Visible to methods in its own class and in friend classes | Visible to methods in its own class, sub-classes and friend classes |
1604 | Method | **Default** - Callable anywhere | Callable by methods in its own class and in friend classes | Callable by methods in its own class, sub-classes and friend classes |
1605 | Class | **Default** - Visible everywhere with the use of **from** rubric | Visible to classes in its own package | Does not exist |
1606 | Package method | **Default** - Callable everywhere with the use of **from** rubric | Visible to classes in its own package | Does not exist |
1607 | Nested Class | **Default** - Visible to the clients of the encompassing class | Visible to the encompassing class and other classes nested in the encompassing class | Does not exist |
1610 @section occt_cdl_5 Appendix A. Syntax Summary
1613 This summary of the CDL syntax will aid in the comprehension of the language, but does *not* constitute an exact definition thereof. In particular, the grammar described here accepts a super-set of CDL constructors semantically validated.
1615 (1) capital ::= ’A’ | ’B’ | ’C’ | ’D’ | ’E’ | ’F’ | ’G’ | ’H’ | ’I’ | ’J’ | ’K’ | ’L’ | ’M’ | ’N’ |
1616 ’O’ | ’P’ | ’Q’ | ’R’ | ’S’ | ’T’ | ’U’ | ’V’ | ’W’ | ’X’ | ’Y’ | ’Z’
1618 (2) non-capital ::= ’a’ | ’b’ | ’c’ | ’d’ | ’e’ | ’f’ | ’g’ | ’h’ | ’i’ | ’j’ | ’k’ | ’l’ | ’m’ | ’n’ |
1619 ’o’ | ’p’ | ’q’ | ’r’ | ’s’ | ’t’ | ’u’ | ’v’ | ’w’ | ’x’ | ’y’ | ’z’
1621 (3) digit ::= ’0’ | ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ | ’8’ | ’9’
1623 (4) underscore ::= ’_’
1625 (5) special character ::= ’ ’ | ’!’ | ’”’ | ’#’ | ’$’ | ’%’ | ’&’ | ’’’ | ’(’ | ’)’ | ’*’ | ’+’ | ’,’ | ’-’ | ’.’ | ’/’ | ’:’ | ’;’ | ’’ | ’=’ | ’’ | ’?’ | ’@’ | ’[’ | ’\’ | ’]’ | ’^’ | ’‘’ | ’{’ | ’|’ | ’}’ | ’~’
1627 (6) printable character::= capitals | non-capitals | digits | underscore | special characters
1629 (7) letter ::= capital | non-capital
1631 (8) alphanumeric ::= letter | digit
1633 (9) identifier ::= letter{[underscore]alphanumeric}
1635 (10) integer ::= digit{digit}
1637 (11) exponent ::= ’E’[’+’]integer | ’E-’integer
1639 (12) numeric-constant ::= [’+’]integer ’.’ integer[exponent] | ’-’integer ’.’ integer[exponent]
1642 (13) literal-constant ::= ’’’printable character’’’ | ’~’{printable
1645 (14) package-name ::= identifier
1647 (15) enumeration-name ::= identifier [**from** package-name]
1649 (16) class-name ::= identifier [**from** package-name]
1651 (17) exception-name ::= identifier [**from** package-name]
1653 (18) constructor-name ::= ’Create’ | ’Initialize’
1655 (19) primitive-type ::= ’Boolean’ | ’Character’ | ’Integer’ | ’Real’
1657 (20) data-type ::= enumeration-name | class-name | exception-name | primitive-type
1659 (21) passed-type ::= data-type | **like me** | **like** identifier
1661 (22) passing-mode ::= [**in**] | **out** | **in out**
1663 (23) parameter-access ::= **mutable** | [**immutable**]
1665 (23A) return-access ::= **mutable** | [**immutable**]| **any**
1667 (24) value ::= numeric-constant | literal-constant | identifier
1669 (25) parameter ::= identifier {’,’ identifier} ’:’ passing-mode access-right passed-type [’=’ value]
1671 (26) simple-formal-part ::= ’(’parameter {’;’ parameter}’)’
1673 (27) formal-part-of-instance-method ::= ’(’ **me** [’:’ passing-mode access-right] {’;’ parameter}’)’
1675 (28) formal-part-of-class-method ::= ’(’ **myclass** {’;’ parameter}’)’
1677 (29) visibility ::= **private** | **protected**
1679 (30) redefinition ::= **static** | **deferred**
1681 (31) definition-level ::= redefinition | **redefined** [redefinition]
1683 (32) declaration-of-constructed-type ::= **returns** [**mutable**] class-name
1685 (33) declaration-of-returned-type ::= **returns** return-access passed-type
1687 (34) declaration-of-errors ::= **raises** exception-name {’,’ exception-name}
1689 (35) declaration-of-visibility ::= **is** visibility
1691 (36) declaration-of-attributes-of-instance-method ::= **is** visibility | **is** definition-of-level [visibility]
1693 (37) constructor ::= constructor-name [simple-formal-part]
1694 [declaration-of-constructed-type]
1695 [declaration-of-errors]
1696 [declaration-of-visibility]’;’
1698 (38) instance-method ::= identifier formal-part-of-instance-method
1699 [declaration of returned type]
1700 [declaration-of-errors]
1701 [declaration-of-attributes-of-instancemethod]’;’
1703 (39) class-method ::= identifier formal-part-of-the-class-method
1704 [declaration of returned type]
1705 [declaration-of-errors]
1706 [declaration-of-visibility]’;’
1708 (40) package-method ::= identifier [simple-formal-part]
1709 [declaration-of-returned-type]
1710 [declaration-of-errors]
1713 (41) member-method ::= constructor | instance-method | class-method
1715 (42) formal-part ::= simple-formal-part | formal-part-of-instance-method| formal-part-of-class-method
1717 (43) friend ::= identifier **from** [**class**] class-name [formal-part]
1718 | identifier **from** [**package**] package-name [formal-part] |
1719 [**class**] class-name
1721 (44) field ::= identifier {’,’ identifier} ’:’ data-type
1722 [’[’integer {’,’ integer}’]’]
1723 [**is protected**]’;’
1725 45) redefinition-of-field ::= [field-name] **from** [**class**] class-name
1727 (46) declaration-of-fields ::= **fields** [**redefined** redefinition-of-field {’,’ redefinition-of-field}’;’]
1730 (47) declaration-of-an-alias::= [**private**] **alias** class-name1 **is** class-name2 [**from** package-name]
1732 (48) declaration-of-friends ::= **friends** friend {’,’ friend}
1734 (49) class-definition ::= [{member-method}]
1735 [declaration-of-fields]
1736 [declaration-of-friends]
1738 (50) declaration-of-an-exception ::= **exception** exception-name **inherits** exception-name
1740 (51) declaration-of-an-enumeration ::= **enumeration** enumeration-name
1741 **is** identifier {’,’ identifier}
1742 [**end** [enumeration-name]]’;’
1744 (52) incomplete-declaration-of-a-non-generic-class ::=
1745 [**deferred**] **class** class-name’;’
1747 (53) incomplete-declaration-of-a-generic-class ::=
1748 [**deferred**] **generic class** class-name {’,’ class-name}’;’
1750 (54) declaration-of-a-non-generic-class ::=
1751 [**deferred**] **class** class-name
1752 [**inherits** class-name
1753 [**uses** data-type {’,’ data-type}]
1754 [**raises** exception-name {’,’ exception-name}]
1755 **is** definition-of-a-class
1756 **end** [class-name]’;’
1758 (55) type-constraint ::= **any** | class-name [’(’data-type {’,’ data-type}’)’]
1760 (56) generic-type ::= identifier **as** type-constraint
1762 (57) declaration-of-a-generic-class ::=
1763 [**deferred**] **generic class** class-name ’(’generic-type
1764 {’,’ generic-type}’)’
1765 [**inherits** class-name
1766 [**uses** data-type {’,’ data-type}]
1767 [**raises** exception-name {’,’ exception-name}]
1768 [{[visibility] declaration-of-a-class}]
1769 **is** class-definition
1770 **end** [class-name]’;’
1772 (58) instantiation-of-a-generic-class::=
1773 [**deferred**] **class** class-name
1774 **instantiates** class-name ’(’data-type
1777 (59) declaration-of-a-class::=
1778 incomplete-declaration-of-a-non-generic-class
1780 incomplete-declaration-of-a-generic-class |
1781 declaration-of-a-non-generic-class |
1782 declaration-of-a-generic-class |
1783 instantiation-of-a-generic-class
1785 (60) type-declaration ::=
1786 [private] declaration-of-an-enumeration | [**private**] class-declaration | declaration-of-an-exception
1788 (61) package-definition ::=
1789 [{type-declaration}]
1792 (62) package-declaration ::= **package** package-name
1793 [**uses** package-name {’,’ package-name}]
1794 **is** package-definition
1795 **end** [package-name]’;’
1797 (63) executable-declaration ::=
1798 **executable** executable-name
1801 **executable** executable-part
1802 [**uses** [identifier **as external**]
1803 [{’,’ identifier **as external**}]
1804 [unit-name **as library**]
1805 [{’,’ unit-name **as library**}]
1807 {file-name [as C++|c|fortran|object];}
1812 (64) schema-declaration ::=
1813 **schema** schema-name
1815 [{**package** package-name ’;’ }]
1816 [{**class** class-name ’;’ }]
1823 @section occt_cdl_6 Appendix B Comparison of CDL and C++
1825 ## Syntax for Data Types manipulated by Handle and by Value in CDL
1827 | | Handle | Value |
1828 | :---- | :---- | :---- |
1829 | Permanent | Persistent | Storable |
1830 | Temporary | Transient | Any |
1831 | Reading | Immutable | In |
1832 | Writing | Mutable | Out |
1833 | Read/Write | Mutable | In out |
1834 | Return | Not specified : any | Without copy: --C++ return const& |
1836 ## Syntax for Data Types manipulated by Handle and by Value in C++
1838 | | Handle | Value |
1839 | :---- | :---- | :--- |
1840 | C++ Declaration | Handle(PGeom_Point) p1; | gp_Pnt p2; |
1841 | C++ Constructor | p1 = newPGeom_Point(p2); | p2(0.,0.,0.); |
1842 | C++ Method | x=p1 -> XCoord(); | x=p2.XCoord(); |