Database Conversion
Detailed Description
This is an example of how to convert an ASCII database into the WinProp binary format. The full example is distributed with the installation.#include <stdio.h> #include <string> #include <iostream> #include "convert_database.h" #ifndef API_DATA_FOLDER #define API_DATA_FOLDER "../../api/winprop/data/" #endif // !API_DATA_FOLDER int main(int argc, char** argv) { /* Define callback functions. */ WinProp_Callback Callback; WinProp_Structure_Init_Callback(&Callback); Callback.Percentage = CallbackProgress; Callback.Message = CallbackMessage; Callback.Error = CallbackError; /* Set correct parameters for conversion. */ WinProp_Converter WinPropConverter; WinProp_Structure_Init_Converter(&WinPropConverter); WinPropConverter.databaseNameSource = API_DATA_FOLDER "outdoor/City.oda"; // with file extension WinPropConverter.databaseNameDest = API_DATA_FOLDER "outdoor/City_odb"; WinPropConverter.measurementUnit = "Meter"; WinPropConverter.ConverterID = 201; // convert oda to odb WinPropConverter.SaveAsciiFormat = 0; // Save output database in binary format // Start conversion of data now: my_oda_Database.oda will be converted and saved as // output_Database_Path/my_oda_Database.odb. if (WinProp_Convert(&WinPropConverter, &Callback) != 0) std::cout << "Error during conversion" << std::endl; return 0; } int _STD_CALL CallbackMessage(const char * Text) { if (Text == nullptr) return 0; std::cout << "\n" << Text; return(0); } int _STD_CALL CallbackError(const char * Text, int Error) { if (Text == nullptr) return 0; std::cout << "\n"; #ifdef __LINUX std::cout << "\033[31m" << "Error (" << Error << "): "; // highlight error in red color #else HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, FOREGROUND_RED); std::cout << "Error (" << Error << "): "; #endif // __LINUX std::cout << Text; #ifdef __LINUX std::cout << "\033[0m"; // highlight error in red color #else SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); #endif // __LINUX return 0; } int _STD_CALL CallbackProgress(int value, const char* text) { char Line[200]; sprintf(Line, "\n%d%% %s", value, text); std::cout << Line; return(0); }