Skip to content

Commit

Permalink
[CLI][WASimClient] Add getVariable() overloads for returning string…
Browse files Browse the repository at this point in the history
… type values; Move var request handling to common private handlers.
  • Loading branch information
mpaperno committed Nov 1, 2023
1 parent 8e75eb8 commit 0e54794
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
44 changes: 41 additions & 3 deletions src/WASimClient_CLI/WASimClient_CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ ref class WASimClient::Private
return (HR)hr;
}

inline HR getVariable(VariableRequest ^var, interior_ptr<double> pfResult, interior_ptr<String ^> psResult)
{
pin_ptr<double> pf = pfResult;
std::string s { };
HR ret = (HR)client->getVariable(var, pf, psResult ? &s : nullptr);
if (psResult)
*psResult = marshal_as<String ^>(s);
return ret;
}

inline HR getOrCreateLocalVariable(String ^ name, interior_ptr<String ^> unit, double defaultValue, interior_ptr<double> pfResult)
{
pin_ptr<double> pf = pfResult;
if (unit)
return (HR)client->getOrCreateLocalVariable(marshal_as<std::string>(name), pf, defaultValue, marshal_as<std::string>((String ^)*unit));
return (HR)client->getOrCreateLocalVariable(marshal_as<std::string>(name), pf, defaultValue);
}

~Private()
{
if (client) {
Expand Down Expand Up @@ -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<DataRequestRecord^>^ WASimClient::dataRequests()
{
const std::vector<WASimCommander::Client::DataRequestRecord> &res = m_client->dataRequests();
Expand Down
25 changes: 12 additions & 13 deletions src/WASimClient_CLI/WASimClient_CLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,24 @@ namespace WASimCommander::CLI::Client

// Variables accessors ------------------------------

/// See \refwccc{getVariable()}
HR getVariable(VariableRequest ^var, [Out] double %pfResult) {
pin_ptr<double> pf = &pfResult;
return (HR)m_client->getVariable(var, pf);
}
/// <summary> Get the value of a variable with a numeric result type. This is the most typical use case since most variable types are numeric. </summary> \sa \refwccc{getVariable()}
HR getVariable(VariableRequest ^var, [Out] double %pfResult);
/// <summary> 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. </summary>
/// 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);
/// <summary> Get the value of a variable with _either_ a numeric or string result based on the unit type of the requested variable. </summary>
/// 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<double> pf = &pfResult;
return (HR)m_client->getOrCreateLocalVariable(marshal_as<std::string>(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<double> pf = &pfResult;
return (HR)m_client->getOrCreateLocalVariable(marshal_as<std::string>(variableName), pf, defaultValue, marshal_as<std::string>(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); }
Expand Down

0 comments on commit 0e54794

Please sign in to comment.