gatelib  2.1
g_common_def.h
1 #pragma once
2 
3 #include "g_option.h"
4 
5 //disabled some warning on visual studio
6 #if G_AUTOPTION_ON_MSVC > 0
7 #pragma warning (disable:4996)
8 #pragma warning (disable:4290)
9 #pragma warning (disable:4005)
10 #endif
11 
13 #define G_REF
14 
16 #if G_AUTOPTION_ON_WINDOWS
17  #if G_OPTION_IS_BUILD
18  #if G_OPTION_IS_DLL > 0
19  #define G_LIB_ITEM __declspec(dllexport)
20  #else
21  #define G_LIB_ITEM
22  #endif
23  #else
24  //use G_LIB_DLL only for importing Glibrary as dll
25  #if G_OPTION_IS_DLL > 0
26  #define G_LIB_ITEM __declspec(dllimport)
27  #else
28  #define G_LIB_ITEM
29  #endif
30  #endif
31 #else
32  #define G_LIB_ITEM
33 #endif
34 
35 #if ( G_AUTOPTION_ON_GCC > 0 )
36 # define G_BUILD_MAY_ALIAS __attribute__((__may_alias__))
37 #else
38 # define G_BUILD_MAY_ALIAS
39 #endif
40 
41 //to be used inside a macro a macro parameter
42 #define G_COMMA ,
43 #define G_STR(s) G_STR_DUMMY(s)
45 #define G_STR_DUMMY(s) #s
46 #define G_METHOD_POINTER(cls_name,method_name) &cls_name::method_name
48 
49 #if G_AUTOPTION_ON_MSVC
50 # define G_THREAD_SAFE_VAR __declspec(thread)
51 #else
52 # define G_THREAD_SAFE_VAR __thread
53 #endif
54 
55 #define G_COPY_CONSTRUCTOR_PROHIBITED(aclsname) private: aclsname ( const aclsname& ) {}
56 
57 #define G_BUILD_ASSERT(condition) ((void)sizeof(char[1 - 2*(!(condition))]))
58 
59 typedef long long GInt64_t;
60 typedef unsigned long long GUint64_t;
61 typedef int GInt32_t;
62 typedef unsigned int GUint32_t;
63 typedef double GReal_t;
64 typedef wchar_t GWchar_t;
65 typedef GInt64_t GHandle_t;
66 typedef double GTimeoutSec_t;
67 
68 #ifndef G_VERBOSE_LEVEL
69 # define G_VERBOSE_LEVEL 0
70 #endif
71 
73 #if G_VERBOSE_LEVEL
74  #include <iostream>
75 #endif
76 
77 #if G_VERBOSE_LEVEL >= 1
78 # define G_VERBOSE_MSG_L1(amessage) std::cout << amessage << std::endl;
79 # define G_VERBOSE_CALL_L1(acall) std::cout << G_STR(acall) << std::endl; acall;
80 #else
81 # define G_VERBOSE_MSG_L1(amessage)
82 # define G_VERBOSE_CALL_L1(acall) acall;
83 #endif
84 
85 #if G_VERBOSE_LEVEL >= 2
86 # define G_VERBOSE_MSG_L2(amessage) std::cout << amessage << std::endl;
87 # define G_VERBOSE_CALL_L2(acall) std::cout << G_STR(acall) << std::endl; acall;
88 #else
89 # define G_VERBOSE_MSG_L2(amessage)
90 # define G_VERBOSE_CALL_L2(acall) acall;
91 #endif
92 
93 #if G_VERBOSE_LEVEL >= 3
94 # define G_VERBOSE_MSG_L3(amessage) std::cout << amessage << std::endl;
95 # define G_VERBOSE_CALL_L3(acall) std::cout << G_STR(acall) << std::endl; acall;
96 #else
97 # define G_VERBOSE_MSG_L3(amessage)
98 # define G_VERBOSE_CALL_L3(acall) acall;
99 #endif
100 
101 #if G_VERBOSE_LEVEL >= 4
102 # define G_VERBOSE_MSG_L4(amessage) std::cout << amessage << std::endl;
103 # define G_VERBOSE_CALL_L4(acall) std::cout << G_STR(acall) << std::endl; acall;
104 #else
105 # define G_VERBOSE_MSG_L4(amessage)
106 # define G_VERBOSE_CALL_L4(acall) (acall);
107 #endif
108 
109 #if G_VERBOSE_LEVEL >= 5
110 # define G_VERBOSE_MSG_L5(amessage) std::cout << amessage << std::endl;
111 # define G_VERBOSE_CALL_L5(acall) std::cout << G_STR(acall) << std::endl; acall;
112 #else
113 # define G_VERBOSE_MSG_L5(amessage)
114 # define G_VERBOSE_CALL_L5(acall) (acall);
115 #endif
116 
118 template < int S > class g_raw_buffer
119 {
120 public:
121  template < class T > T* ptr ()
122  {
123  union
124  {
125  //causes an error in case sizeof mBuff is insufficient
126  char fake[sizeof(mBuff)-sizeof(T)];
127  T* p;
128  }temp;
129 
130  temp.p = reinterpret_cast<T*>(&mBuff.fake);
131 
132  return temp.p;
133  }
134 protected:
135  union
136  {
137  int fake;
138  char data[S];
139  }mBuff;
140 };
141 
Raw buffer (array of char) wrapper.
Definition: g_common_def.h:118