map/das-dn/third_party/AdsLib/Beckhoff/StringToInteger.h
2024-12-09 09:41:04 +08:00

23 lines
383 B
C++

// SPDX-License-Identifier: MIT
/**
Copyright (C) 2023 Beckhoff Automation GmbH & Co. KG
*/
#pragma once
#include <string>
namespace Beckhoff
{
template<class T>
static T try_stoi(const char* str, const T defaultValue = 0)
{
try {
if (str && *str) {
return static_cast<T>(std::stoi(++str));
}
} catch (...) {}
return defaultValue;
}
}