]> err.no Git - sope/blob - sope-core/NGExtensions/common.h
Drop apache 1 build-dependency
[sope] / sope-core / NGExtensions / common.h
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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 #include <NGExtensions/AutoDefines.h>
29
30 #if defined(WIN32)
31 #  include <windows.h>
32 #elif defined(NeXT) || NeXT_Foundation_LIBRARY
33 #  include <netinet/in.h>
34 #else
35 #  include <arpa/inet.h>
36 #endif
37
38 #if !defined(WIN32)
39 #include <unistd.h>
40 #endif
41
42 #if GNU_RUNTIME
43 #  import <objc/objc-api.h>
44 #  import <objc/objc.h>
45 #  import <objc/encoding.h>
46 #endif
47
48 #if LIB_FOUNDATION_LIBRARY
49 #  include <time.h>
50 #  import <extensions/objc-runtime.h>
51 #endif
52
53 #ifndef ASSIGN
54 #  define ASSIGN(object, value) \
55        ({id __object = (id)object;    \
56          id __value = (id)value;      \
57          if (__value != __object) { if (__value) [__value retain]; \
58           if (__object) [__object release]; \
59           object = __value;}})
60 #endif
61 #ifndef ASSIGNCOPY
62 #  define ASSIGNCOPY(object, value) \
63        ({id __object = (id)object;    \
64          id __value = (id)value;      \
65          if (__value != __object) { if (__value) __value = [__value copy];   \
66           if (__object) [__object release]; \
67           object = __value;}})
68 #endif
69
70 #if LIB_FOUNDATION_LIBRARY
71 #  define NoZone nil
72 #else
73 #  define NoZone NULL
74 #endif
75
76 #include <ctype.h>
77 #include <stdarg.h>
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <string.h>
81
82 #ifndef __MINGW32__
83 #include <strings.h>
84 #endif
85
86 #if defined(WIN32)
87 static inline const char *index(const char *str, char c) __attribute__((unused));
88
89 static const char *index(const char *str, char c) {
90   while ((*str != '\0') && (*str != c)) str++;
91   if (*str == '\0') return NULL;
92   else return str;
93 }
94 #endif
95
96 #if PROFILE
97 #  define BEGIN_PROFILE \
98      { NSTimeInterval __ti = [[NSDate date] timeIntervalSince1970];
99
100 #  define END_PROFILE \
101      __ti = [[NSDate date] timeIntervalSince1970] - __ti;\
102      if (__ti > 0.05) \
103        printf("***PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
104      else if (__ti > 0.005) \
105        printf("PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
106      }
107
108 #  define PROFILE_CHECKPOINT(__key__) \
109        printf("---PROF[%s] CP %s: %0.3fs\n", __PRETTY_FUNCTION__, __key__,\
110               [[NSDate date] timeIntervalSince1970] - __ti)
111
112 #else
113 #  define BEGIN_PROFILE {
114 #  define END_PROFILE   }
115 #  define PROFILE_CHECKPOINT(__key__)
116 #endif
117
118 #endif