**4. Examples of BiCOMC-based application**

#### **4.1 A simple example**

This section describes in sequence how to make a file copy application, which is a simple example based on BiCOMC. The file copy application is designed to run on Windows and Linux and is built using MSVC and GCC, respectively. The dynamic library providing the file copy function, which named utility, is created, and the executable file using this dynamic library, which named app, is generated as the application. The interface is first defined to share an object that provides a method for *How to Keep the Binary Compatibility of C++ Based Objects DOI: http://dx.doi.org/10.5772/intechopen.77383*

copying files. The interface to provide this functionality is defined in the utility.h file as the ICopy interface. **Figure 12** shows that the ICopy interface is defined based on the macro of BiCOMC and is the source code of the dynamic library named *utility.cpp*.

The BiCOMC macro is defined in *object.h*, which is added as shown on line 5 in **Figure 12** to use it. *ICopy* has a *copy()* method that receives two file names of *src* and *dst* as the input parameters and copies *src* to *dst*, which is shown on the eighth line in **Figure 12**.

In order to implement the *ICopy* interface in **Figure 12**, the *Copy* class is written made as shown in the *utility.cpp* of **Figure 13**. In addition, *copy()* method of *ICopy* is overridden in **Figure 13**. Note that the *utility.cpp* file is the source code for the *utility* dynamic library.

The *utility.h* which defines the *ICopy* interface is added as one of the header files on the second line in **Figure 13**, and some header files for the *Copy* class implementation on lines 4–13 are defined for Windows and Linux. The *Copy* class inherits the *ICopy* interface on the 15th line, and the overriding methods are explicitly specified using the BiCOMC macro on lines 16–19, where the specified methods are written on lines 23–37. The *create()* function on lines 40–46 creates an instance of the *Copy* class in order to pass its instance outside of the dynamic library called *utility*. The *main()* function of *app* using *utility* dynamic library is written in the *app.cpp* file, which is illustrated in **Figure 14**.

The *create()* function is called on the 21th line in **Figure 14** to get an instance of the *Copy* class in **Figure 13** but casted to *ICopy\** using *bicomc\_cast()* since *create()* returns *Object\**. The *copy()* method is called to perform file copy on the 24th line. This method is used in try-catch because it generates an exception when *copy()* fails. The commands shown in **Figure 15** are executed to build *utility.cpp* into *utility* dynamic library and *app.cpp* into *app* executable file, respectively.

## **4.2 BiCOMC-based component for robot application**

This section explains how to implement BiCOMC-based components using a robot applications. The robot application consists of three components in a Windows environment as follows: the *ManipulatorComp*, the *MobileComp*, and the *AppComp* in **Figure 16**.

The component *ManipulatorComp* is compiled with GCC 5.2 and controls the manipulator. The component *MobileComp* is compiled with MSVC 14 and controls the mobile platform. The component *AppComp* is compiled with MSVC 10 and coordinates the components *MobileComp* and *ManipulatorComp*. The component *AppComp* accesses the components *MobileComp* and *ManipulatorComp* through the interfaces *IMobile* and *IManipulator*, respectively. Definitions of these interfaces are illustrated in **Figure 17**. **Figure 18** shows the definition of the component *MobileComp* that inherits the interface *IMobile* and overrides the methods of the

**Figure 12.** *C++ code of utility.h.*
