00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef MRPT_OS_H 00029 #define MRPT_OS_H 00030 00031 #include <mrpt/config.h> 00032 00033 #include <cstdarg> 00034 #include <cstdlib> 00035 #include <cstring> 00036 #include <deque> 00037 #include <vector> 00038 00039 // Duplicated here since <mrpt/system/os.h> is the only header that cannot include "utils_defs.h" 00040 #define _IAMINUTILSDEFS_H 00041 #include <mrpt/utils/utils_impexp.h> // DLL import/export definitions 00042 #undef _IAMINUTILSDEFS_H 00043 00044 #include <mrpt/utils/types.h> // This must be AFTER <utils_impexp.h> 00045 00046 // Define a decl. modifier for printf-like format checks at compile time: 00047 #ifdef __GNUC__ 00048 # define MRPT_printf_format_check(_FMT_,_VARARGS_) __attribute__ ((__format__ (__printf__, _FMT_,_VARARGS_))) 00049 #else 00050 # define MRPT_printf_format_check(_FMT_,_VARARGS_) 00051 #endif 00052 00053 // Define a decl. modifier for scanf-like format checks at compile time: 00054 #ifdef __GNUC__ 00055 # define MRPT_scanf_format_check(_FMT_,_VARARGS_) __attribute__ ((__format__ (__scanf__, _FMT_,_VARARGS_))) 00056 #else 00057 # define MRPT_scanf_format_check(_FMT_,_VARARGS_) 00058 #endif 00059 00060 00061 /** Used after member declarations */ 00062 #define MRPT_NO_THROWS throw() 00063 00064 /** Represents an invalid timestamp, where applicable. 00065 */ 00066 #define INVALID_TIMESTAMP (0) 00067 00068 namespace mrpt 00069 { 00070 /** This namespace provides a OS-independent interface to many useful functions: filenames manipulation, time and date, string parsing, file I/O, threading, memory allocation, etc. 00071 * \sa mrpt::system::os 00072 */ 00073 namespace system 00074 { 00075 /** This namespace provides a OS-independent interface to low-level functions. 00076 * Most of these functions are converted into calls to standard functions, unless we are into Visual Studio 2005 (or newer). In that case the secure version 00077 * of the standard library functions (prefix "_s") are used instead. 00078 */ 00079 namespace os 00080 { 00081 /** An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compilers) 00082 * \sa utils::format 00083 */ 00084 int MRPTDLLIMPEXP sprintf(char *buf, size_t bufSize, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(3,4); 00085 00086 /** An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compilers) 00087 */ 00088 int MRPTDLLIMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS; 00089 00090 /** An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compilers) 00091 */ 00092 int MRPTDLLIMPEXP vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS; 00093 00094 /** An OS-independent version of fopen. 00095 * \return It will always return NULL on any error. 00096 */ 00097 FILE MRPTDLLIMPEXP *fopen(const char *fileName,const char *mode) MRPT_NO_THROWS; 00098 00099 /** An OS-independent version of fopen (std::string version) 00100 * \return It will always return NULL on any error. 00101 */ 00102 FILE MRPTDLLIMPEXP *fopen(const std::string &fileName,const char *mode) MRPT_NO_THROWS; 00103 00104 /** An OS-independent version of fprintf 00105 */ 00106 int MRPTDLLIMPEXP fprintf(FILE *fil, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(2,3); 00107 00108 /** An OS-independent version of fscanf 00109 * \return The number of fields correctly assigned 00110 */ 00111 int MRPTDLLIMPEXP fscanf(FILE *fil, const char *format, ...) MRPT_NO_THROWS MRPT_scanf_format_check(2,3); 00112 00113 /** An OS-independent version of fclose. 00114 * \exception std::exception On trying to close a NULL file descriptor. 00115 */ 00116 void MRPTDLLIMPEXP fclose(FILE *f); 00117 00118 /** An OS-independent version of strcat. 00119 * \return It will always return the "dest" pointer. 00120 */ 00121 char MRPTDLLIMPEXP * strcat(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS; 00122 00123 /** An OS-independent version of strcpy. 00124 * \return It will always return the "dest" pointer. 00125 */ 00126 char MRPTDLLIMPEXP *strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS; 00127 00128 /** An OS-independent version of strcmp. 00129 * \return It will return 0 when both strings are equal, casi sensitive. 00130 */ 00131 int MRPTDLLIMPEXP _strcmp(const char*str1,const char*str2) MRPT_NO_THROWS; 00132 00133 /** An OS-independent version of strcmpi. 00134 * \return It will return 0 when both strings are equal, casi insensitive. 00135 */ 00136 int MRPTDLLIMPEXP _strcmpi(const char*str1,const char*str2) MRPT_NO_THROWS; 00137 00138 /** An OS-independent version of strtoll. 00139 */ 00140 int64_t MRPTDLLIMPEXP _strtoll(const char *nptr, char **endptr, int base); 00141 00142 /** An OS-independent version of strtoull. 00143 */ 00144 uint64_t MRPTDLLIMPEXP _strtoull(const char *nptr, char **endptr, int base); 00145 00146 /** An OS-independent version of timegm (which is not present in all compilers): converts a time structure into an UTM time_t */ 00147 time_t MRPTDLLIMPEXP timegm(struct tm *tm); 00148 00149 /** An OS and compiler independent version of "memcpy" 00150 */ 00151 void MRPTDLLIMPEXP memcpy( 00152 void *dest, 00153 size_t destSize, 00154 const void *src, 00155 size_t copyCount ) MRPT_NO_THROWS; 00156 00157 /** An OS-independent version of getch, which waits until a key is pushed. 00158 * \return The pushed key code 00159 */ 00160 int MRPTDLLIMPEXP getch() MRPT_NO_THROWS; 00161 00162 /** An OS-independent version of kbhit, which returns true if a key has been pushed. 00163 */ 00164 bool MRPTDLLIMPEXP kbhit() MRPT_NO_THROWS; 00165 00166 } // end namespace "os" 00167 00168 /** Returns true if the number is NaN. */ 00169 bool MRPTDLLIMPEXP isNaN(float f) MRPT_NO_THROWS; 00170 00171 /** Returns true if the number is NaN. */ 00172 bool MRPTDLLIMPEXP isNaN(double f) MRPT_NO_THROWS; 00173 00174 /** Returns true if the number is non infinity. */ 00175 bool MRPTDLLIMPEXP isFinite(float f) MRPT_NO_THROWS; 00176 00177 /** Returns true if the number is non infinity. */ 00178 bool MRPTDLLIMPEXP isFinite(double f) MRPT_NO_THROWS; 00179 00180 #ifdef HAVE_LONG_DOUBLE 00181 /** Returns true if the number is NaN. */ 00182 bool MRPTDLLIMPEXP isNaN(long double f) MRPT_NO_THROWS; 00183 00184 /** Returns true if the number is non infinity. */ 00185 bool MRPTDLLIMPEXP isFinite(long double f) MRPT_NO_THROWS; 00186 #endif 00187 00188 /** Shows the message "Press any key to continue" (or other custom message) to the current standard output and returns when a key is pressed. 00189 */ 00190 void MRPTDLLIMPEXP pause(const std::string &msg = std::string("Press any key to continue...") ) MRPT_NO_THROWS; 00191 00192 /** Clears the console window */ 00193 void MRPTDLLIMPEXP clearConsole(); 00194 00195 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00196 * \return Returns false on any error, true on everything OK. 00197 */ 00198 bool MRPTDLLIMPEXP vectorToTextFile( const std::vector<float> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00199 00200 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00201 * \return Returns false on any error, true on everything OK. 00202 */ 00203 bool MRPTDLLIMPEXP vectorToTextFile( const std::vector<double> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00204 00205 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00206 * \return Returns false on any error, true on everything OK. 00207 */ 00208 bool MRPTDLLIMPEXP vectorToTextFile( const std::vector<int> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00209 00210 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00211 * \return Returns false on any error, true on everything OK. 00212 * \sa vectorToBinaryFile 00213 */ 00214 bool MRPTDLLIMPEXP vectorToTextFile( const std::vector<size_t> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00215 00216 /** Saves a vector directly as a binary dump to a file: 00217 * \return Returns false on any error, true on everything OK. 00218 * \sa loadBinaryFile 00219 */ 00220 bool MRPTDLLIMPEXP vectorToBinaryFile( const vector_byte &vec, const std::string &fileName ); 00221 00222 /** Loads a entire file as a vector of bytes. 00223 * \return Returns false on any error, true on everything OK. 00224 * \sa vectorToBinaryFile 00225 */ 00226 bool MRPTDLLIMPEXP loadBinaryFile( vector_byte &out_data, const std::string &fileName ); 00227 00228 /** Returns the MRPT compilation date 00229 */ 00230 std::string MRPTDLLIMPEXP MRPT_getCompilationDate(); 00231 00232 /** Returns a string describing the MRPT version including the SVN number. 00233 */ 00234 std::string MRPTDLLIMPEXP MRPT_getVersion(); 00235 00236 /** Call this to register handlers for fatal erros (memory access,etc) that show useful debug information (It is called automatically normally, no need for the user to explicitly call this method.). 00237 */ 00238 void MRPTDLLIMPEXP registerFatalExceptionHandlers(); 00239 00240 /** Dumps the current program stack with detailed information of source files and lines. 00241 * This function requires MRPT linked against wxWidgets. Otherwise, an empty string is returned. 00242 * File names and lines won't be available in release builds. 00243 */ 00244 std::string MRPTDLLIMPEXP stack_trace(bool calling_from_exception = false); 00245 00246 /** For use in setConsoleColor */ 00247 enum TConsoleColor 00248 { 00249 CONCOL_NORMAL = 0, 00250 CONCOL_BLUE = 1, 00251 CONCOL_GREEN = 2, 00252 CONCOL_RED = 4 00253 }; 00254 00255 /** Changes the text color in the console for the text written from now on. 00256 * The parameter "color" can be any value in TConsoleColor. 00257 * 00258 * By default the color of "cout" is changed, unless changeStdErr=true, in which case "cerr" is changed. 00259 */ 00260 void MRPTDLLIMPEXP setConsoleColor( TConsoleColor color, bool changeStdErr=false ); 00261 00262 } // End of namespace 00263 00264 } // End of namespace 00265 00266 #endif
| Page generated by Doxygen 1.6.2 for MRPT 0.8.1 SVN:exported at Mon Feb 15 22:01:07 UTC 2010 |
