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 FILE_MRPT_OS_H 00029 #define FILE_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 #include <mrpt/base/link_pragmas.h> // DLL import/export definitions 00041 00042 #include <mrpt/utils/types.h> // This must be AFTER <utils_impexp.h> 00043 00044 // Define a decl. modifier for printf-like format checks at compile time: 00045 #ifdef __GNUC__ 00046 # define MRPT_printf_format_check(_FMT_,_VARARGS_) __attribute__ ((__format__ (__printf__, _FMT_,_VARARGS_))) 00047 #else 00048 # define MRPT_printf_format_check(_FMT_,_VARARGS_) 00049 #endif 00050 00051 // Define a decl. modifier for scanf-like format checks at compile time: 00052 #ifdef __GNUC__ 00053 # define MRPT_scanf_format_check(_FMT_,_VARARGS_) __attribute__ ((__format__ (__scanf__, _FMT_,_VARARGS_))) 00054 #else 00055 # define MRPT_scanf_format_check(_FMT_,_VARARGS_) 00056 #endif 00057 00058 00059 /** Used after member declarations */ 00060 #define MRPT_NO_THROWS throw() 00061 00062 /** Represents an invalid timestamp, where applicable. 00063 */ 00064 #define INVALID_TIMESTAMP (0) 00065 00066 namespace mrpt 00067 { 00068 /** 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. 00069 * \sa mrpt::system::os 00070 */ 00071 namespace system 00072 { 00073 /** This namespace provides a OS-independent interface to low-level functions. 00074 * 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 00075 * of the standard library functions (prefix "_s") are used instead. 00076 */ 00077 namespace os 00078 { 00079 /** An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compilers) 00080 * \sa utils::format 00081 */ 00082 int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(3,4); 00083 00084 /** An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compilers) 00085 */ 00086 int BASE_IMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS; 00087 00088 /** An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compilers) 00089 */ 00090 int BASE_IMPEXP vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS; 00091 00092 /** An OS-independent version of fopen. 00093 * \return It will always return NULL on any error. 00094 */ 00095 FILE BASE_IMPEXP *fopen(const char *fileName,const char *mode) MRPT_NO_THROWS; 00096 00097 /** An OS-independent version of fopen (std::string version) 00098 * \return It will always return NULL on any error. 00099 */ 00100 FILE BASE_IMPEXP *fopen(const std::string &fileName,const char *mode) MRPT_NO_THROWS; 00101 00102 /** An OS-independent version of fprintf 00103 */ 00104 int BASE_IMPEXP fprintf(FILE *fil, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(2,3); 00105 00106 /** An OS-independent version of fscanf 00107 * \return The number of fields correctly assigned 00108 */ 00109 //int BASE_IMPEXP fscanf(FILE *fil, const char *format, ...) MRPT_NO_THROWS MRPT_scanf_format_check(2,3); 00110 00111 /** An OS-independent version of fclose. 00112 * \exception std::exception On trying to close a NULL file descriptor. 00113 */ 00114 void BASE_IMPEXP fclose(FILE *f); 00115 00116 /** An OS-independent version of strcat. 00117 * \return It will always return the "dest" pointer. 00118 */ 00119 char BASE_IMPEXP * strcat(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS; 00120 00121 /** An OS-independent version of strcpy. 00122 * \return It will always return the "dest" pointer. 00123 */ 00124 char BASE_IMPEXP *strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS; 00125 00126 /** An OS-independent version of strcmp. 00127 * \return It will return 0 when both strings are equal, casi sensitive. 00128 */ 00129 int BASE_IMPEXP _strcmp(const char*str1,const char*str2) MRPT_NO_THROWS; 00130 00131 /** An OS-independent version of strcmpi. 00132 * \return It will return 0 when both strings are equal, casi insensitive. 00133 */ 00134 int BASE_IMPEXP _strcmpi(const char*str1,const char*str2) MRPT_NO_THROWS; 00135 00136 /** An OS-independent version of strtoll. 00137 */ 00138 int64_t BASE_IMPEXP _strtoll(const char *nptr, char **endptr, int base); 00139 00140 /** An OS-independent version of strtoull. 00141 */ 00142 uint64_t BASE_IMPEXP _strtoull(const char *nptr, char **endptr, int base); 00143 00144 /** An OS-independent version of timegm (which is not present in all compilers): converts a time structure into an UTM time_t */ 00145 time_t BASE_IMPEXP timegm(struct tm *tm); 00146 00147 /** An OS and compiler independent version of "memcpy" 00148 */ 00149 void BASE_IMPEXP memcpy( 00150 void *dest, 00151 size_t destSize, 00152 const void *src, 00153 size_t copyCount ) MRPT_NO_THROWS; 00154 00155 /** An OS-independent version of getch, which waits until a key is pushed. 00156 * \return The pushed key code 00157 */ 00158 int BASE_IMPEXP getch() MRPT_NO_THROWS; 00159 00160 /** An OS-independent version of kbhit, which returns true if a key has been pushed. 00161 */ 00162 bool BASE_IMPEXP kbhit() MRPT_NO_THROWS; 00163 00164 } // end namespace "os" 00165 00166 /** Shows the message "Press any key to continue" (or other custom message) to the current standard output and returns when a key is pressed. 00167 */ 00168 void BASE_IMPEXP pause(const std::string &msg = std::string("Press any key to continue...") ) MRPT_NO_THROWS; 00169 00170 /** Clears the console window */ 00171 void BASE_IMPEXP clearConsole(); 00172 00173 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00174 * \return Returns false on any error, true on everything OK. 00175 */ 00176 bool BASE_IMPEXP vectorToTextFile( const std::vector<float> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00177 00178 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00179 * \return Returns false on any error, true on everything OK. 00180 */ 00181 bool BASE_IMPEXP vectorToTextFile( const std::vector<double> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00182 00183 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00184 * \return Returns false on any error, true on everything OK. 00185 */ 00186 bool BASE_IMPEXP vectorToTextFile( const std::vector<int> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00187 00188 /** A useful function for debuging, which saves a std::vector into a text file (compat. with MATLAB) 00189 * \return Returns false on any error, true on everything OK. 00190 * \sa vectorToBinaryFile 00191 */ 00192 bool BASE_IMPEXP vectorToTextFile( const std::vector<size_t> &vec, const std::string &fileName, bool append = false, bool byRows=false ); 00193 00194 /** Saves a vector directly as a binary dump to a file: 00195 * \return Returns false on any error, true on everything OK. 00196 * \sa loadBinaryFile 00197 */ 00198 bool BASE_IMPEXP vectorToBinaryFile( const vector_byte &vec, const std::string &fileName ); 00199 00200 /** Loads a entire file as a vector of bytes. 00201 * \return Returns false on any error, true on everything OK. 00202 * \sa vectorToBinaryFile 00203 */ 00204 bool BASE_IMPEXP loadBinaryFile( vector_byte &out_data, const std::string &fileName ); 00205 00206 /** Returns the MRPT compilation date 00207 */ 00208 std::string BASE_IMPEXP MRPT_getCompilationDate(); 00209 00210 /** Returns a string describing the MRPT version including the SVN number. 00211 */ 00212 std::string BASE_IMPEXP MRPT_getVersion(); 00213 00214 /** 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.). 00215 */ 00216 void BASE_IMPEXP registerFatalExceptionHandlers(); 00217 00218 /** Dumps the current program stack with detailed information of source files and lines. 00219 * This function requires MRPT linked against wxWidgets. Otherwise, an empty string is returned. 00220 * File names and lines won't be available in release builds. 00221 */ 00222 std::string BASE_IMPEXP stack_trace(bool calling_from_exception = false); 00223 00224 /** For use in setConsoleColor */ 00225 enum TConsoleColor 00226 { 00227 CONCOL_NORMAL = 0, 00228 CONCOL_BLUE = 1, 00229 CONCOL_GREEN = 2, 00230 CONCOL_RED = 4 00231 }; 00232 00233 /** Changes the text color in the console for the text written from now on. 00234 * The parameter "color" can be any value in TConsoleColor. 00235 * 00236 * By default the color of "cout" is changed, unless changeStdErr=true, in which case "cerr" is changed. 00237 */ 00238 void BASE_IMPEXP setConsoleColor( TConsoleColor color, bool changeStdErr=false ); 00239 00240 } // End of namespace 00241 00242 } // End of namespace 00243 00244 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
