Skip to content

Commit

Permalink
VarList v1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
James Dunkerley committed Dec 24, 2018
1 parent 75ae5c0 commit 2403337
Show file tree
Hide file tree
Showing 10 changed files with 1,130 additions and 18 deletions.
Binary file modified AlteryxAbacus.dll
Binary file not shown.
Binary file modified AlteryxAbacus/AlteryxAbacus.aps
Binary file not shown.
278 changes: 268 additions & 10 deletions AlteryxAbacus/AlteryxAbacus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
#include "AlteryxAbacus.h"
#include "AlteryxAbacusUtils.h"
#include <string>
#include <deque>
#include <map>
#include <sstream>
#include <ostream>
#include <fstream>

static std::map<std::wstring, std::wstring> stringLookup;
static std::map<std::wstring, double> doubleLookup;
static std::map<std::wstring, std::deque<double>> listLookup;

extern "C" long _declspec(dllexport) _stdcall VarTextExists(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 1 || nNumArgs > 2 || pArgs[0].nVarType == 1)
{
return AlteryxAbacusUtils::ReturnError(L"Variable: Requires a string key argument.", pReturnValue, nNumArgs, pArgs);
return AlteryxAbacusUtils::ReturnError(L"VarTextExists: Syntax error - key:string argument.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
Expand All @@ -38,7 +40,7 @@ extern "C" long _declspec(dllexport) _stdcall VarNumExists(int nNumArgs, Formula
{
if (nNumArgs < 1 || nNumArgs > 2 || pArgs[0].nVarType == 1)
{
return AlteryxAbacusUtils::ReturnError(L"Variable: Requires a string key argument.", pReturnValue, nNumArgs, pArgs);
return AlteryxAbacusUtils::ReturnError(L"VarNumExists: Syntax error - key:string argument.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
Expand All @@ -57,11 +59,34 @@ extern "C" long _declspec(dllexport) _stdcall VarNumExists(int nNumArgs, Formula
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListExists(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 1 || nNumArgs > 2 || pArgs[0].nVarType == 1)
{
return AlteryxAbacusUtils::ReturnError(L"VarListExists: Syntax error - key:string argument.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
if (pArgs[0].isNull)
{
pReturnValue->isNull = true;
}
else
{
const std::wstring key(pArgs[0].pVal);
pReturnValue->isNull = false;
const auto listFind = listLookup.find(key);
pReturnValue->dVal = listFind != listLookup.end();
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarText(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 1 || pArgs[0].nVarType == 1 || (nNumArgs > 1 && pArgs[1].nVarType != 2) || (nNumArgs > 2 && pArgs[2].nVarType != 1) || nNumArgs > 3)
{
return AlteryxAbacusUtils::ReturnError(L"Variable: [key:string] <value:string> <setIfTrue:boolean = true> arguments.", pReturnValue, nNumArgs, pArgs);
return AlteryxAbacusUtils::ReturnError(L"VarText: Syntax error - key:string [value:string] [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 2;
Expand Down Expand Up @@ -104,7 +129,7 @@ extern "C" long _declspec(dllexport) _stdcall VarNum(int nNumArgs, FormulaAddInD
{
if (nNumArgs < 1 || pArgs[0].nVarType == 1 || (nNumArgs > 1 && pArgs[1].nVarType != 1) || (nNumArgs > 2 && pArgs[2].nVarType != 1) || nNumArgs > 3)
{
return AlteryxAbacusUtils::ReturnError(L"Variable: [key:string] <value:number> <setIfTrue:boolean = true> arguments.", pReturnValue, nNumArgs, pArgs);
return AlteryxAbacusUtils::ReturnError(L"VarNum: Syntax error - key:string [value:number] [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
Expand Down Expand Up @@ -142,6 +167,216 @@ extern "C" long _declspec(dllexport) _stdcall VarNum(int nNumArgs, FormulaAddInD
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListLength(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 1 || nNumArgs > 2 || pArgs[0].nVarType != 2)
{
return AlteryxAbacusUtils::ReturnError(L"VarListLength: Syntax error - key:string argument.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;
if (!pArgs[0].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
pReturnValue->isNull = false;
pReturnValue->dVal = listFind->second.size();
}
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListGet(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs != 2 || pArgs[0].nVarType != 2 || pArgs[1].nVarType != 1)
{
return AlteryxAbacusUtils::ReturnError(L"VarListGet: Syntax error - key:string index:integer arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;
if (!pArgs[0].isNull && !pArgs[1].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
const auto size = listFind->second.size();
const unsigned int index = pArgs[1].dVal < 0 ? size + pArgs[1].dVal : pArgs[1].dVal;
if (index >= 0 && index < size)
{
pReturnValue->isNull = false;
pReturnValue->dVal = listFind->second[index];
}
}
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListAdd(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 2 || nNumArgs > 3 || pArgs[0].nVarType != 2 || pArgs[1].nVarType != 1 || (nNumArgs > 2 && pArgs[2].nVarType != 1))
{
return AlteryxAbacusUtils::ReturnError(L"VarListAdd: Syntax error - key:string [value:number] [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;

if (nNumArgs == 3 && !pArgs[2].isNull && pArgs[2].dVal == 0)
{
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

if (!pArgs[0].isNull && !pArgs[1].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
listFind->second.push_back(pArgs[1].dVal);
}
else
{
const std::deque<double> vector({ pArgs[1].dVal });
listLookup[key] = vector;
}

pReturnValue->isNull = false;
pReturnValue->dVal = pArgs[1].dVal;
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListSet(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 3 || nNumArgs > 4 || pArgs[0].nVarType != 2 || pArgs[1].nVarType != 1 || pArgs[2].nVarType != 1 || (nNumArgs == 4 && pArgs[3].nVarType != 1))
{
return AlteryxAbacusUtils::ReturnError(L"VarListSet: Syntax error - key:string index:integer value:number [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;

if (nNumArgs == 4 && !pArgs[3].isNull && pArgs[3].dVal == 0)
{
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

if (!pArgs[0].isNull && !pArgs[1].isNull && !pArgs[2].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
const auto size = listFind->second.size();
const unsigned int index = pArgs[1].dVal < 0 ? size + pArgs[1].dVal : pArgs[1].dVal;
if (index < 0 || index >= size)
{
return AlteryxAbacusUtils::ReturnError(L"Cannot set as index out of range", pReturnValue, nNumArgs, pArgs);
}
listFind->second[index] = pArgs[2].dVal;
}
else
{
return AlteryxAbacusUtils::ReturnError(L"Cannot set as index out of range", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->isNull = false;
pReturnValue->dVal = pArgs[2].dVal;
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListInsert(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 3 || nNumArgs > 4 || pArgs[0].nVarType != 2 || pArgs[1].nVarType != 1 || pArgs[2].nVarType != 1 || (nNumArgs == 4 && pArgs[3].nVarType != 1))
{
return AlteryxAbacusUtils::ReturnError(L"VarListInsert: Syntax error - key:string index:integer value:number [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;

if (nNumArgs == 4 && !pArgs[3].isNull && pArgs[3].dVal == 0)
{
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

if (!pArgs[0].isNull && !pArgs[1].isNull && !pArgs[2].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
const auto size = listFind->second.size();
const unsigned int index = pArgs[1].dVal < 0 ? size + pArgs[1].dVal : pArgs[1].dVal;
if (index < 0 || index > size)
{
return AlteryxAbacusUtils::ReturnError(L"Cannot insert as index out of range", pReturnValue, nNumArgs, pArgs);
}
listFind->second.insert(listFind->second.begin() + index, pArgs[2].dVal);
}
else
{
if (pArgs[1].dVal != 0)
{
return AlteryxAbacusUtils::ReturnError(L"Cannot insert as index out of range", pReturnValue, nNumArgs, pArgs);
}
const std::deque<double> vector({ pArgs[2].dVal });
listLookup[key] = vector;
}

pReturnValue->isNull = false;
pReturnValue->dVal = pArgs[2].dVal;
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarListRemove(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs < 2 || nNumArgs > 3 || pArgs[0].nVarType != 2 || pArgs[1].nVarType != 1 || (nNumArgs == 3 && pArgs[2].nVarType != 1))
{
return AlteryxAbacusUtils::ReturnError(L"VarListRemove: Syntax error - key:string index:integer [setIfTrue:boolean = true] arguments.", pReturnValue, nNumArgs, pArgs);
}

pReturnValue->nVarType = 1;
pReturnValue->isNull = true;

if (nNumArgs == 3 && !pArgs[2].isNull && pArgs[2].dVal == 0)
{
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

if (!pArgs[0].isNull && !pArgs[1].isNull)
{
const std::wstring key(pArgs[0].pVal);
const auto listFind = listLookup.find(key);
if (listFind != listLookup.end())
{
const auto size = listFind->second.size();
const unsigned int index = pArgs[1].dVal < 0 ? size + pArgs[1].dVal : pArgs[1].dVal;
if (index >= 0 && index < size)
{
const auto it = listFind->second.begin() + index;
pReturnValue->isNull = false;
pReturnValue->dVal = *it;
listFind->second.erase(it);
}
}
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarReset(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
if (nNumArgs > 1 || (nNumArgs == 1 && pArgs[0].nVarType == 1))
Expand All @@ -158,24 +393,26 @@ extern "C" long _declspec(dllexport) _stdcall VarReset(int nNumArgs, FormulaAddI
const std::wstring key(pArgs[0].pVal);
doubleLookup.erase(key);
stringLookup.erase(key);
listLookup.erase(key);
}
}
else {
stringLookup.clear();
doubleLookup.clear();
listLookup.clear();
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long _declspec(dllexport) _stdcall VarList(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
extern "C" long _declspec(dllexport) _stdcall VarPrint(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
pReturnValue->nVarType = 2;
pReturnValue->isNull = false;

std::wstringstream buffer;

for (const auto pair : stringLookup )
for (const auto& pair : stringLookup )
{
buffer << "text\t";
buffer << pair.first;
Expand All @@ -184,7 +421,7 @@ extern "C" long _declspec(dllexport) _stdcall VarList(int nNumArgs, FormulaAddIn
buffer << "\n";
}

for (const auto pair : doubleLookup)
for (const auto& pair : doubleLookup)
{
buffer << "text\t";
buffer << pair.first;
Expand All @@ -193,6 +430,25 @@ extern "C" long _declspec(dllexport) _stdcall VarList(int nNumArgs, FormulaAddIn
buffer << "\n";
}

for (const auto& pair : listLookup)
{
buffer << "text\t";
buffer << pair.first;
buffer << "\t";

bool first = true;
for (const auto value : pair.second)
{
if (!first)
{
buffer << ",";
}
buffer << value;
first = false;
}
buffer << "\n";
}

AlteryxAbacusUtils::SetString(pReturnValue, buffer.str().c_str());
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}
Expand Down Expand Up @@ -420,10 +676,12 @@ extern "C" long _declspec(dllexport) _stdcall RangeJoin(int nNumArgs, FormulaAdd
const auto target = static_cast<long long>(pArgs[0].dVal);

// Read String
const wchar_t* start = pArgs[1].pVal - 1;
int done_one = 0;
const wchar_t* start = pArgs[1].pVal;
while (*start != L'\0') {
wchar_t* end;
const auto value = _wcstoi64(start + 1, &end, 10);
const auto value = _wcstoi64(start + done_one, &end, 10);
done_one = 1;

start = end;
if (value > target)
Expand Down
Loading

0 comments on commit 2403337

Please sign in to comment.