**3. Definition and implementation of component based on BiCOMC model**

In this section the component based on BiCOMC is defined, and its implementation is shown using examples. **Figure 5** shows an example of the class Comp\_1 based on BiCOMC, where the interface Interface\_1 and the interface Interface\_2 inherit the interface Object and Interface\_3 inherits Interface\_2. The definition of the interfaces in **Figure 5** is shown in **Figure 7**. The class Comp\_1 is one of the components that provide interfaces Interface\_1 and Interface\_3. Interface Interface\_1 consists of void mth\_1(int) and int. mth\_2(), and interface Interface\_3 inherits interface Interface\_2 and consists of void mth\_1() and int. mth\_2(int).

#### *Computer Methods and Programs in Biomedical Signal and Image Processing*

**Figure 5.** *Class diagram example of relationship between component and interface.*

**Figure 6** shows an example of the interface casting algorithm in **Figure 4**, which shows that Interface\_1 is converted to Interface\_2 using bicomc\_cast based on the algorithm in **Figure 4**.

The macro BICOMC\_INTERFACE defines interfaces as shown in **Figure 7**, using one or two parameters. The first parameter is the name of the interface, and the second parameter is the name of the parent interface and optional. In the case where the second parameter is empty, the interface Object is inherited. The macro BICOMC\_DECL\_METHOD in **Figure 7** declares the method of the interface. The macro has three parameters as follows: the first parameter is the name of the method, the second parameter is the function type of the method, and the third parameter is the number of parameters of the method. For example, let us consider BICOMC\_DECL\_METHOD(mth\_2, int.(), 0). This macro represents the method int. mth\_2() in **Figure 8**.

The interface definition in **Figure 7** is converted into the C++ code of **Figure 8** by C++ preprocessor. Note that C++ code for Interface\_2 is not represented. The macro BICOMC\_INTERFACE in **Figure 7** is converted to the C++ code related to the inputted interface name such as Interface\_1. As seen in the 1st and 17th lines of **Figure 8**, the macro BICOMC\_INTERFACE (Interface\_1) and BICOMC\_ INTERFACE (Interface\_3, Interface\_2) create the codes of class Interface\_1 public Object and class Interface\_3 public Interface\_2, respectively. The macro BICOMC\_ DECL\_METHOD is converted to a method which consists of a name, a return type, and parameters. The second, third, and eleventh lines in **Figure 7** are converted into the third–seventh lines, ninth–fourteenth lines, and nineteenth to twenty-fourth lines in **Figure 8**, respectively. From the virtual function table pointed at by the vftptr pointer of the interface Object, the addresses of functions(or methods) are acquired using the inheritance depth of the interface and the order of declarations of the interface methods as shown in the 5th, 11th, and 21st lines in **Figure 8**, and then the actual overridden methods are called. These methods are converted into the function type as shown in **Figure 9** and then stored. Note that ErrorCode is a wrapper class of ErrorDetail in **Figure 1**.

**Figure 6.** *An example of interface casting.* *How to Keep the Binary Compatibility of C++ Based Objects DOI: http://dx.doi.org/10.5772/intechopen.77383*

#### **Figure 7.**

*Definition of interface using macro in* **Figure 5***.*

#### **Figure 8.**

*C++ code of* **Figure 7** *after preprocessing.*

In **Figure 9**, parameter I\* is the address of the interface instance, the second parameter R\* is the address of the variable receiving the return value of the method, and other parameters (P\_1…P\_N) are parameters of the method. The method stored in the function type is called with the same function-calling convention. Note that exception information is returned using the interface ErrorDetail. When the exception information has been returned, the C++ code of the method throws the exception on behalf of the method as shown in the 6th, 12th, and 22nd lines in **Figure 8**.

**Figure 10** shows the implementation of the interfaces in **Figure 7**. The interfaces in **Figure 7** are inherited, and the methods are overridden in order to define the class Comp\_1. The interfaces and methods for overriding are set using the macros BICOMC\_OVERRIDE and BICOMC\_OVER\_METHOD. Parameters of the macro

**Figure 9.** *Function type stored in the virtual function table.*

#### **Figure 10.**

*Implementation of interfaces and overriding.*

#### **Figure 11.**

*C++ code of* **Figure 10** *after preprocessing.*

BICOMC\_OVERRIDE are names of all interfaces that the component inherits. Parameters of the macro BICOMC\_OVER\_METHOD are the names and signatures of the overridden methods. **Figure 11** shows C++ code converted from **Figure 10** by C++ preprocessor. The macro BICOMC\_OVERRIDE is converted to bool overrideMethod(), and parameters of the macro such as Interface\_1 and Interface\_3 are used for clear conversion of overridden methods related to the type of the interface. The BICOMC\_OVER\_METHOD macros on lines 3–7 in **Figure 10** are converted to codes on lines 6–11 in **Figure 11** and the macro BiCOMC\_OVERRIDE\_INIT() to holder(overrideMethod()) on the 16th line in **Figure 11**.
