]> Creatis software - crea.git/blob - src/creaSystem.h
Feature #1763
[crea.git] / src / creaSystem.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */                                                                         
24
25 /*=========================================================================
26                                                                                 
27   Program:   crea
28   Module:    $RCSfile: creaSystem.h,v $
29   Language:  C++
30   Date:      $Date: 2012/11/15 09:07:32 $
31   Version:   $Revision: 1.15 $
32 =========================================================================*/
33
34 /**
35  *\file
36  *\brief contains all the OS depending stuff
37  */
38 #ifndef __creaSystem_h__
39 #define __creaSystem_h__
40
41 #include "creaConfigure.h"
42
43 // We try for Visual 6..????
44 //#pragma warning( disable : 4786)
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 // //#pragma warning ( disable : 4800 )
69 #endif //_MSC_VER
70
71
72 #include <stdio.h>  // for printf, ...
73 #include <iostream> // for cout, endl, ...
74
75 #ifdef _MSC_VER
76 // Micro$oft related stuff
77 #pragma once
78 #include <conio.h>
79 #include <tchar.h>
80 #else
81 //#include  <curses.h> // for getch
82 #endif //_MSC_VER
83
84 //-----------------------------------------------------------------------------
85 // Micro$oft shared library related stuff
86 //
87 // all the classes that must be visible outside the crea library 
88 // should be defined as :
89 // class CREA_EXPORT ClassName 
90 // instead of :
91 // class ClassName
92
93
94 /*
95 // Useless ?
96 #if defined(_WIN32) 
97 //&& defined(BUILD_SHARED_LIBS)
98   #ifdef CREA_EXPORTS2
99     #define CREA_EXPORT2 export
100   #else
101     #define CREA_EXPORT2 
102   #endif
103 #else
104   #define CREA_EXPORT2
105 #endif // defined(_WIN32) && defined(BUILD_SHARED_LIBS)
106 */
107 //#define TEST toto
108
109
110 #if defined(_WIN32) && defined(CREA_BUILD_SHARED)
111   #ifdef CREA_EXPORT_SYMBOLS
112     #define CREA_EXPORT __declspec( dllexport ) 
113   #else
114         #define CREA_EXPORT __declspec( dllimport )
115   #endif
116   #define CREA_CDECL __cdecl
117 #else
118   #define CREA_EXPORT
119   #define CREA_CDECL
120 #endif // defined(_WIN32) && defined(CREA_BUILD_SHARED)
121
122
123 #ifdef __BORLANDC__
124 #include <mem.h>
125 #endif //__BORLANDC__
126
127
128
129 // ----------------------------------------------------------------------------
130 // wx headers
131 // ----------------------------------------------------------------------------
132 //#include "creaWx.h"
133
134 /*
135 #ifdef _USE_WXWIDGETS_
136 #include "wx/wxprec.h"
137 #include <wx/datetime.h>
138 #ifndef WX_PRECOMP
139 #   include <wx/wx.h>
140 #endif //WX_PRECOMP
141
142 #include <wx/log.h>
143
144 #ifdef __WXGTK__
145 # include <locale.h>
146 #endif //__WXGTK__
147
148 #endif //_USE_WXWIDGETS_
149 */
150 //-----------------------------------------------------------------------------
151
152 //-----------------------------------------------------------------------------
153 // Version
154 #include <string.h>
155
156 namespace crea
157 {
158 #define CREA_STRINGIFY(A) #A
159 #define CREA_STRINGIFY_SYMBOL(A) CREA_STRINGIFY(A)
160
161   extern "C" 
162   {
163     CREA_EXPORT inline const std::string& CREA_CDECL GetVersion() 
164     {
165       static const std::string v(CREA_STRINGIFY_SYMBOL(CREA_VERSION));
166       return v;
167     }
168   }
169
170 }
171 //-----------------------------------------------------------------------------
172
173 //-----------------------------------------------------------------------------
174 /*
175 #ifdef _WIN32
176 typedef  signed char         int8_t;
177 typedef  signed short        int16_t;
178 typedef  signed int          int32_t;
179 typedef  unsigned char       uint8_t;
180 typedef  unsigned short      uint16_t;
181 typedef  unsigned int        uint32_t;
182 #else 
183 #include <stdint.h>
184 #include <inttypes.h> 
185 #endif
186 */
187
188 #ifdef CMAKE_HAVE_STDINT_H
189    #include <stdint.h>
190 #else
191 #ifdef CMAKE_HAVE_INTTYPES_H
192    // Old system only have this
193    #include <inttypes.h>   // For uint8_t uint16_t and uint32_t
194 #else
195    //#include "XXX.h"
196 // Broken plateforms do not respect C99 and do not provide those typedef
197 // Special case for recent Borland compiler, comes with stdint.h
198 #if defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  \
199                       || defined(__MINGW32__)
200 typedef  signed char         int8_t;
201 typedef  signed short        int16_t;
202 typedef  signed int          int32_t;
203 typedef  unsigned char       uint8_t;
204 typedef  unsigned short      uint16_t;
205 typedef  unsigned int        uint32_t;
206
207 /// \todo Find a clever way to deal with int64_t, uint64_t
208
209 #else
210 #error "Sorry your plateform is not supported"
211 #endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  || defined(__MINGW32__)
212 #endif // CMAKE_HAVE_INTTYPES_H
213 #endif // CMAKE_HAVE_STDINT_H
214
215 // Basically for VS6 and bcc 5.5.1:
216 #ifndef UINT32_MAX
217 #define UINT32_MAX    (4294967295U)
218 #endif
219
220 //-----------------------------------------------------------------------------
221
222
223 //-----------------------------------------------------------------------------
224 namespace crea
225 {
226  
227   /// System related stuff
228   struct System
229   {
230     /// returns true iff the program has a tty
231     static int HasTTY(); 
232     CREA_EXPORT static int GetAppPath(char *pname, size_t pathsize);
233     CREA_EXPORT static std::string GetDllAppPath(std::string &nomdll);
234     CREA_EXPORT static std::string GetDllAppPath(const char *nomdll);   
235     CREA_EXPORT static std::string GetExecutablePath();
236     CREA_EXPORT static void createDirectory(const char* directorypath);
237   };
238
239 } // namespace crea
240 //-----------------------------------------------------------------------------
241
242     // file separator
243 #if defined(_WIN32)
244 #define VALID_FILE_SEPARATOR "\\"
245 #define INVALID_FILE_SEPARATOR "/"
246 #else
247 #define INVALID_FILE_SEPARATOR "\\"
248 #define VALID_FILE_SEPARATOR "/"
249 #endif
250
251 #endif