]> Creatis software - bbtk.git/blob - kernel/src/bbtkSystem.h
72f4e6f7e9efbf45c9a419ab22ed1895b51619b3
[bbtk.git] / kernel / src / bbtkSystem.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkSystem.h,v $
4   Language:  C++
5   Date:      $Date: 2009/01/08 10:18:29 $
6   Version:   $Revision: 1.12 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *\file
34  *\brief contains all the OS depending stuff
35  */
36 #ifndef __bbtkSystem_h__
37 #define __bbtkSystem_h__
38
39 #include "bbtkConfigure.h"
40
41 // We try for Visual 6..????
42 //#pragma warning( disable : 4786)
43
44
45
46 //-----------------------------------------------------------------------------
47 //This is needed when compiling in debug mode
48 #ifdef _MSC_VER
49 // 'identifier' : class 'type' needs to have dll-interface to be used by
50 // clients of class 'type2'
51 #pragma warning ( disable : 4251 )
52 // non dll-interface class 'type' used as base for dll-interface class 'type2'
53 #pragma warning ( disable : 4275 )
54 // 'identifier' : identifier was truncated to 'number' characters in the
55 // debug information
56 #pragma warning ( disable : 4786 )
57 //'identifier' : decorated name length exceeded, name was truncated
58 #pragma warning ( disable : 4503 )
59 // C++ exception specification ignored except to indicate a 
60 // function is not __declspec(nothrow)
61 #pragma warning ( disable : 4290 )
62 // signed/unsigned mismatch
63 #pragma warning ( disable : 4018 )
64 // return type for 'identifier' is '' (ie; not a UDT or reference to UDT. Will
65 // produce errors if applied using infix notation
66 #pragma warning ( disable : 4284 )
67 // 'type' : forcing value to bool 'true' or 'false' (performance warning)
68 // Has revealed a real error !
69 //  bbSignalOutputModification(bool) called rather than 
70 //  bbSignalOutputModification(const std::string&, bool = true)
71 //  when invoking bbSignalOutputModification("Out") 
72 // KEEP IT !  
73 // //#pragma warning ( disable : 4800 )
74 // To avoid warning :
75 // 'PACKAGE_NAMEGetPackage' has C-linkage specified, but returns UDT 'boost::shared_ptr<T>' which is incompatible with C
76 #pragma warning ( disable : 4190 )
77 #endif //_MSC_VER
78
79
80 #include <stdio.h>  // for printf, ...
81 #include <iostream> // for cout, endl, ...
82
83 #ifdef _MSC_VER
84 // Micro$oft related stuff
85 #pragma once
86 #include <conio.h>
87 #include <tchar.h>
88 #else
89 //#include  <curses.h> // for getch
90 #endif //_MSC_VER
91
92 //-----------------------------------------------------------------------------
93 // Micro$oft shared library related stuff
94 //
95 // all the classes that must be visible outside the bbtk library 
96 // should be defined as :
97 // class BBTK_EXPORT ClassName 
98 // instead of :
99 // class ClassName
100
101
102
103
104 #if defined(_WIN32) 
105 //&& defined(BUILD_SHARED_LIBS)
106 //#include "WWW.h"
107   #ifdef BBTK_EXPORT_SYMBOLS
108     #define BBTK_EXPORT __declspec( dllexport )
109 #else
110     #define BBTK_EXPORT __declspec( dllimport )
111   #endif
112   #define BBTK_CDECL __cdecl
113 #else
114   #define BBTK_EXPORT
115   #define BBTK_CDECL
116 #endif // defined(_WIN32) && defined(BUILD_SHARED_LIBS)
117
118
119
120 #ifdef __BORLANDC__
121 #include <mem.h>
122 #endif //__BORLANDC__
123
124
125
126
127
128 //-----------------------------------------------------------------------------
129 // Version
130 #include <string.h>
131
132 namespace bbtk
133 {
134 #define BBTK_STRINGIFY(A) #A
135 #define BBTK_STRINGIFY_SYMBOL(A) BBTK_STRINGIFY(A)
136
137   extern "C" 
138   {
139     BBTK_EXPORT inline const std::string& BBTK_CDECL GetVersion() 
140     {
141       static const std::string v(BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
142       return v;
143     }
144   }
145
146 }
147 //-----------------------------------------------------------------------------
148
149
150
151
152 //-----------------------------------------------------------------------------
153 /*
154 #ifdef _WIN32
155 typedef  signed char         int8_t;
156 typedef  signed short        int16_t;
157 typedef  signed int          int32_t;
158 typedef  unsigned char       uint8_t;
159 typedef  unsigned short      uint16_t;
160 typedef  unsigned int        uint32_t;
161 #else 
162 #include <stdint.h>
163 #include <inttypes.h> 
164 #endif
165 */
166
167 #ifdef CMAKE_HAVE_STDINT_H
168    #include <stdint.h>
169 #else
170 #ifdef CMAKE_HAVE_INTTYPES_H
171    // Old system only have this
172    #include <inttypes.h>   // For uint8_t uint16_t and uint32_t
173 #else
174    //#include "XXX.h"
175 // Broken plateforms do not respect C99 and do not provide those typedef
176 // Special case for recent Borland compiler, comes with stdint.h
177 #if defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  \
178                       || defined(__MINGW32__)
179 typedef  signed char         int8_t;
180 typedef  signed short        int16_t;
181 typedef  signed int          int32_t;
182 typedef  unsigned char       uint8_t;
183 typedef  unsigned short      uint16_t;
184 typedef  unsigned int        uint32_t;
185
186 /// \todo Find a clever way to deal with int64_t, uint64_t
187
188 #else
189 #error "Sorry your plateform is not supported"
190 #endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  || defined(__MINGW32__)
191 #endif // CMAKE_HAVE_INTTYPES_H
192 #endif // CMAKE_HAVE_STDINT_H
193
194 // Basically for VS6 and bcc 5.5.1:
195 #ifndef UINT32_MAX
196 #define UINT32_MAX    (4294967295U)
197 #endif
198
199
200
201 //-----------------------------------------------------------------------------
202
203
204 //-----------------------------------------------------------------------------
205 namespace bbtk
206 {
207  
208   /// System related stuff
209   struct System
210   {
211     /// returns true iff the program has a tty
212     static int HasTTY(); 
213   };
214
215 } // namespace bbtk
216 //-----------------------------------------------------------------------------
217
218     // file separator
219 #if defined(_WIN32)
220 #define VALID_FILE_SEPARATOR "\\"
221 #define INVALID_FILE_SEPARATOR "/"
222 #define VALID_FILE_SEPARATOR_CHAR '\\'
223 #define INVALID_FILE_SEPARATOR_CHAR '/'
224 #else
225 #define INVALID_FILE_SEPARATOR "\\"
226 #define VALID_FILE_SEPARATOR "/"
227 #define INVALID_FILE_SEPARATOR_CHAR '\\'
228 #define VALID_FILE_SEPARATOR_CHAR '/'
229 #endif
230
231 #endif
232
233
234 //----------------------------
235 #ifndef _WIN32
236 #include <unistd.h> //for access, unlink
237 #else
238 #include <io.h> //for _access on Win32
239 #endif
240
241 #ifdef _MSC_VER
242 # define access _access
243 #endif