Issue #218: Used refenrces instead of pointers in C++ functions

This commit is contained in:
Viacheslav Demydiuk
2020-11-01 15:59:11 +02:00
parent f6659ed91d
commit 1a1b0cd822
2 changed files with 31 additions and 25 deletions
+24 -23
View File
@@ -58,6 +58,7 @@ template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default
catch (Exception^ e)
{
convertSystemString(err, e->Message);
MtAdapter::GetInstance()->LogError(e->Message);
}
return result;
}
@@ -220,26 +221,26 @@ _DLLAPI int _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* mess
//----------- get values -------------------------------
_DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
_DLLAPI int _stdcall getCommandType(int expertHandle, int& res, wchar_t* err)
{
return Execute<int>([&expertHandle, res]() {
*res = MtAdapter::GetInstance()->GetCommandType(expertHandle);
return Execute<int>([&expertHandle, &res]() {
res = MtAdapter::GetInstance()->GetCommandType(expertHandle);
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getIntValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
_DLLAPI int _stdcall getIntValue(int expertHandle, int paramIndex, int& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return Execute<int>([&expertHandle, &paramIndex, &res]() {
res = MtAdapter::GetInstance()->GetCommandParameter<int>(expertHandle, paramIndex);
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res, wchar_t* err)
_DLLAPI int _stdcall getDoubleValue(int expertHandle, int paramIndex, double& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return Execute<int>([&expertHandle, &paramIndex, &res]() {
res = MtAdapter::GetInstance()->GetCommandParameter<double>(expertHandle, paramIndex);
return 1;
}, err, 0);
}
@@ -247,40 +248,40 @@ _DLLAPI int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* re
_DLLAPI int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
convertSystemString(res, MtAdapter::GetInstance()->GetCommandParameter<String^>(expertHandle, paramIndex));
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* res, wchar_t* err)
_DLLAPI int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (unsigned __int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return Execute<int>([&expertHandle, &paramIndex, &res]() {
res = MtAdapter::GetInstance()->GetCommandParameter<unsigned __int64>(expertHandle, paramIndex);
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res, wchar_t* err)
_DLLAPI int _stdcall getLongValue(int expertHandle, int paramIndex, __int64& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (__int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return Execute<int>([&expertHandle, &paramIndex, &res]() {
res = MtAdapter::GetInstance()->GetCommandParameter<__int64>(expertHandle, paramIndex);
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
_DLLAPI int _stdcall getBooleanValue(int expertHandle, int paramIndex, int& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
bool val = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = val == true ? 1 : 0;
return Execute<int>([&expertHandle, &paramIndex, &res]() {
bool val = MtAdapter::GetInstance()->GetCommandParameter<bool>(expertHandle, paramIndex);
res = val == true ? 1 : 0;
return 1;
}, err, 0);
}
_DLLAPI int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res, wchar_t* err)
_DLLAPI int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int& res, wchar_t* err)
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (unsigned int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return Execute<int>([&expertHandle, &paramIndex, &res]() {
res = MtAdapter::GetInstance()->GetCommandParameter<unsigned int>(expertHandle, paramIndex);
return 1;
}, err, 0);
}
+7 -2
View File
@@ -185,7 +185,7 @@ namespace MTApiService
return retval;
}
public object GetCommandParameter(int expertHandle, int index)
public T GetCommandParameter<T>(int expertHandle, int index)
{
Log.DebugFormat("GetCommandParameter: begin. expertHandle = {0}, index = {1}", expertHandle, index);
@@ -204,7 +204,7 @@ namespace MTApiService
Log.DebugFormat("GetCommandParameter: end. retval = {0}", retval);
return retval;
return (T)retval;
}
public object GetNamedParameter(int expertHandle, string name)
@@ -250,6 +250,11 @@ namespace MTApiService
return retval;
}
public void LogError(string message)
{
Log.Error(message);
}
#endregion
#region Private Methods