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.
- See also
- mrpt::system::os
|
std::string | MRPT_getVersion () |
| Returns a string describing the MRPT version. More...
|
|
void | getCallStackBackTrace (TCallStackBackTrace &out_bt) |
| Returns a list of strings representing the current call stack backtrace. More...
|
|
mrpt::system::TTimeStamp | buildTimestampFromParts (const mrpt::system::TTimeParts &p) |
| Builds a timestamp from the parts (Parts are in UTC) More...
|
|
mrpt::system::TTimeStamp | buildTimestampFromPartsLocalTime (const mrpt::system::TTimeParts &p) |
| Builds a timestamp from the parts (Parts are in local time) More...
|
|
void | timestampToParts (TTimeStamp t, TTimeParts &p, bool localTime=false) |
| Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time. More...
|
|
mrpt::system::TTimeStamp | getCurrentTime () |
| Returns the current (UTC) system time. More...
|
|
mrpt::system::TTimeStamp | now () |
| A shortcut for system::getCurrentTime. More...
|
|
mrpt::system::TTimeStamp | getCurrentLocalTime () |
| Returns the current (local) time. More...
|
|
mrpt::system::TTimeStamp | time_tToTimestamp (const double t) |
| Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to TTimeStamp. More...
|
|
mrpt::system::TTimeStamp | time_tToTimestamp (const time_t &t) |
| Transform from standard "time_t" to TTimeStamp. More...
|
|
double | timestampTotime_t (const mrpt::system::TTimeStamp t) |
| Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds). More...
|
|
double | timestampToDouble (const mrpt::system::TTimeStamp t) |
| Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds). More...
|
|
double | timeDifference (const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later) |
| Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds. More...
|
|
double | now_double () |
| Returns the current time, as a double (fractional version of time_t) instead of a TTimeStamp . More...
|
|
mrpt::system::TTimeStamp | timestampAdd (const mrpt::system::TTimeStamp tim, const double num_seconds) |
| Shifts a timestamp the given amount of seconds (>0: forwards in time, <0: backwards) More...
|
|
mrpt::system::TTimeStamp | secondsToTimestamp (const double nSeconds) |
| Transform a time interval (in seconds) into TTimeStamp (e.g. More...
|
|
std::string | formatTimeInterval (const double timeSeconds) |
| Returns a formated string with the given time difference (passed as the number of seconds), as a string [H]H:MM:SS.MILISECS. More...
|
|
std::string | dateTimeToString (const mrpt::system::TTimeStamp t) |
| Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM. More...
|
|
std::string | dateTimeLocalToString (const mrpt::system::TTimeStamp t) |
| Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM. More...
|
|
std::string | dateToString (const mrpt::system::TTimeStamp t) |
| Convert a timestamp into this textual form: YEAR/MONTH/DAY. More...
|
|
double | extractDayTimeFromTimestamp (const mrpt::system::TTimeStamp t) |
| Returns the number of seconds ellapsed from midnight in the given timestamp. More...
|
|
std::string | timeToString (const mrpt::system::TTimeStamp t) |
| Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM. More...
|
|
std::string | timeLocalToString (const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits=6) |
| Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM. More...
|
|
std::string | intervalFormat (const double seconds) |
| This function implements time interval formatting: Given a time in seconds, it will return a string describing the interval with the most appropriate unit. More...
|
|
std::string | getTempFileName () |
| Returns the name of a proposed temporary file name. More...
|
|
std::string | getcwd () |
| Returns the current working directory. More...
|
|
std::string | getShareMRPTDir () |
| Attempts to find the directory [PREFIX/]share/mrpt/ and returns its absolute path, or empty string if not found. More...
|
|
bool | createDirectory (const std::string &dirName) |
| Creates a directory. More...
|
|
bool | deleteFile (const std::string &fileName) |
| Deletes a single file. More...
|
|
void | deleteFiles (const std::string &s) |
| Delete one or more files, especified by the (optional) path and the file name (including '?' or '*') - Use forward slash ('/') for directories for compatibility between Windows and Linux, since they will be internally traslated into backward slashes ('\') if MRPT is compiled under Windows. More...
|
|
bool | renameFile (const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=nullptr) |
| Renames a file - If the target path is different and the filesystem allows it, it will be moved to the new location. More...
|
|
bool | deleteFilesInDirectory (const std::string &s, bool deleteDirectoryAsWell=false) |
| Delete all the files in a given directory (nothing done if directory does not exists, or path is a file). More...
|
|
std::string | extractFileName (const std::string &filePath) |
| Extract just the name (without extension) of a filename from a complete path plus name plus extension. More...
|
|
std::string | extractFileExtension (const std::string &filePath, bool ignore_gz=false) |
| Extract the extension of a filename. More...
|
|
std::string | extractFileDirectory (const std::string &filePath) |
| Extract the whole path (the directory) of a filename from a complete path plus name plus extension. More...
|
|
bool | fileExists (const std::string &fileName) |
| Test if a given file (or directory) exists. More...
|
|
bool | directoryExists (const std::string &fileName) |
| Test if a given directory exists (it fails if the given path refers to an existing file). More...
|
|
std::string | fileNameStripInvalidChars (const std::string &filename, const char replacement_to_invalid_chars='_') |
| Replace invalid filename chars by underscores ('_') or any other user-given char. More...
|
|
std::string | fileNameChangeExtension (const std::string &filename, const std::string &newExtension) |
| Replace the filename extension by another one. More...
|
|
uint64_t | getFileSize (const std::string &fileName) |
| Return the size of the given file, or size_t(-1) if some error is found accessing that file. More...
|
|
time_t | getFileModificationTime (const std::string &filename) |
| Return the time of the file last modification, or "0" if the file doesn't exist. More...
|
|
std::string | filePathSeparatorsToNative (const std::string &filePath) |
| Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'. More...
|
|
bool | copyFile (const std::string &sourceFile, const std::string &targetFile, std::string *outErrStr=nullptr, bool copyAttribs=true) |
| Copies file sourceFile to targetFile. More...
|
|
unsigned long | getMemoryUsage () |
| Returns the memory occupied by this process, in bytes. More...
|
|
template<int bytes> |
bool | is_aligned (const void *ptr) |
|
template<> |
bool | is_aligned< 8 > (const void *ptr) |
|
template<> |
bool | is_aligned< 16 > (const void *ptr) |
|
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 output and returns when a key is pressed. More...
|
|
void | clearConsole () |
| Clears the console window. More...
|
|
std::string | MRPT_getCompilationDate () |
| Returns the MRPT source code timestamp, according to the Reproducible-Builds specifications: https://reproducible-builds.org/specs/source-date-epoch/. More...
|
|
const std::string & | getMRPTLicense () |
| 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) More...
|
|
std::string | find_mrpt_shared_dir () |
| Finds the "[MRPT]/share/mrpt/" directory, if available in the system. More...
|
|
void | setConsoleColor (TConsoleColor color, bool changeStdErr=false) |
| Changes the text color in the console for the text written from now on. More...
|
|
int | executeCommand (const std::string &command, std::string *output=NULL, const std::string &mode="r") |
| Execute Generic Shell Command. More...
|
|
bool | launchProcess (const std::string &command) |
| Executes the given command (which may contain a program + arguments), and waits until it finishes. More...
|
|
char * | strtok (char *str, const char *strDelimit, char **context) noexcept |
| An OS-independent method for tokenizing a string. More...
|
|
void | tokenize (const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) noexcept |
| Tokenizes a string according to a set of delimiting characters. More...
|
|
void | tokenize (const std::string &inString, const std::string &inDelimiters, std::vector< std::string > &outTokens, bool skipBlankTokens=true) noexcept |
|
std::string | trim (const std::string &str) |
| Removes leading and trailing spaces. More...
|
|
std::string | upperCase (const std::string &str) |
| Returns a upper-case version of a string. More...
|
|
std::string | lowerCase (const std::string &str) |
| Returns an lower-case version of a string. More...
|
|
void | decodeUTF8 (const std::string &strUTF8, vector_word &out_uniStr) |
| Decodes a UTF-8 string into an UNICODE string. More...
|
|
void | encodeUTF8 (const vector_word &input, std::string &output) |
| Encodes a 2-bytes UNICODE string into a UTF-8 string. More...
|
|
void | encodeBase64 (const vector_byte &inputData, std::string &outString) |
| Encode a sequence of bytes as a string in base-64. More...
|
|
bool | decodeBase64 (const std::string &inString, vector_byte &outData) |
| Decode a base-64 string into the original sequence of bytes. More...
|
|
std::string | unitsFormat (const double val, int nDecimalDigits=2, bool middle_space=true) |
| This function implements formatting with the appropriate SI metric unit prefix: 1e-12->'p', 1e-9->'n', 1e-6->'u', 1e-3->'m', 1->'', 1e3->'K', 1e6->'M', 1e9->'G', 1e12->'T'. More...
|
|
std::string | rightPad (const std::string &str, const size_t total_len, bool truncate_if_larger=false) |
| Enlarge the string with spaces up to the given length. More...
|
|
bool | strCmp (const std::string &s1, const std::string &s2) |
| Return true if the two strings are equal (case sensitive) More...
|
|
bool | strCmpI (const std::string &s1, const std::string &s2) |
| Return true if the two strings are equal (case insensitive) More...
|
|
bool | strStarts (const std::string &str, const std::string &subStr) |
| Return true if "str" starts with "subStr" (case sensitive) More...
|
|
bool | strStartsI (const std::string &str, const std::string &subStr) |
| Return true if "str" starts with "subStr" (case insensitive) More...
|
|
template<typename T > |
std::string | sprintf_container (const char *fmt, const T &V) |
| Generates a string for a container in the format [A,B,C,...], and the fmt string for each vector element. More...
|
|
bool | vectorToTextFile (const std::vector< float > &vec, const std::string &fileName, bool append=false, bool byRows=false) |
| A useful function for debugging, which saves a std::vector into a text file (compat. More...
|
|
bool | vectorToTextFile (const std::vector< double > &vec, const std::string &fileName, bool append=false, bool byRows=false) |
|
bool | vectorToTextFile (const std::vector< int > &vec, const std::string &fileName, bool append=false, bool byRows=false) |
|
bool | vectorToTextFile (const std::vector< size_t > &vec, const std::string &fileName, bool append=false, bool byRows=false) |
|
template<class EIGEN_MATRIX > |
bool | vectorToTextFile (const EIGEN_MATRIX &vec, const std::string &fileName) |
|
bool | vectorFromTextFile (std::vector< double > &vec, const std::string &fileName, const bool byRows=false) |
| Load a std::vector from a text file (compat. More...
|
|
bool | vectorToBinaryFile (const vector_byte &vec, const std::string &fileName) |
| Saves a vector directly as a binary dump to a file: More...
|
|
bool | loadBinaryFile (vector_byte &out_data, const std::string &fileName) |
| Loads a entire file as a vector of bytes. More...
|
|
|
template<typename T > |
T | str2num (std::string const &value) |
| Original code snippet found in http://stackoverflow.com/a/30357710. More...
|
|
template<typename T > |
std::string | num2str (T const &value) |
| Convert number instance to string. More...
|
|