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