]> err.no Git - sope/blob - sope-core/NGExtensions/common.h
NGLogEventFormatter.h was marked as project, not public - fixed
[sope] / sope-core / NGExtensions / common.h
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #ifndef __NGExtensions_common_h__
23 #define __NGExtensions_common_h__
24
25 #import <Foundation/Foundation.h>
26 #import <Foundation/NSMapTable.h>
27
28 #if defined(WIN32)
29 #  include <windows.h>
30 #elif defined(NeXT) || NeXT_Foundation_LIBRARY
31 #  include <netinet/in.h>
32 #else
33 #  include <arpa/inet.h>
34 #endif
35
36 #if !defined(WIN32)
37 #include <unistd.h>
38 #endif
39
40 #if defined(__MINGW32__)
41 #  define WITH_OPENSTEP 0
42 #  define GNUSTEP  1
43 #elif defined(NeXT) || defined(WIN32)
44 #  define WITH_OPENSTEP 1
45 #  define GNUSTEP  0
46 #  ifndef NeXT_RUNTIME
47 #    define NeXT_RUNTIME 1
48 #  endif
49 #else
50 #  define WITH_OPENSTEP 0
51 #  define GNUSTEP  1
52 #endif
53
54 #if LIB_FOUNDATION_LIBRARY
55 #  include <time.h>
56 #  import <objc/objc-api.h>
57 #  import <objc/objc.h>
58 #  import <objc/encoding.h>
59 #  import <extensions/objc-runtime.h>
60 #endif
61
62 #ifndef ASSIGN
63 #  define ASSIGN(object, value) \
64        ({id __object = (id)object;    \
65          id __value = (id)value;      \
66          if (__value != __object) { if (__value) [__value retain]; \
67           if (__object) [__object release]; \
68           object = __value;}})
69 #endif
70 #ifndef ASSIGNCOPY
71 #  define ASSIGNCOPY(object, value) \
72        ({id __object = (id)object;    \
73          id __value = (id)value;      \
74          if (__value != __object) { if (__value) __value = [__value copy];   \
75           if (__object) [__object release]; \
76           object = __value;}})
77 #endif
78
79 #if defined(LIB_FOUNDATION_LIBRARY)
80 #  define NoZone nil
81 #else
82 #  define NoZone NULL
83 #endif
84
85 #include <ctype.h>
86 #include <stdarg.h>
87 #include <stdio.h>
88 #include <stdlib.h>
89 #include <string.h>
90
91 #ifndef __MINGW32__
92 #include <strings.h>
93 #endif
94
95 #if defined(WIN32)
96 static inline const char *index(const char *str, char c) __attribute__((unused));
97
98 static const char *index(const char *str, char c) {
99   while ((*str != '\0') && (*str != c)) str++;
100   if (*str == '\0') return NULL;
101   else return str;
102 }
103 #endif
104
105 #if PROFILE
106 #  define BEGIN_PROFILE \
107      { NSTimeInterval __ti = [[NSDate date] timeIntervalSince1970];
108
109 #  define END_PROFILE \
110      __ti = [[NSDate date] timeIntervalSince1970] - __ti;\
111      if (__ti > 0.05) \
112        printf("***PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
113      else if (__ti > 0.005) \
114        printf("PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
115      }
116
117 #  define PROFILE_CHECKPOINT(__key__) \
118        printf("---PROF[%s] CP %s: %0.3fs\n", __PRETTY_FUNCTION__, __key__,\
119               [[NSDate date] timeIntervalSince1970] - __ti)
120
121 #else
122 #  define BEGIN_PROFILE {
123 #  define END_PROFILE   }
124 #  define PROFILE_CHECKPOINT(__key__)
125 #endif
126
127 #endif