Updated license
[anna.git] / include / anna / config / defines.hpp
1 // ANNA - Anna is Not Nothingness Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef anna_config_defines_hpp
38 #define anna_config_defines_hpp
39
40 #include <sys/types.h>
41
42 #ifdef ANNA_FILE_LOCATION
43 #undef ANNA_FILE_LOCATION
44 #endif
45 #define ANNA_FILE_LOCATION (const char *)__FILE__,(const int)__LINE__
46 //#define ANNA_FILE_LOCATION __PRETTY_FUNCTION__,(const char *)__FILE__,(const int)__LINE__
47
48
49 #define ANNA_VERSION 0x000d03
50
51 #if defined(__linux__) && !defined (_NO_BUILTIN)
52 #define anna_memcpy(a,b,c) __builtin_memcpy((a),(b),(c))
53 #define anna_memset(a,b,c) __builtin_memset((a),(b),(c))
54 #define anna_memmove(a,b,c) __builtin_memmove((a),(b),(c))
55 #define anna_strcpy(a,b) __builtin_strcpy((a),(b))
56 #define anna_strncpy(a,b,c) __builtin_strncpy((a),(b),(c))
57 #define anna_strcmp(a,b) __builtin_strcmp((a),(b))
58 #define anna_strncmp(a,b,n) __builtin_strncmp((a),(b),(n))
59 #define anna_strcat(a,b) __builtin_strcat((a),(b))
60 #define anna_strlen(a) __builtin_strlen((a))
61 #define anna_strstr(a,b) __builtin_strstr((a),(b))
62 #define anna_strchr(a,b) __builtin_strchr((a),(b))
63 #else
64 #define anna_memcpy(a,b,c) memcpy((a),(b),(c))
65 #define anna_memset(a,b,c) memset((a),(b),(c))
66 #define anna_memmove(a,b,c) memmove((a),(b),(c))
67 #define anna_strcpy(a,b) strcpy((a),(b))
68 #define anna_strncpy(a,b,c) strncpy((a),(b),(c))
69 #define anna_strcmp(a,b) strcmp((a),(b))
70 #define anna_strncmp(a,b,n) strncmp((a),(b),(n))
71 #define anna_strcat(a,b) strcat((a),(b))
72 #define anna_strlen(a) strlen((a))
73 #define anna_strstr(a,b) strstr((a),(b))
74 #define anna_strchr(a,b) strchr((a),(b))
75 #endif
76
77 #define anna_signal_shield(r,a) { register int cx (0); do { if ((r = (a)) < 0) cx ++; } while (r < 0 && errno == EINTR && cx < 5); }
78
79 //#define anna_append_string(str,str1,str2) (str).append (str1).append (str2)
80
81 #ifndef _NOTRACE
82 #define LOGWARNING(a) if (anna::Logger::isActive (anna::Logger::Warning) == true) {a;}
83 #define LOGNOTICE(a) if (anna::Logger::isActive (anna::Logger::Notice) == true) {a;}
84 #define LOGINFORMATION(a) if (anna::Logger::isActive (anna::Logger::Information) == true) {a;}
85 #define LOG_EXCL_INFORMATION(a) if (anna::Logger::isActive (anna::Logger::Debug) == false && anna::Logger::isActive (anna::Logger::Information) == true) {a;}
86 #define LOGDEBUG(a) if (anna::Logger::isActive (anna::Logger::Debug) == true) {a;}
87 #define LOGLOCAL0(a) if (anna::Logger::isActive (anna::Logger::Local0) == true) {a;}
88 #define LOGLOCAL1(a) if (anna::Logger::isActive (anna::Logger::Local1) == true) {a;}
89 #define LOGLOCAL2(a) if (anna::Logger::isActive (anna::Logger::Local2) == true) {a;}
90 #define LOGLOCAL3(a) if (anna::Logger::isActive (anna::Logger::Local3) == true) {a;}
91 #define LOGLOCAL4(a) if (anna::Logger::isActive (anna::Logger::Local4) == true) {a;}
92 #define LOGLOCAL5(a) if (anna::Logger::isActive (anna::Logger::Local5) == true) {a;}
93 #define LOGLOCAL6(a) if (anna::Logger::isActive (anna::Logger::Local6) == true) {a;}
94 #define LOGLOCAL7(a) if (anna::Logger::isActive (anna::Logger::Local7) == true) {a;}
95 #define LOGMETHOD(a) a;
96 #define LOGFUNCTION(a) a;
97 #else
98 #define LOGWARNING(a)
99 #define LOGNOTICE(a)
100 #define LOGINFORMATION(a)
101 #define LOGDEBUG(a)
102 #define LOGLOCAL0(a)
103 #define LOGLOCAL1(a)
104 #define LOGLOCAL2(a)
105 #define LOGLOCAL3(a)
106 #define LOGLOCAL4(a)
107 #define LOGLOCAL5(a)
108 #define LOGLOCAL6(a)
109 #define LOGLOCAL7(a)
110 #define LOGMETHOD(a)
111 #define LOGFUNCTION(a)
112 #endif
113
114 #ifdef _MT
115 #define WHEN_MULTITHREAD(a) a
116 #define WHEN_SINGLETHREAD(a)
117 #else
118 #define WHEN_MULTITHREAD(a)
119 #define WHEN_SINGLETHREAD(a) a
120 #endif
121
122 namespace anna {
123 #ifndef __x86_64__
124 #undef  __anna64__
125 /** Defines required data type to conversion from pointer to integer */
126 typedef int ptrnumber;
127 #else
128 #define __anna64__
129 /** Defines required data type to conversion from pointer to integer */
130 typedef long ptrnumber;
131 #endif
132 }
133
134 /**
135  * Make conversion from pointer to integer, it will work both 64 bits and 32 bits architecture.
136  */
137 #define anna_ptrnumber_cast(pointer) (anna::ptrnumber)((void*)(pointer))
138
139 #endif
140