#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <numeric>
#include <stdexcept>
#include <stdlib.h>
#include "../../include/example_utils.h"
#include "../../include/pgslic.h"
using namespace std;
using namespace nuvovis;
namespace
{
const char* PWD = "---Replace with your Developer Key---";
const char* LICS_DIR = ".";
const string CONFIG_FILENAME = "RomanNumerals.ini";
const string APP_NAME = "RomanNumerals";
bool licenseOK()
{
switch (
checkLicense(LICS_DIR, PWD, readTextFileUntilSpace(CONFIG_FILENAME).c_str(), APP_NAME.c_str()))
{
break;
return false;
return false;
{
const int NUM_SECONDS_IN_48_HOURS = 60 * 60 * 48;
if (numSecondsStale < NUM_SECONDS_IN_48_HOURS)
{
cout << "Warning: License has been stale for " << numSecondsStale << " seconds" << endl;
}
else
{
cerr << "License has been stale for more than two days" << endl;
return false;
}
}
break;
default:
throw runtime_error("Unexpected license status");
}
if (daysUntilExpiry <= 10 && daysUntilExpiry > 0)
cout << "Warning: Only " << daysUntilExpiry << " day(s) until license expires! Contact sales@myplace.com" << endl;
return true;
}
template<class T> T parseStr(const string& str)
{
stringstream ss(str);
T x;
ss >> x;
if (!ss)
throw runtime_error(string(string("Failed to convert ") + str).c_str());
return x;
}
typedef pair<int,string> NumeralPair;
NumeralPair RN(NumeralPair number, const NumeralPair& value)
{
while (number.first >= value.first)
{
number.second += value.second;
number.first -= value.first;
}
return number;
}
}
int main(int argc, char* argv[])
{
try
{
if (argc != 2 && argc != 3)
{
cout <<
"Usage: RomanNumeralsCmd Number\n"
" Outputs the decimal number as Roman numerals\n"
"\n"
" RomanNumeralsCmd -info\n"
" View application version and license settings\n";
return 1;
}
else if (!licenseOK())
{
cout << "License activation required" << endl;
return 1;
}
else if (string(argv[1]) == string("-info"))
{
{
cout << "License never expires" << endl;
}
else
{
}
cout <<
"Maximum number = " <<
getSetting(
"MaxLimit") << endl;
}
else
{
int number = parseStr<int>(argv[1]);
int maxLimit = parseStr<int>(
getSetting(
"MaxLimit"));
if (number > maxLimit)
throw runtime_error(
string(
string(
"You are only licensed for numbers up to ") +
getSetting(
"MaxLimit")).c_str());
vector<NumeralPair> numeralPairs;
numeralPairs.push_back(NumeralPair(1000, "M"));
numeralPairs.push_back(NumeralPair(500, "D"));
numeralPairs.push_back(NumeralPair(100, "C"));
numeralPairs.push_back(NumeralPair(90, "XC"));
numeralPairs.push_back(NumeralPair(50, "L"));
numeralPairs.push_back(NumeralPair(40, "XL"));
numeralPairs.push_back(NumeralPair(10, "X"));
numeralPairs.push_back(NumeralPair(9, "IX"));
numeralPairs.push_back(NumeralPair(5, "V"));
numeralPairs.push_back(NumeralPair(4, "IV"));
numeralPairs.push_back(NumeralPair(1, "I"));
NumeralPair np = accumulate(numeralPairs.begin(), numeralPairs.end(), NumeralPair(number, ""), RN);
cout << np.second << endl;
}
}
catch (exception& e)
{
cout << "*** Error: " << e.what() << endl;
return 1;
}
return 0;
}
PGSLIC_API const char * getSetting(const char *settingName)
PGSLIC_API int isPerpetual()
PGSLIC_API const char * getExpiryDate()
PGSLIC_API const char * getAppName()
PGSLIC_API int getDaysUntilExpiry()
@ LICENSE_STALE
Definition: pgslic.h:96
@ LICENSE_EXPIRED
Definition: pgslic.h:96
@ LICENSE_OK
Definition: pgslic.h:96
@ LICENSE_ERROR
Definition: pgslic.h:96
PGSLIC_API const char * getClientName()
PGSLIC_API const char * getSettings()
PGSLIC_API int getStaleTime()
PGSLIC_API const char * getLastError()
PGSLIC_API LicenseStatus checkLicense(const char *licPath, const char *pwd, const char *key, const char *appName, const char *appInfo="", const char *cxnOpts="")