License Expiry Date – C++ Sample
#include "lqtcr.h"
#include "stdio.h"
#include <iostream>
#include <vector>
#include<string>
#include<string.h>
using namespace std;
std::vector<std::string> split(std::string productstr,std::string sep){
char* cstr=const_cast<char*>(productstr.c_str());
char* temp;
std::vector<std::string> arr;
temp=strtok(cstr,sep.c_str());
while(temp!=NULL){
arr.push_back(temp);
temp=strtok(NULL,sep.c_str());
}
return arr;
}
int main(int argc, char* argv[])
{
try
{
// Create the objects
lqtServer* srv(lqtServer::create());
lqtProcessOptions* opts(lqtProcessOptions::create());
lqtInputRecord* rec(lqtInputRecord::create());
lqtProcessResult* res(lqtProcessResult::create());
lqtProcessList* lst(lqtProcessList::create());
// Initialize the objects
srv->init("./data");
lst->add("GKRInfo", opts);
printf("\n----------------------------\n");
// Loop around the records we want to process
{
// Load the input record
rec->clear();
// Process it
srv->process(rec, lst, res);
// get product codes
string productCodes;
for (size_t rec(0); rec < res->getCount(); rec++) {
for (long field(0); field < res->getFieldCount(rec); field++) {
const char* str = "DataProductList";
if (std::string(res->getFieldName(rec, field)) == std::string("DataProductList")) {
// print out
printf(res->getFieldName(rec, field));
printf(": ");
printf(res->getField(rec, field));
printf("\n");
productCodes = res->getField(rec, field);
}
}
}
if(!productCodes.empty()) {
printf("\n----------------------------");
printf("\n ***Expiry Dates*** \n");
printf("----------------------------\n");
//split product codes
std::vector<std::string> splitCodes;
splitCodes=split(productCodes,",");
// grab names and expiry dates from the Product Code
for (size_t rec(0); rec < res->getCount(); rec++) {
for (long field(0); field < res->getFieldCount(rec); field++) {
for(size_t codeCount(0); codeCount < splitCodes.size(); codeCount++) {
if ((std::string(res->getFieldName(rec, field)) == std::string(splitCodes[codeCount])) || (std::string(res->getFieldName(rec, field)) == std::string(splitCodes[codeCount]+".ExpiryDate"))) {
//print out
printf(res->getFieldName(rec, field));
printf(": ");
printf(res->getField(rec, field));
printf("\n");
}
}
}
}
} else {
printf("No Products found...");
printf(srv->getLastError());
}
}
// Tidy up
srv->shutdown();
lqtProcessOptions::destroy(opts);
lqtInputRecord::destroy(rec);
lqtProcessResult::destroy(res);
lqtProcessList::destroy(lst);
lqtServer::destroy(srv);
}
catch (exception& e)
{
printf("Exception thrown: %s\n", e.what());
}
return 0;
}