]> Creatis software - crea.git/blob - src/creaSystem.h
eduardo
[crea.git] / src / creaSystem.h
1 /*=========================================================================
2                                                                                 
3   Program:   crea
4   Module:    $RCSfile: creaSystem.h,v $
5   Language:  C++
6   Date:      $Date: 2010/06/11 05:06:46 $
7   Version:   $Revision: 1.12 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/creatools/license.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 /**
20  *\file
21  *\brief contains all the OS depending stuff
22  */
23 #ifndef __creaSystem_h__
24 #define __creaSystem_h__
25
26 #include "creaConfigure.h"
27
28 // We try for Visual 6..????
29 //#pragma warning( disable : 4786)
30
31 //-----------------------------------------------------------------------------
32 //This is needed when compiling in debug mode
33 #ifdef _MSC_VER
34 // 'identifier' : class 'type' needs to have dll-interface to be used by
35 // clients of class 'type2'
36 #pragma warning ( disable : 4251 )
37 // non dll-interface class 'type' used as base for dll-interface class 'type2'
38 #pragma warning ( disable : 4275 )
39 // 'identifier' : identifier was truncated to 'number' characters in the
40 // debug information
41 #pragma warning ( disable : 4786 )
42 //'identifier' : decorated name length exceeded, name was truncated
43 #pragma warning ( disable : 4503 )
44 // C++ exception specification ignored except to indicate a 
45 // function is not __declspec(nothrow)
46 #pragma warning ( disable : 4290 )
47 // signed/unsigned mismatch
48 #pragma warning ( disable : 4018 )
49 // return type for 'identifier' is '' (ie; not a UDT or reference to UDT. Will
50 // produce errors if applied using infix notation
51 #pragma warning ( disable : 4284 )
52 // 'type' : forcing value to bool 'true' or 'false' (performance warning)
53 // //#pragma warning ( disable : 4800 )
54 #endif //_MSC_VER
55
56
57 #include <stdio.h>  // for printf, ...
58 #include <iostream> // for cout, endl, ...
59
60 #ifdef _MSC_VER
61 // Micro$oft related stuff
62 #pragma once
63 #include <conio.h>
64 #include <tchar.h>
65 #else
66 //#include  <curses.h> // for getch
67 #endif //_MSC_VER
68
69 //-----------------------------------------------------------------------------
70 // Micro$oft shared library related stuff
71 //
72 // all the classes that must be visible outside the crea library 
73 // should be defined as :
74 // class CREA_EXPORT ClassName 
75 // instead of :
76 // class ClassName
77
78
79 /*
80 // Useless ?
81 #if defined(_WIN32) 
82 //&& defined(BUILD_SHARED_LIBS)
83   #ifdef CREA_EXPORTS2
84     #define CREA_EXPORT2 export
85   #else
86     #define CREA_EXPORT2 
87   #endif
88 #else
89   #define CREA_EXPORT2
90 #endif // defined(_WIN32) && defined(BUILD_SHARED_LIBS)
91 */
92 //#define TEST toto
93
94
95 #if defined(_WIN32) && defined(CREA_BUILD_SHARED)
96   #ifdef CREA_EXPORT_SYMBOLS
97     #define CREA_EXPORT __declspec( dllexport ) 
98   #else
99         #define CREA_EXPORT __declspec( dllimport )
100   #endif
101   #define CREA_CDECL __cdecl
102 #else
103   #define CREA_EXPORT
104   #define CREA_CDECL
105 #endif // defined(_WIN32) && defined(CREA_BUILD_SHARED)
106
107
108 #ifdef __BORLANDC__
109 #include <mem.h>
110 #endif //__BORLANDC__
111
112
113
114 // ----------------------------------------------------------------------------
115 // wx headers
116 // ----------------------------------------------------------------------------
117 //#include "creaWx.h"
118
119 /*
120 #ifdef _USE_WXWIDGETS_
121 #include "wx/wxprec.h"
122 #include <wx/datetime.h>
123 #ifndef WX_PRECOMP
124 #   include <wx/wx.h>
125 #endif //WX_PRECOMP
126
127 #include <wx/log.h>
128
129 #ifdef __WXGTK__
130 # include <locale.h>
131 #endif //__WXGTK__
132
133 #endif //_USE_WXWIDGETS_
134 */
135 //-----------------------------------------------------------------------------
136
137 //-----------------------------------------------------------------------------
138 // Version
139 #include <string.h>
140
141 namespace crea
142 {
143 #define CREA_STRINGIFY(A) #A
144 #define CREA_STRINGIFY_SYMBOL(A) CREA_STRINGIFY(A)
145
146   extern "C" 
147   {
148     CREA_EXPORT inline const std::string& CREA_CDECL GetVersion() 
149     {
150       static const std::string v(CREA_STRINGIFY_SYMBOL(CREA_VERSION));
151       return v;
152     }
153   }
154
155 }
156 //-----------------------------------------------------------------------------
157
158 //-----------------------------------------------------------------------------
159 /*
160 #ifdef _WIN32
161 typedef  signed char         int8_t;
162 typedef  signed short        int16_t;
163 typedef  signed int          int32_t;
164 typedef  unsigned char       uint8_t;
165 typedef  unsigned short      uint16_t;
166 typedef  unsigned int        uint32_t;
167 #else 
168 #include <stdint.h>
169 #include <inttypes.h> 
170 #endif
171 */
172
173 #ifdef CMAKE_HAVE_STDINT_H
174    #include <stdint.h>
175 #else
176 #ifdef CMAKE_HAVE_INTTYPES_H
177    // Old system only have this
178    #include <inttypes.h>   // For uint8_t uint16_t and uint32_t
179 #else
180    //#include "XXX.h"
181 // Broken plateforms do not respect C99 and do not provide those typedef
182 // Special case for recent Borland compiler, comes with stdint.h
183 #if defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  \
184                       || defined(__MINGW32__)
185 typedef  signed char         int8_t;
186 typedef  signed short        int16_t;
187 typedef  signed int          int32_t;
188 typedef  unsigned char       uint8_t;
189 typedef  unsigned short      uint16_t;
190 typedef  unsigned int        uint32_t;
191
192 /// \todo Find a clever way to deal with int64_t, uint64_t
193
194 #else
195 #error "Sorry your plateform is not supported"
196 #endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560)  || defined(__MINGW32__)
197 #endif // CMAKE_HAVE_INTTYPES_H
198 #endif // CMAKE_HAVE_STDINT_H
199
200 // Basically for VS6 and bcc 5.5.1:
201 #ifndef UINT32_MAX
202 #define UINT32_MAX    (4294967295U)
203 #endif
204
205 //-----------------------------------------------------------------------------
206
207
208 //-----------------------------------------------------------------------------
209 namespace crea
210 {
211  
212   /// System related stuff
213   struct System
214   {
215     /// returns true iff the program has a tty
216     static int HasTTY(); 
217     CREA_EXPORT static int GetAppPath(char *pname, size_t pathsize);
218     CREA_EXPORT static std::string GetDllAppPath(std::string &nomdll);
219     CREA_EXPORT static std::string GetDllAppPath(const char *nomdll);   
220     CREA_EXPORT static std::string GetExecutablePath();
221     CREA_EXPORT static void createDirectory(const char* directorypath);
222   };
223
224 } // namespace crea
225 //-----------------------------------------------------------------------------
226
227     // file separator
228 #if defined(_WIN32)
229 #define VALID_FILE_SEPARATOR "\\"
230 #define INVALID_FILE_SEPARATOR "/"
231 #else
232 #define INVALID_FILE_SEPARATOR "\\"
233 #define VALID_FILE_SEPARATOR "/"
234 #endif
235
236 #endif