Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
StrArg.h
Go to the documentation of this file.
1 //
5 //
6 #ifndef _INC_StrArg_H
7 #define _INC_StrArg_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "StrChar.h"
13 #include "StrConst.h"
14 #include "cUnitTestDecl.h"
15 
16 namespace Gray
17 {
18  // Convert some type into a string. ALA ToString()
19  // Define temporary string values for use as sprintf() arguments.
20  // Use cTempPool
21 
22  template< typename TYPE>
23  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(const char* pszStr);
24  template< typename TYPE>
25  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(const wchar_t* pszStr);
26 
27  template< typename TYPE>
28  inline const TYPE* StrArg(const BYTE* pszStr)
29  {
30  // auto convert to a const type arg. (but not return)
31  return StrArg<TYPE>(reinterpret_cast<const char*>(pszStr));
32  }
33 
34 #ifdef _NATIVE_WCHAR_T_DEFINED
35  template< typename TYPE>
36  inline const TYPE* StrArg(const WORD* pszStr)
37  {
38  // auto convert to a const type arg. (but not return)
39  return StrArg<TYPE>(reinterpret_cast<const wchar_t*>(pszStr));
40  }
41 #endif
42 
43  // TODO Front padding with max X chars.
44 
45  template< typename TYPE>
46  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(TYPE ch, StrLen_t nRepeat = 1);
47 
48  template< typename TYPE>
49  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(INT32 iVal);
50  template< typename TYPE>
51  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(UINT32 uVal, RADIX_t uRadix = 10);
52 
53 #ifdef USE_INT64
54  template< typename TYPE>
55  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(INT64 iVal);
56  template< typename TYPE>
57  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(UINT64 uVal, RADIX_t uRadix = 10);
58 #endif
59 
60  template< typename TYPE>
61  GRAYCORE_LINK const TYPE* GRAYCALL StrArg(double dVal); // , int iPlaces, bool bFormat=false
62 
63  template<> inline const char* GRAYCALL StrArg<char>(const char* pszStr) noexcept // static
64  {
68  return pszStr;
69  }
70  template<> inline const wchar_t* GRAYCALL StrArg<wchar_t>(const wchar_t* pszStr) noexcept // static
71  {
75  return pszStr;
76  }
77 
78  template<> inline const BYTE* GRAYCALL StrArg<BYTE>(const BYTE* pszStr) noexcept // static
79  {
80  return pszStr;
81  }
82  template<> inline const BYTE* GRAYCALL StrArg<BYTE>(const char* pszStr) noexcept // static
83  {
84  return (const BYTE *)pszStr;
85  }
86 
87 #if 0 // def _NATIVE_WCHAR_T_DEFINED // is wchar_t the same type as WORD ?
88  template<> inline const BYTE* GRAYCALL StrArg<BYTE>(const wchar_t* pszStr) noexcept // static
89  {
90  return (const BYTE*)StrArg<char>(pszStr);
91  }
92  template<> inline const BYTE* GRAYCALL StrArg<BYTE>(const WORD* pszStr) noexcept // static
93  {
94  return (const BYTE*)StrArg<char>((const wchar_t*)pszStr);
95  }
96 
97  template<> inline const WORD* GRAYCALL StrArg<WORD>(const WORD* pszStr) noexcept // static
98  {
99  return pszStr;
100  }
101  template<> inline const WORD* GRAYCALL StrArg<WORD>(const wchar_t* pszStr) noexcept // static
102  {
103  return (const WORD*)pszStr;
104  }
105  template<> inline const WORD* GRAYCALL StrArg<WORD>(const char* pszStr) noexcept // static
106  {
107  return (const WORD*)StrArg<wchar_t>(pszStr);
108  }
109  template<> inline const WORD* GRAYCALL StrArg<WORD>(const BYTE* pszStr) noexcept // static
110  {
111  return (const WORD*)StrArg<wchar_t>((const char*)pszStr);
112  }
113 #endif
114 
115 };
116 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define TYPE
Definition: StrT.cpp:38
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
const BYTE *__stdcall StrArg< BYTE >(const BYTE *pszStr) noexcept
Definition: StrArg.h:78
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
const wchar_t *__stdcall StrArg< wchar_t >(const wchar_t *pszStr) noexcept
Definition: StrArg.h:70
__DECL_IMPORT const TYPE *__stdcall StrArg(const char *pszStr)
WORD RADIX_t
Base for convert of numbers to strings. e.g. 10 base vs 16 base hex numbers.
Definition: StrChar.h:27
const char *__stdcall StrArg< char >(const char *pszStr) noexcept
Definition: StrArg.h:63