Please enable JavaScript to view this site.

Altova MapForce 2020 Enterprise Edition

This example shows you how to create a sample C++ library and adapt it to a MapForce Function File (.mff) that can be imported as a MapForce library.

 

1.Create a header (.h) file for your class library. The following code listing illustrates a sample header file called Greetings.h.

 

#ifndef MYLIBRARY_GREETINGS_H_INCLUDED
#define MYLIBRARY_GREETINGS_H_INCLUDED
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
using namespace altova;
 
namespace mylib {
 
class ALTOVA_DECLSPECIFIER Greetings
{
  public:
  static string_type SayHello(bool isMorning);
};
 
} // namespace mylib
 
#endif // MYLIBRARY_GREETINGS_H_INCLUDED

 

Notice that the function has been declared as static, and that the namespace altova is imported. Remember to write ALTOVA_DECLSPECIFIER in front of the class name, this ensures that your classes will compile correctly—whether you use dynamic or static linkage in subsequently generated code.

 

2.Create a .cpp file with the same name as the header file. The .cpp file must be in the same directory as the .h file. The following code listing illustrates a sample .cpp file called Greetings.cpp that includes the Greetings.h file created previously:

 

#include "StdAfx.h"
#include "../Altova/Altova.h"
#include "../Altova/AltovaException.h"
#include "../Altova/SchemaTypes.h"
 
#include "Greetings.h"
 
namespace mylib {
 
  string_type Greetings::SayHello(bool isMorning)
  {
    if( isMorning )        
        return _T("Good morning!");
    return _T("Good day!");
  }
}

 

Notice the lines that import the StdAfx.h and several Altova libraries. These lines must be left unchanged. The paths to the Altova libraries is correct; in the generated code, these paths will point to the respective files.

 

In contrast to Java or C#, you do not need to compile your source C++ files. They will be copied to the generated code, and are compiled with the rest of the generated mapping code.

 

3.Using an XML editor, create a new .mff file and validate it against the ..\Program Files\MapForceLibraries\mff.xsd schema. Make sure that the namespace and function names and data types defined here correspond to those in the C++ code, as described in Configuring the .mff File. For information about data type support, see Data Type Mapping.

 

<?xml version="1.0" encoding="UTF-8"?>
<mapping version="9" library="mylib" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mff.xsd">
  <implementations>
    <implementation language="cpp">
        <setting name="namespace" value="mylib"/>
        <setting name="class" value="Greetings"/>
        <setting name="path" value="C:\Libraries\cpp"/>
        <setting name="include" value="Greetings.h"/>
        <setting name="source" value="Greetings.cpp"/>
    </implementation>
  </implementations>
  <group name="greetings">
    <component name="sayhello">
        <sources>
          <datapoint name="ismorning" type="xs:boolean"/>
        </sources>
        <targets>
          <datapoint name="result" type="xs:string"/>
        </targets>
        <implementations>
          <implementation language="cpp">
              <function name="SayHello"/>
          </implementation>
        </implementations>
        <description>
          <short>result = sayhello(ismorning)</short>
          <long>Returns "Good morning" or "Good day", depending on the input parameter.</long>
        </description>
    </component>
  </group>
</mapping>

 

You have now finished creating a custom library and the .mff file which adapts it to MapForce. The custom .mff file can now be imported as a library into MapForce, see Importing .mff Libraries. Remember that, in order to execute mappings that use native C++ libraries, you will need to generate C++ code and run the mapping from your C++ code or application, as described in Generating C++ code.

 

Resolving C++ compile errors

If you get a compiler error at the following line:

 

 #import "msado15.dll" rename("EOF", "EndOfFile")

 

modify the project properties to include a reference to the msado15.dll file (usually, C:\Program Files\Common Files\System\ADO).

© 2020 Altova GmbH