Main MRPT website > C++ reference for MRPT 1.9.9
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
18 // include "utils_defs.h"
19 
20 #include <cstdint>
21 #include <mrpt/utils/mrpt_macros.h>
22 
23 namespace mrpt
24 {
25 /** This namespace provides a OS-independent interface to many useful functions:
26  * filenames manipulation, time and date, string parsing, file I/O, threading,
27  * memory allocation, etc.
28  * \sa mrpt::system::os \ingroup mrpt_base_grp
29  */
30 namespace system
31 {
32 /** \defgroup mrpt_system_os OS and compiler abstraction (in #include
33  * <mrpt/system/os.h>)
34  * \ingroup mrpt_base_grp */
35 
36 /** This namespace provides a OS-independent interface to low-level functions.
37  * Most of these functions are converted into calls to standard functions,
38  * unless we are into Visual Studio 2005 (or newer). In that case the secure
39  * version
40  * of the standard library functions (prefix "_s") are used instead.
41  * \ingroup mrpt_base_grp mrpt_system_os
42  */
43 namespace os
44 {
45 /** \addtogroup mrpt_system_os
46  * @{ */
47 
48 /** An OS-independent version of sprintf (Notice the bufSize param, which may be
49  * ignored in some compilers)
50  * \sa utils::format
51  */
52 int sprintf(
53  char* buf, size_t bufSize, const char* format,
54  ...) noexcept MRPT_printf_format_check(3, 4);
55 
56 /** An OS-independent version of vsprintf (Notice the bufSize param, which may
57  * be ignored in some compilers)
58  */
59 int vsprintf(
60  char* buf, size_t bufSize, const char* format, va_list args) noexcept;
61 
62 /** An OS-independent version of vsnprintf (Notice the bufSize param, which may
63  * be ignored in some compilers)
64  */
65 int vsnprintf(
66  char* buf, size_t bufSize, const char* format, va_list args) noexcept;
67 
68 /** An OS-independent version of fopen.
69  * \return It will always return nullptr on any error.
70  */
71 FILE* fopen(const char* fileName, const char* mode) noexcept;
72 
73 /** An OS-independent version of fopen (std::string version)
74  * \return It will always return nullptr on any error.
75  */
76 FILE* fopen(const std::string& fileName, const char* mode) noexcept;
77 
78 /** An OS-independent version of fprintf
79  */
80 int fprintf(
81  FILE* fil, const char* format, ...) noexcept MRPT_printf_format_check(2, 3);
82 
83 /** An OS-independent version of fclose.
84  * \exception std::exception On trying to close a nullptr file descriptor.
85  */
86 void fclose(FILE* f);
87 
88 /** An OS-independent version of strcat.
89  * \return It will always return the "dest" pointer.
90  */
91 char* strcat(char* dest, size_t destSize, const char* source) noexcept;
92 
93 /** An OS-independent version of strcpy.
94  * \return It will always return the "dest" pointer.
95  */
96 char* strcpy(char* dest, size_t destSize, const char* source) noexcept;
97 
98 /** An OS-independent version of strcmp.
99  * \return It will return 0 when both strings are equal, casi sensitive.
100  */
101 int _strcmp(const char* str1, const char* str2) noexcept;
102 
103 /** An OS-independent version of strcmpi.
104  * \return It will return 0 when both strings are equal, casi insensitive.
105  */
106 int _strcmpi(const char* str1, const char* str2) noexcept;
107 
108 /** An OS-independent version of strncmp.
109  * \return It will return 0 when both strings are equal, casi sensitive.
110  */
111 int _strncmp(const char* str, const char* subStr, size_t count) noexcept;
112 
113 /** An OS-independent version of strnicmp.
114  * \return It will return 0 when both strings are equal, casi insensitive.
115  */
116 int _strnicmp(const char* str, const char* subStr, size_t count) noexcept;
117 
118 /** An OS-independent version of strtoll.
119  */
120 int64_t _strtoll(const char* nptr, char** endptr, int base);
121 
122 /** An OS-independent version of strtoull.
123  */
124 uint64_t _strtoull(const char* nptr, char** endptr, int base);
125 
126 /** An OS-independent version of timegm (which is not present in all compilers):
127  * converts a time structure into an UTM time_t */
128 time_t timegm(struct tm* tm);
129 
130 /** An OS and compiler independent version of "memcpy"
131  */
132 void memcpy(
133  void* dest, size_t destSize, const void* src, size_t copyCount) noexcept;
134 
135 /** An OS-independent version of getch, which waits until a key is pushed.
136  * \return The pushed key code
137  */
138 int getch() noexcept;
139 
140 /** An OS-independent version of kbhit, which returns true if a key has been
141  * pushed.
142  */
143 bool kbhit() noexcept;
144 
145 /** @} */
146 
147 } // end namespace "os"
148 
149 /** \addtogroup mrpt_system_os
150  * @{ */
151 
152 /** Shows the message "Press any key to continue" (or other custom message) to
153  * the current standard output and returns when a key is pressed */
154 void pause(
155  const std::string& msg =
156  std::string("Press any key to continue...")) noexcept;
157 
158 /** Clears the console window */
159 void clearConsole();
160 
161 /** Returns the MRPT source code timestamp, according to the Reproducible-Builds
162  * specifications: https://reproducible-builds.org/specs/source-date-epoch/ */
163 std::string MRPT_getCompilationDate();
164 
165 /** Returns a string describing the MRPT version */
166 std::string MRPT_getVersion();
167 
168 /** Returns a const ref to a text with the same text that appears at the
169  * beginning of each MRPT file (useful for displaying the License text in GUIs)
170  */
171 const std::string& getMRPTLicense();
172 
173 /** Finds the "[MRPT]/share/mrpt/" directory, if available in the system. This
174  * searches in (1) source code tree, (2) install target paths. */
175 std::string find_mrpt_shared_dir();
176 
177 /** For use in setConsoleColor */
179 {
184 };
185 
186 /** Changes the text color in the console for the text written from now on.
187  * The parameter "color" can be any value in TConsoleColor.
188  *
189  * By default the color of "cout" is changed, unless changeStdErr=true, in
190  * which case "cerr" is changed.
191  */
192 void setConsoleColor(TConsoleColor color, bool changeStdErr = false);
193 
194 /** @brief Execute Generic Shell Command
195  *
196  * @param[in] command Command to execute
197  * @param[out] output Pointer to string containing the shell output
198  * @param[in] mode read/write access
199  *
200  * @return 0 for success, -1 otherwise.
201  *
202  * \note Original code snippet found in http://stackoverflow.com/a/30357710
203  */
204 int executeCommand(
205  const std::string& command, std::string* output = NULL,
206  const std::string& mode = "r");
207 
208 /** Executes the given command (which may contain a program + arguments), and
209 waits until it finishes.
210 
211 * \return false on any error, true otherwise
212 
213 */
214 bool launchProcess(const std::string& command);
215 
216 /** @} */
217 
218 } // End of namespace
219 
220 } // End of namespace
221 
222 #endif
GLuint GLuint GLsizei count
Definition: glext.h:3528
int getch() noexcept
An OS-independent version of getch, which waits until a key is pushed.
Definition: os.cpp:369
int _strncmp(const char *str, const char *subStr, size_t count) noexcept
An OS-independent version of strncmp.
Definition: os.cpp:335
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:272
time_t timegm(struct tm *tm)
An OS-independent version of timegm (which is not present in all compilers): converts a time structur...
Definition: os.cpp:109
int _strnicmp(const char *str, const char *subStr, size_t count) noexcept
An OS-independent version of strnicmp.
Definition: os.cpp:343
void setConsoleColor(TConsoleColor color, bool changeStdErr=false)
Changes the text color in the console for the text written from now on.
Definition: os.cpp:479
STL namespace.
std::string MRPT_getCompilationDate()
Returns the MRPT source code timestamp, according to the Reproducible-Builds specifications: https://...
Definition: os.cpp:151
GLuint src
Definition: glext.h:7278
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
std::string find_mrpt_shared_dir()
Finds the "[MRPT]/share/mrpt/" directory, if available in the system.
Definition: os.cpp:612
int executeCommand(const std::string &command, std::string *output=NULL, const std::string &mode="r")
Execute Generic Shell Command.
Definition: os.cpp:661
GLuint color
Definition: glext.h:8300
__int64 int64_t
Definition: rptypes.h:49
void clearConsole()
Clears the console window.
Definition: os.cpp:436
TConsoleColor
For use in setConsoleColor.
Definition: os.h:178
GLsizei const GLchar ** string
Definition: glext.h:4101
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:405
void pause(const std::string &msg=std::string("Press any key to continue...")) noexcept
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
Definition: os.cpp:427
GLint mode
Definition: glext.h:5669
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) noexcept
An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compil...
Definition: os.cpp:227
int int vsprintf(char *buf, size_t bufSize, const char *format, va_list args) noexcept
An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compile...
Definition: os.cpp:211
char * strcat(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcat.
Definition: os.cpp:281
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:389
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
uint64_t _strtoull(const char *nptr, char **endptr, int base)
An OS-independent version of strtoull.
Definition: os.cpp:463
GLuint GLsizei bufSize
Definition: glext.h:4064
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:254
GLenum GLsizei GLenum format
Definition: glext.h:3531
std::string MRPT_getVersion()
Returns a string describing the MRPT version.
Definition: os.cpp:184
int64_t _strtoll(const char *nptr, char **endptr, int base)
An OS-independent version of strtoll.
Definition: os.cpp:451
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
Definition: os.cpp:296
bool launchProcess(const std::string &command)
Executes the given command (which may contain a program + arguments), and waits until it finishes...
Definition: os.cpp:559
const std::string & 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:531
int _strcmp(const char *str1, const char *str2) noexcept
An OS-independent version of strcmp.
Definition: os.cpp:311
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept 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:188
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:355
int _strcmpi(const char *str1, const char *str2) noexcept
An OS-independent version of strcmpi.
Definition: os.cpp:319



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019