#include "optaddr.h"
#include <string.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
int i;
OptimaServer myServer;
OptimaContact myContact;
OptimaLicense myLicense;
const char* pcACR;
// Initialise objects
InitServer(&myServer);
InitContact(&myContact);
InitLicense(&myLicense);
// Connect to the server
AddHost(&myServer, "localhost");
if (!Connect(&myServer))
{
cout << "Error connecting to server: "
<< getLastError(&myServer)
<< endl;
return -1;
}
// Retrieve and view the license data
GetLicenseInfo(&myServer, &myLicense);
cout << "License information:"
<< endl;
cout << "\tUsername:\t"
<< getUserName(&myLicense)
<< endl;
cout << "\tCompany:\t"
<< getCompanyName(&myLicense)
<< endl;
cout << "\tLicense:\t"
<< getLicenseKey(&myLicense)
<< endl;
// Example of setting some options on the server using // SetOption and SetOptionMask:
// Output the address in upper case
SetOption(&myServer,
OONAddressCasing,
OCOUpperCase);
// Don't include items in output address lines
SetOptionMask(&myServer,
OONFormatComponents1,
OFTCity,
false);
SetOptionMask(&myServer,
OONFormatComponents1,
OFTCedex,
false);
SetOptionMask(&myServer,
OONFormatComponents1,
OFTRegion,
false);
SetOptionMask(&myServer,
OONFormatComponents1,
OFTPostcode,
false);
SetOptionMask(&myServer,
OONFormatComponents1,
OFTCountry,
false);
// Start the loop here for multiple contacts
{
// Create the sample contact data
setField(&myContact,
OFTAddressLine1,
"Optima Database Management Ltd");
setField(&myContact,
OFTAddressLine2,
"2 Concorde Drive");
setField(&myContact,
OFTAddressLine3,
setField(&myContact,
OFTAddressLine4,
"BS21 7RY");
setField(&myContact,
OFTCountryISO,
"GBR");
cout << "Input data:" << endl;
i = OFTAddressLine1;
while (strlen(getField(&myContact, i)) > 0)
cout << getField(&myContact, i++) << endl;
// Process the address
if (!ProcessAddress(&myServer,
&myContact,
-1 /*Acceptable Validation Level*/,
60 /*Inner Matchscore Threshold*/,
0 /*Outer Matchscore Threshold*/))
{
cout << "Error processing address: "
<< getLastError(&myServer)
<< endl;
return -1;
}
// Generate the matchkey
if (!GenerateMatchkey(&myServer, &myContact))
{
cout << "Error generating matchkey: "
<< getLastError(&myServer)
<< endl;
return -1;
}
// Check whether its processed OK
pcACR = getField(&myContact, OFTACR);
if (*pcACR == 'L')
{
// Output processed contact
cout << "Output processed contact in "
<< GetOCOText(&myServer,
GetOption(&myServer,
OONAddressCasing))
<< " with field names."
<< endl;
for (i = OFTRecordID;
i < OFTNumFieldsPlusOne;
i++)
{
if (strlen(getField(&myContact, i)) > 0)
cout << GetOFTText(&myServer, i)
<< " : "
<< getField(&myContact, i)
<< endl;
}
}
// End of loop for multiple contacts
}
// Disconnect from server
Disconnect(&myServer);
// Tidy up
DestroyServer(&myServer);
DestroyContact(&myContact);
DestroyLicense(&myLicense);
return 0;