27#include <CArcBaseDllMain.h>
28#include <CArcStringList.h>
46 #define throwArcGen3Error( ... ) arc::gen3::CArcBase::throwException<std::runtime_error>( __FUNCTION__, __LINE__, __VA_ARGS__ )
48 #define throwArcGen3InvalidArgument( ... ) arc::gen3::CArcBase::throwException<std::invalid_argument>( __FUNCTION__, __LINE__, __VA_ARGS__ )
50 #define throwArcGen3OutOfRange( ... ) arc::gen3::CArcBase::throwOutOfRange( __FUNCTION__, __LINE__, __VA_ARGS__ )
52 #define throwArcGen3LengthError( ... ) arc::gen3::CArcBase::throwException<std::length_error>( __FUNCTION__, __LINE__, __VA_ARGS__ )
54 #define throwArcGen3NoDeviceError() arc::gen3::CArcBase::throwNoDeviceError( __FUNCTION__, __LINE__ )
73 static const std::string version(
void );
81 static void zeroMemory(
void* pDest,
const std::size_t uiSize );
90 static void copyMemory(
void* pDest,
void* pSrc,
const std::size_t uiSize );
100 static void throwOutOfRange(
const std::string& sMethodName,
const std::int32_t iLine,
const std::uint32_t uiElement, std::pair<std::uint32_t, std::uint32_t> range );
110 static void throwOutOfRange(
const std::string& sMethodName,
const std::int32_t iLine,
const std::string& sElement,
const std::size_t uiSize );
119 static void throwNoDeviceError(
const std::string& sMethodName,
const std::int32_t iLine,
const std::string& sMsg =
"" );
128 template <
typename T = std::runtime_error>
129 static void throwException(
const std::string& sMethodName,
const std::int32_t iLine,
const std::string& sMsg )
131 std::ostringstream oss;
133 oss << sMsg <<
"\nTrace: ( " << sMethodName <<
"() line: " << iLine <<
" )" << std::ends;
135 throw T( oss.str() );
159 template <
typename T = std::runtime_error>
160 static void throwException(
const std::string& sMethodName,
const std::int32_t iLine,
const char* pszFmt, ... )
162 std::ostringstream oss;
168 va_start( ap, pszFmt );
170 for ( pzChar = (
char* )pszFmt; *pzChar; pzChar++ )
172 if ( *pzChar !=
'%' )
182 oss << va_arg( ap,
int );
188 oss << va_arg( ap,
unsigned int );
194 oss << va_arg( ap,
long );
200 oss << va_arg( ap,
unsigned long );
206 oss << va_arg( ap,
unsigned long long );
212 oss << va_arg( ap,
double );
218 for ( pszVal = va_arg( ap,
char* ); *pszVal; pszVal++ )
238 oss << std::uppercase << std::hex << va_arg( ap,
unsigned int ) << std::dec;
244 oss << std::boolalpha << ( va_arg( ap,
int ) > 0 ? true : false );
250 oss << std::uppercase << std::showbase << std::hex << va_arg( ap, std::uint64_t ) << std::dec;
263 throwException<T>( sMethodName, iLine, oss.str() );
271 template<
typename ErrCode>
272 static const std::string
getSystemMessage( ErrCode iCode )
requires std::is_integral_v<ErrCode>
275 std::ostringstream oss;
280 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
283 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
288 char szBuffer[ 1024 ] = {
'\0' };
290 std::int32_t iBytes = WideCharToMultiByte( CP_ACP,
292 reinterpret_cast< LPWSTR
>( lpBuffer ),
304 LocalFree( lpBuffer );
308 std::ostringstream oss;
313 oss <<
"( errno: " << iCode <<
" ) - " << strerror( iCode );
321 if (sMsg.back() ==
'\n' || sMsg.back() ==
'\r')
323 sMsg.erase( sMsg.end() - 1, sMsg.end() );
333 if ( sMsg.back() ==
'\n' || sMsg.back() ==
'\r' )
335 sMsg.erase( sMsg.end() - 1, sMsg.end() );
346 static std::uint32_t getSystemError(
void )
noexcept
348 return static_cast< std::uint32_t
>( ::GetLastError() );
353 return static_cast< std::int32_t
>( errno );
364 static std::unique_ptr<CArcStringList> splitString(
const std::string& sString,
const char& zDelim =
' ' );
384 static std::string formatString(
const char* pszFmt, ... );
391 static std::string convertWideToAnsi(
wchar_t wzString[] )
noexcept;
398 static std::string convertWideToAnsi(
const std::wstring& wsString );
405 static std::wstring convertAnsiToWide(
const char* pszString );
416 static std::string cmdToString(
const std::uint32_t uiCmd );
428 static std::string cmdToString(
const std::uint32_t uiReply,
const std::initializer_list<std::uint32_t>& tCmdList );
439 static std::string setDots( std::string_view svText,
const std::size_t uiMaxLength,
const char szDot =
'.' );
455 template <
typename T>
static std::string
iterToString( T* pBegin, T* pEnd,
char zSeperator =
' ' )
457 std::ostringstream oss;
459 if ( pBegin !=
nullptr )
461 if ( pEnd !=
nullptr )
463 while ( pBegin != pEnd )
465 oss << cmdToString( *pBegin++ ) << zSeperator;
471 throwArcGen3Error(
"Invalid \"end\" parameter ( nullptr )." );
477 throwArcGen3Error(
"Invalid \"begin\" parameter ( nullptr )." );
Definition: CArcBase.h:67
static std::int32_t getSystemError(void) noexcept
Definition: CArcBase.h:351
static const std::string m_sVersion
Definition: CArcBase.h:505
CArcBase & operator=(CArcBase &&)=delete
static std::string iterToString(T *pBegin, T *pEnd, char zSeperator=' ')
Definition: CArcBase.h:455
CArcBase(const CArcBase &)=delete
CArcBase & operator=(const CArcBase &)=delete
static const std::string getSystemMessage(ErrCode iCode)
Definition: CArcBase.h:272
static void throwException(const std::string &sMethodName, const std::int32_t iLine, const char *pszFmt,...)
Definition: CArcBase.h:160
static void throwException(const std::string &sMethodName, const std::int32_t iLine, const std::string &sMsg)
Definition: CArcBase.h:129
CArcBase(CArcBase &&)=delete