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