From 0e54794b2ec8411f42d34a7696426724ffc5e932 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Tue, 24 Oct 2023 00:00:57 -0400 Subject: [PATCH] [CLI][WASimClient] Add `getVariable()` overloads for returning string type values; Move var request handling to common private handlers. --- src/WASimClient_CLI/WASimClient_CLI.cpp | 44 +++++++++++++++++++++++-- src/WASimClient_CLI/WASimClient_CLI.h | 25 +++++++------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/WASimClient_CLI/WASimClient_CLI.cpp b/src/WASimClient_CLI/WASimClient_CLI.cpp index f234258..720e6f5 100644 --- a/src/WASimClient_CLI/WASimClient_CLI.cpp +++ b/src/WASimClient_CLI/WASimClient_CLI.cpp @@ -145,6 +145,24 @@ ref class WASimClient::Private return (HR)hr; } + inline HR getVariable(VariableRequest ^var, interior_ptr pfResult, interior_ptr psResult) + { + pin_ptr pf = pfResult; + std::string s { }; + HR ret = (HR)client->getVariable(var, pf, psResult ? &s : nullptr); + if (psResult) + *psResult = marshal_as(s); + return ret; + } + + inline HR getOrCreateLocalVariable(String ^ name, interior_ptr unit, double defaultValue, interior_ptr pfResult) + { + pin_ptr pf = pfResult; + if (unit) + return (HR)client->getOrCreateLocalVariable(marshal_as(name), pf, defaultValue, marshal_as((String ^)*unit)); + return (HR)client->getOrCreateLocalVariable(marshal_as(name), pf, defaultValue); + } + ~Private() { if (client) { @@ -197,18 +215,38 @@ WASimClient::!WASimClient() m_client = nullptr; } -inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, [Out] double % pfResult) { +inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, double %pfResult) { return d->executeCalculatorCode(code, resultType, &pfResult, nullptr); } -inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, [Out] String ^% psResult) { +inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, String^ %psResult) { return d->executeCalculatorCode(code, resultType, nullptr, &psResult); } -inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, [Out] double % pfResult, [Out] String ^% psResult) { +inline HR WASimClient::executeCalculatorCode(String ^ code, CalcResultType resultType, double %pfResult, String^ %psResult) { return d->executeCalculatorCode(code, resultType, &pfResult, &psResult); } +inline HR WASimClient::getVariable(VariableRequest ^ var, double %pfResult) { + return d->getVariable(var, &pfResult, nullptr); +} + +inline HR WASimClient::getVariable(VariableRequest ^ var, String^ %psResult) { + return d->getVariable(var, nullptr, &psResult); +} + +inline HR WASimClient::getVariable(VariableRequest ^ var, double %pfResult, String^ %psResult) { + return d->getVariable(var, &pfResult, &psResult); +} + +inline HR WASimClient::getOrCreateLocalVariable(String ^variableName, double defaultValue, double %pfResult) { + return d->getOrCreateLocalVariable(variableName, nullptr, defaultValue, &pfResult); +} + +inline HR WASimClient::getOrCreateLocalVariable(String ^variableName, String ^unitName, double defaultValue, double %pfResult) { + return d->getOrCreateLocalVariable(variableName, &unitName, defaultValue, &pfResult); +} + inline array^ WASimClient::dataRequests() { const std::vector &res = m_client->dataRequests(); diff --git a/src/WASimClient_CLI/WASimClient_CLI.h b/src/WASimClient_CLI/WASimClient_CLI.h index 8ccde9e..d7ccff8 100644 --- a/src/WASimClient_CLI/WASimClient_CLI.h +++ b/src/WASimClient_CLI/WASimClient_CLI.h @@ -164,25 +164,24 @@ namespace WASimCommander::CLI::Client // Variables accessors ------------------------------ - /// See \refwccc{getVariable()} - HR getVariable(VariableRequest ^var, [Out] double %pfResult) { - pin_ptr pf = &pfResult; - return (HR)m_client->getVariable(var, pf); - } + /// Get the value of a variable with a numeric result type. This is the most typical use case since most variable types are numeric. \sa \refwccc{getVariable()} + HR getVariable(VariableRequest ^var, [Out] double %pfResult); + /// Get the value of a variable with a string result type. The request is executed as calculator code since that is the only way to get string results. + /// Note that only some 'A', 'C', and 'T' type variables can have a string value type in the first place. \sa \refwccc{getVariable()} + HR getVariable(VariableRequest ^var, [Out] String^ %psResult); + /// Get the value of a variable with _either_ a numeric or string result based on the unit type of the requested variable. + /// The request is executed as calculator code since that is the only way to get string results. Unlike `executeCalculatorCode()`, this method will not return a string representation of a numeric value. + /// Note that only some 'A', 'C', and 'T' type variables can have a string value type in the first place. \sa \refwccc{getVariable()} + HR getVariable(VariableRequest ^var, [Out] double %pfResult, [Out] String^ %psResult); ///< See \refwccc{getVariable()} + /// See \refwccc{getLocalVariable()} HR getLocalVariable(String ^variableName, [Out] double %pfResult) { return getVariable(gcnew VariableRequest(variableName), pfResult); } /// See \refwccc{getLocalVariable()} HR getLocalVariable(String ^variableName, String ^unitName, [Out] double %pfResult) { return getVariable(gcnew VariableRequest(variableName, false, unitName), pfResult); } /// \sa \refwccc{getOrCreateLocalVariable()} - HR getOrCreateLocalVariable(String ^variableName, double defaultValue, [Out] double %pfResult) { - pin_ptr pf = &pfResult; - return (HR)m_client->getOrCreateLocalVariable(marshal_as(variableName), pf, defaultValue); - } + HR getOrCreateLocalVariable(String ^variableName, double defaultValue, [Out] double %pfResult); /// \sa \refwccc{getOrCreateLocalVariable()} - HR getOrCreateLocalVariable(String ^variableName, String ^unitName, double defaultValue, [Out] double %pfResult) { - pin_ptr pf = &pfResult; - return (HR)m_client->getOrCreateLocalVariable(marshal_as(variableName), pf, defaultValue, marshal_as(unitName)); - } + HR getOrCreateLocalVariable(String ^variableName, String ^unitName, double defaultValue, [Out] double %pfResult); /// See \refwccc{setVariable()} HR setVariable(VariableRequest ^var, const double value) { return (HR)m_client->setVariable(var, value); }