Main MRPT website > C++ reference for MRPT 1.5.7
os.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef FILE_MRPT_OS_H
10 #define FILE_MRPT_OS_H
11 
12 #include <mrpt/config.h>
13 
14 #include <cstdlib>
15 #include <cstdarg>
16 
17 // Duplicated here since <mrpt/system/os.h> is the only header that cannot include "utils_defs.h"
18 #include <mrpt/base/link_pragmas.h> // DLL import/export definitions
19 
20 #include <mrpt/utils/mrpt_stdint.h>
21 #include <mrpt/utils/mrpt_macros.h>
22 
23 namespace mrpt
24 {
25  /** 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.
26  * \sa mrpt::system::os \ingroup mrpt_base_grp
27  */
28  namespace system
29  {
30  /** \defgroup mrpt_system_os OS and compiler abstraction (in #include <mrpt/system/os.h>)
31  * \ingroup mrpt_base_grp */
32 
33  /** This namespace provides a OS-independent interface to low-level functions.
34  * 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
35  * of the standard library functions (prefix "_s") are used instead. \ingroup mrpt_base_grp mrpt_system_os
36  */
37  namespace os
38  {
39  /** \addtogroup mrpt_system_os
40  * @{ */
41 
42  /** An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compilers)
43  * \sa utils::format
44  */
45  int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(3,4);
46 
47  /** An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compilers)
48  */
49  int BASE_IMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS;
50 
51  /** An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compilers)
52  */
53  int BASE_IMPEXP vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS;
54 
55  /** An OS-independent version of fopen.
56  * \return It will always return NULL on any error.
57  */
58  FILE BASE_IMPEXP *fopen(const char *fileName,const char *mode) MRPT_NO_THROWS;
59 
60  /** An OS-independent version of fopen (std::string version)
61  * \return It will always return NULL on any error.
62  */
63  FILE BASE_IMPEXP *fopen(const std::string &fileName,const char *mode) MRPT_NO_THROWS;
64 
65  /** An OS-independent version of fprintf
66  */
67  int BASE_IMPEXP fprintf(FILE *fil, const char *format, ...) MRPT_NO_THROWS MRPT_printf_format_check(2,3);
68 
69  /** An OS-independent version of fclose.
70  * \exception std::exception On trying to close a NULL file descriptor.
71  */
72  void BASE_IMPEXP fclose(FILE *f);
73 
74  /** An OS-independent version of strcat.
75  * \return It will always return the "dest" pointer.
76  */
77  char BASE_IMPEXP * strcat(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS;
78 
79  /** An OS-independent version of strcpy.
80  * \return It will always return the "dest" pointer.
81  */
82  char BASE_IMPEXP *strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS;
83 
84  /** An OS-independent version of strcmp.
85  * \return It will return 0 when both strings are equal, casi sensitive.
86  */
87  int BASE_IMPEXP _strcmp(const char*str1,const char*str2) MRPT_NO_THROWS;
88 
89  /** An OS-independent version of strcmpi.
90  * \return It will return 0 when both strings are equal, casi insensitive.
91  */
92  int BASE_IMPEXP _strcmpi(const char*str1,const char*str2) MRPT_NO_THROWS;
93 
94  /** An OS-independent version of strncmp.
95  * \return It will return 0 when both strings are equal, casi sensitive.
96  */
97  int BASE_IMPEXP _strncmp(const char*str,const char*subStr,size_t count) MRPT_NO_THROWS;
98 
99  /** An OS-independent version of strnicmp.
100  * \return It will return 0 when both strings are equal, casi insensitive.
101  */
102  int BASE_IMPEXP _strnicmp(const char*str,const char*subStr,size_t count) MRPT_NO_THROWS;
103 
104  /** An OS-independent version of strtoll.
105  */
106  int64_t BASE_IMPEXP _strtoll(const char *nptr, char **endptr, int base);
107 
108  /** An OS-independent version of strtoull.
109  */
110  uint64_t BASE_IMPEXP _strtoull(const char *nptr, char **endptr, int base);
111 
112  /** An OS-independent version of timegm (which is not present in all compilers): converts a time structure into an UTM time_t */
113  time_t BASE_IMPEXP timegm(struct tm *tm);
114 
115  /** An OS and compiler independent version of "memcpy"
116  */
117  void BASE_IMPEXP memcpy(
118  void *dest,
119  size_t destSize,
120  const void *src,
121  size_t copyCount) MRPT_NO_THROWS;
122 
123  /** An OS-independent version of getch, which waits until a key is pushed.
124  * \return The pushed key code
125  */
127 
128  /** An OS-independent version of kbhit, which returns true if a key has been pushed.
129  */
131 
132  /** @} */
133 
134  } // end namespace "os"
135 
136  /** \addtogroup mrpt_system_os
137  * @{ */
138 
139  /** Shows the message "Press any key to continue" (or other custom message) to the current standard output and returns when a key is pressed */
140  void BASE_IMPEXP pause(const std::string &msg = std::string("Press any key to continue...")) MRPT_NO_THROWS;
141 
142  /** Clears the console window */
143  void BASE_IMPEXP clearConsole();
144 
145  /** Returns the MRPT source code timestamp, according to the Reproducible-Builds specifications: https://reproducible-builds.org/specs/source-date-epoch/ */
147 
148  /** Returns a string describing the MRPT version */
149  std::string BASE_IMPEXP MRPT_getVersion();
150 
151  /** Returns a const ref to a text with the same text that appears at the beginning of each MRPT file (useful for displaying the License text in GUIs) */
152  const std::string BASE_IMPEXP & getMRPTLicense();
153 
154  /** Finds the "[MRPT]/share/mrpt/" directory, if available in the system. This searches in (1) source code tree, (2) install target paths. */
156 
157  /** For use in setConsoleColor */
159  {
164  };
165 
166  /** Changes the text color in the console for the text written from now on.
167  * The parameter "color" can be any value in TConsoleColor.
168  *
169  * By default the color of "cout" is changed, unless changeStdErr=true, in which case "cerr" is changed.
170  */
171  void BASE_IMPEXP setConsoleColor(TConsoleColor color, bool changeStdErr=false);
172 
173  /** @brief Execute Generic Shell Command
174  *
175  * @param[in] command Command to execute
176  * @param[out] output Pointer to string containing the shell output
177  * @param[in] mode read/write access
178  *
179  * @return 0 for success, -1 otherwise.
180  *
181  * \note Original code snippet found in http://stackoverflow.com/a/30357710
182  */
184  const std::string& command,
185  std::string* output=NULL,
186  const std::string& mode="r");
187 
188 
189  /** @} */
190 
191  } // End of namespace
192 
193 } // End of namespace
194 
195 #endif
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358
GLuint GLuint GLsizei count
Definition: glext.h:3512
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
Definition: os.cpp:255
int BASE_IMPEXP vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS
An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compil...
Definition: os.cpp:229
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:272
void BASE_IMPEXP pause(const std::string &msg=std::string("Press any key to continue...")) MRPT_NO_THROWS
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
Definition: os.cpp:435
time_t BASE_IMPEXP timegm(struct tm *tm)
An OS-independent version of timegm (which is not present in all compilers): converts a time structur...
Definition: os.cpp:116
void BASE_IMPEXP setConsoleColor(TConsoleColor color, bool changeStdErr=false)
Changes the text color in the console for the text written from now on.
Definition: os.cpp:489
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations.
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:412
STL namespace.
std::string BASE_IMPEXP MRPT_getCompilationDate()
Returns the MRPT source code timestamp, according to the Reproducible-Builds specifications: https://...
Definition: os.cpp:157
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy.
Definition: os.cpp:296
GLuint src
Definition: glext.h:6303
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
std::string BASE_IMPEXP find_mrpt_shared_dir()
Finds the "[MRPT]/share/mrpt/" directory, if available in the system.
Definition: os.cpp:557
int BASE_IMPEXP executeCommand(const std::string &command, std::string *output=NULL, const std::string &mode="r")
Execute Generic Shell Command.
Definition: os.cpp:603
GLuint color
Definition: glext.h:7093
int BASE_IMPEXP getch() MRPT_NO_THROWS
An OS-independent version of getch, which waits until a key is pushed.
Definition: os.cpp:375
__int64 int64_t
Definition: rptypes.h:51
void BASE_IMPEXP clearConsole()
Clears the console window.
Definition: os.cpp:444
TConsoleColor
For use in setConsoleColor.
Definition: os.h:158
GLsizei const GLchar ** string
Definition: glext.h:3919
GLint mode
Definition: glext.h:5078
unsigned __int64 uint64_t
Definition: rptypes.h:52
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool BASE_IMPEXP kbhit() MRPT_NO_THROWS
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:396
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
Definition: os.cpp:320
GLsizei GLsizei GLchar * source
Definition: glext.h:3908
uint64_t BASE_IMPEXP _strtoull(const char *nptr, char **endptr, int base)
An OS-independent version of strtoull.
Definition: os.cpp:472
char BASE_IMPEXP * strcat(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcat.
Definition: os.cpp:281
GLuint GLsizei bufSize
Definition: glext.h:3900
int BASE_IMPEXP int BASE_IMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS
An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compile...
Definition: os.cpp:214
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191
GLenum GLsizei GLenum format
Definition: glext.h:3513
std::string BASE_IMPEXP MRPT_getVersion()
Returns a string describing the MRPT version.
Definition: os.cpp:183
int64_t BASE_IMPEXP _strtoll(const char *nptr, char **endptr, int base)
An OS-independent version of strtoll.
Definition: os.cpp:459
int BASE_IMPEXP _strcmp(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmp.
Definition: os.cpp:312
int BASE_IMPEXP _strnicmp(const char *str, const char *subStr, size_t count) MRPT_NO_THROWS
An OS-independent version of strnicmp.
Definition: os.cpp:344
const std::string BASE_IMPEXP & getMRPTLicense()
Returns a const ref to a text with the same text that appears at the beginning of each MRPT file (use...
Definition: os.cpp:535
int BASE_IMPEXP _strncmp(const char *str, const char *subStr, size_t count) MRPT_NO_THROWS
An OS-independent version of strncmp.
Definition: os.cpp:336



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019