Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
StrConst.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_StrConst_H
6 #define _INC_StrConst_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "GrayCore.h"
12 
13 namespace Gray
14 {
15  typedef char ATOMCHAR_t;
16 
17 #define _AT(x) x
18 #define __TOA(x) x
19 #define __TOW(x) L##x
20 
21 #if USE_UNICODE
22  typedef wchar_t GChar_t;
23 #define _GT(x) __TOW(x)
24 #define _GTN(c) c##W
25 #else
26  typedef char GChar_t;
27 #define _GT(x) __TOA(x)
28 #define _GTN(c) c##A
29 #endif
30 #define _GTNPST(c,p) _GTN(c)##p
31 
32  typedef int StrLen_t;
33 #define STRMAX(x) ((StrLen_t)(_countof(x)-1))
34  const StrLen_t k_StrLen_UNK = -1;
35 
36 #define STRLIT2(s) (s), STRMAX(s)
37 
39  {
42 
43  public:
44  const char* m_A;
45  const wchar_t* m_W; // the Unicode version of m_A;
46 
47  static const StrLen_t k_TabSize = 4;
48 
49  static const char k_EmptyA = '\0';
50  static const wchar_t k_EmptyW = '\0';
51 
52  static const cStrConst k_Empty;
53 
54  public:
55  cStrConst(const char* a, const wchar_t* w) noexcept
56  : m_A(a), m_W(w)
57  {}
58  operator const char*() const noexcept
59  {
60  return m_A;
61  }
62  operator const wchar_t*() const noexcept
63  {
64  return m_W;
65  }
66  const char* get_StrA() const noexcept
67  {
68  return m_A;
69  }
70  const wchar_t* get_StrW() const noexcept
71  {
72  return m_W;
73  }
74  const GChar_t* get_CPtr() const noexcept
75  {
77 #if USE_UNICODE
78  return m_W;
79 #else
80  return m_A;
81 #endif
82  }
83  bool isNull() const noexcept
84  {
85  return(m_A == nullptr);
86  }
87  };
88 
89 #define CSTRCONST(t) cStrConst(t,__TOW(t))
90 };
91 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
Definition: StrConst.h:39
const wchar_t * m_W
Definition: StrConst.h:45
static const cStrConst k_Empty
Empty cStrConst string. like CString::m_Nil.
Definition: StrConst.h:52
const char * get_StrA() const noexcept
Definition: StrConst.h:66
cStrConst(const char *a, const wchar_t *w) noexcept
Definition: StrConst.h:55
bool isNull() const noexcept
Definition: StrConst.h:83
const GChar_t * get_CPtr() const noexcept
Definition: StrConst.h:74
const wchar_t * get_StrW() const noexcept
Definition: StrConst.h:70
const char * m_A
Definition: StrConst.h:44
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
const StrLen_t k_StrLen_UNK
use the default/current length of the string argument.
Definition: StrConst.h:34
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
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26