Summary: How to use an existing C++ class and write it to the space.
Overview This example shows you how to write your own C++ class to the space (as opposed to writing a class that is generated from a XML file). The code for this example is located at <GigaSpaces Root>\cpp\examples\PocoFromExistingClass. This path will be referred to as <Example Root> in this page. This example can be built and run on Windows OS only. If you use Visual Studio open the solution PocoFromExistingClass.sln located in <GigaSpaces Root>\cpp\examples\PocoFromExistingClass. It is recommended to set your solution configuration to Release and do a rebuild that will generate all related files. It is assumed that you have read the CPP API Hello World Example example which serves as a starting point. To write your C++ class to the space, perform the following steps:
- Create a gs.xml file that contains the class definition. For example, this is the file <Example Root>\PocoFromExistingClass.gs.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gigaspaces-mapping SYSTEM "../../config/cpp.dtd">
<gigaspaces-mapping>
<include-header file="UserMessage.h"/>
<class name="UserMessage" persist="false" replicate="false" fifo="false" >
<property name="id" type="int" null-value="-999" index="true"/>
<routing name="id"/>
<property name="uid" type="string" null-value="" index="false"/>
<id name="uid" auto-generate="true" />
<property name="content" type="string" null-value="" index="false"/>
</class>
</gigaspaces-mapping>
Note the line that informs gsxml2cpp about the file of your existing class:
<include-header file="UserMessage.h"/>
- Change the user class.
An example of an original class can be found at <Example Root>\UserMessage_original.h.txt; and an example of the same class with the changes listed below can be found at <Example Root>\UserMessage.h.
- Handle the C++ serializer code generation, build the shared library (DLL) from this code, and place the library in the appropiate directory (<GigaSpaces Root>\lib\serviceGrid\native).
The following instructions show you how to do this in Visual Studio using the supplied makefile (<Example Root>/makefileSerializer.mk):
- Rebuild the example.
 |
Compiling the file PocoFromExistingClass.gs.xml causes the following:
- The file UserMessageSerializer.cpp is automatically generated in <Example Root>.
- The DLL UserMessageSerializer.dll is created and placed in <GigaSpaces Root>\lib\ServiceGrid\native.
|
- Run the example. The output should be as follows:

|