Add static constructor

This commit is contained in:
Viktor Andreev
2024-06-28 20:51:59 +06:00
parent e4e35ab579
commit d2724ac712
2 changed files with 23 additions and 13 deletions

View File

@ -35,15 +35,6 @@
namespace XLS namespace XLS
{ {
std::map<std::wstring, std::vector<bool>> FutureFunctionArgs =
{
{
L"_xlfn.DAYS",{0,1,1}
},
{
L"_xlfn.NETWORKDAYS.INTL",{0, 0, 0, 1, 0}
}
};
const bool FutureFunctionParser::GetFutureFunction(std::wstring& functionName) const bool FutureFunctionParser::GetFutureFunction(std::wstring& functionName)
{ {
@ -52,7 +43,8 @@ namespace XLS
{ {
tempName = L"_xlfn." + tempName; tempName = L"_xlfn." + tempName;
} }
if(FutureFunctionArgs.find(tempName) != FutureFunctionArgs.end()) auto functions = init();
if(functions.FutureFunctions.find(tempName) != functions.FutureFunctions.end())
{ {
functionName = tempName; functionName = tempName;
return true; return true;
@ -63,12 +55,25 @@ namespace XLS
std::vector<bool> FutureFunctionParser::GetArgumentList( const std::wstring& functionName) std::vector<bool> FutureFunctionParser::GetArgumentList( const std::wstring& functionName)
{ {
std::vector<bool> argVector; std::vector<bool> argVector;
auto findedFunc = FutureFunctionArgs.find(functionName); auto functions = init();
if(findedFunc != FutureFunctionArgs.end()) auto findedFunc = functions.FutureFunctions.find(functionName);
if(findedFunc != functions.FutureFunctions.end())
{ {
argVector = findedFunc->second; argVector = findedFunc->second;
} }
return argVector; return argVector;
} }
} // namespace XLS FutureFunctionParser& FutureFunctionParser::init()
{
static FutureFunctionParser parser;
return parser;
}
FutureFunctionParser::FutureFunctionParser()
{
FutureFunctions.emplace (L"_xlfn.DAYS", std::vector<bool>{0,1,1});
FutureFunctions.emplace(L"_xlfn.NETWORKDAYS.INTL",std::vector<bool>{0, 0, 0, 1, 0});
}
} // namespace XLS

View File

@ -45,6 +45,11 @@ public:
static const bool GetFutureFunction(std::wstring& functionName); static const bool GetFutureFunction(std::wstring& functionName);
static std::vector<bool> GetArgumentList( const std::wstring& functionName); static std::vector<bool> GetArgumentList( const std::wstring& functionName);
private:
FutureFunctionParser();
static FutureFunctionParser& init();
std::map<std::wstring, std::vector<bool>> FutureFunctions;
}; };