namespace mrpt::system
System helpers and utilities.
namespace system { // namespaces namespace mrpt::system::os; // typedefs typedef std::function<void(std::string_view msg, const mrpt::system::VerbosityLevel level, std::string_view loggerName, const mrpt::Clock::time_point timestamp)> output_logger_callback_t; typedef mrpt::Clock::time_point TTimeStamp; // enums enum ConsoleBackgroundColor; enum ConsoleForegroundColor; enum ConsoleTextStyle; enum TProcessPriority; enum TThreadPriority; enum VerbosityLevel; // structs struct COutputLoggerStreamWrapper; struct CTimeLoggerEntry; struct CTimeLoggerSaveAtDtor; struct TTimeParts; // classes class CConsoleRedirector; class CControlledRateTimer; class CDirectoryExplorer; class CFileSystemWatcher; template <class DATA_PARAMS, class POOLABLE_DATA> class CGenericMemoryPool; class CObservable; class CObserver; class COutputLogger; class CRateTimer; class CTicTac; class CTimeLogger; class WorkerThreadsPool; class mrptEvent; class mrptEventOnDestroy; // global functions void global_profiler_enter(const char* func_name); void global_profiler_leave(const char* func_name); mrpt::system::CTimeLogger& global_profiler_getref(); template <typename T> T str2num(std::string const& value); uint16_t compute_CRC16(const std::vector<uint8_t>& data, const uint16_t gen_pol = 0x8005); uint16_t compute_CRC16(const uint8_t* data, size_t len, const uint16_t gen_pol = 0x8005); uint32_t compute_CRC32( const std::vector<uint8_t>& data, const uint32_t gen_pol = 0xEDB88320L ); uint32_t compute_CRC32(const uint8_t* data, size_t len, const uint32_t gen_pol = 0xEDB88320L); const TTimeStamp& InvalidTimeStamp(); mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts& p); mrpt::system::TTimeStamp buildTimestampFromPartsLocalTime(const mrpt::system::TTimeParts& p); void timestampToParts(TTimeStamp t, TTimeParts& p, bool localTime = false); mrpt::system::TTimeStamp getCurrentTime(); mrpt::system::TTimeStamp now(); mrpt::system::TTimeStamp time_tToTimestamp(const double t); mrpt::system::TTimeStamp time_tToTimestamp(const time_t& t); double timestampTotime_t(const mrpt::system::TTimeStamp t); double timestampToDouble(const mrpt::system::TTimeStamp t); double timeDifference(const mrpt::system::TTimeStamp& t_first, const mrpt::system::TTimeStamp& t_later); double now_double(); mrpt::system::TTimeStamp timestampAdd(const mrpt::system::TTimeStamp tim, const double num_seconds); std::string formatTimeInterval(const double timeSeconds); std::string dateTimeToString(const mrpt::system::TTimeStamp t); std::string dateTimeLocalToString(const mrpt::system::TTimeStamp t); std::string dateToString(const mrpt::system::TTimeStamp t); double extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t); std::string timeToString(const mrpt::system::TTimeStamp t); std::string timeLocalToString(const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits = 6); std::string intervalFormat(const double seconds); std::ostream& operator << (std::ostream& o, const TTimeStamp& t); std::string getTempFileName(); std::string getcwd(); std::string getShareMRPTDir(); bool createDirectory(const std::string& dirName); bool deleteFile(const std::string& fileName); void deleteFiles(const std::string& s); bool renameFile( const std::string& oldFileName, const std::string& newFileName, std::string* error_msg = nullptr ); bool deleteFilesInDirectory(const std::string& s, bool deleteDirectoryAsWell = false); std::string extractFileName(const std::string& filePath); std::string extractFileExtension(const std::string& filePath, bool ignore_gz = false); std::string extractFileDirectory(const std::string& filePath); bool fileExists(const std::string& fileName); bool directoryExists(const std::string& fileName); std::string fileNameStripInvalidChars( const std::string& filename, const char replacement_to_invalid_chars = '_' ); std::string fileNameChangeExtension(const std::string& filename, const std::string& newExtension); uint64_t getFileSize(const std::string& fileName); time_t getFileModificationTime(const std::string& filename); std::string filePathSeparatorsToNative(const std::string& filePath); bool copyFile( const std::string& sourceFile, const std::string& targetFile, std::string* outErrStr = nullptr ); std::string toAbsolutePath(const std::string& path, bool resolveToCanonical = false); std::string pathJoin(const std::vector<std::string>& paths); std::string hyperlink( const std::string& text, const std::string& uri, bool force_use_format = false, bool show_uri_anyway = false ); std::string md5(const std::string& str); std::string md5(const std::vector<uint8_t>& str); std::string md5(const unsigned char* data, size_t len); unsigned long getMemoryUsage(); template < std::size_t alignment, typename T, typename = std::enable_if_t<std::is_pointer<T>::value> > bool is_aligned(T ptr); void pause(const std::string& msg = std::string("Press any key to continue...")); void clearConsole(); std::string MRPT_getCompilationDate(); std::string MRPT_getVersion(); const std::string& getMRPTLicense(); std::string find_mrpt_shared_dir(); void consoleColorAndStyle(ConsoleForegroundColor fg, ConsoleBackgroundColor bg = ConsoleBackgroundColor::DEFAULT, ConsoleTextStyle style = ConsoleTextStyle::REGULAR, bool applyToStdErr = false); int executeCommand( const std::string& command, std::string* output = nullptr, const std::string& mode = "r" ); bool launchProcess(const std::string& command); bool loadPluginModule( const std::string& moduleFileName, mrpt::optional_ref<std::string> outErrorMsgs = std::nullopt ); bool unloadPluginModule( const std::string& moduleFileName, mrpt::optional_ref<std::string> outErrorMsgs = std::nullopt ); bool loadPluginModules( const std::string& moduleFileNames, mrpt::optional_ref<std::string> outErrorMsgs = std::nullopt ); bool unloadPluginModules( const std::string& moduleFileNames, mrpt::optional_ref<std::string> outErrorMsgs = std::nullopt ); std::string progress( const double progressRatio0to1, const std::size_t barLength, bool encloseInSquareBrackets = true ); void changeCurrentThreadPriority(TThreadPriority priority); void changeCurrentProcessPriority(TProcessPriority priority); char* strtok(char* str, const char* strDelimit, char** context); template <class OUT_CONTAINER> void tokenize( const std::string& inString, const std::string& inDelimiters, OUT_CONTAINER& outTokens, bool skipBlankTokens = true ); template void tokenize< std::deque< std::string > >( const std::string& inString, const std::string& inDelimiters, std::deque<std::string>& outTokens, bool skipBlankTokens ); template void tokenize< std::vector< std::string > >( const std::string& inString, const std::string& inDelimiters, std::vector<std::string>& outTokens, bool skipBlankTokens ); std::string trim(const std::string& str); std::string upperCase(const std::string& str); std::string lowerCase(const std::string& str); void decodeUTF8(const std::string& strUTF8, std::vector<uint16_t>& out_uniStr); void encodeUTF8(const std::vector<uint16_t>& input, std::string& output); void encodeBase64(const std::vector<uint8_t>& inputData, std::string& outString); bool decodeBase64(const std::string& inString, std::vector<uint8_t>& outData); std::string unitsFormat(const double val, int nDecimalDigits = 2, bool middle_space = true); std::string rightPad( const std::string& str, size_t total_len, bool truncate_if_larger = false ); bool strCmp(const std::string& s1, const std::string& s2); bool strCmpI(const std::string& s1, const std::string& s2); bool strStarts(const std::string& str, const std::string& subStr); bool strStartsI(const std::string& str, const std::string& subStr); template <typename T> std::string sprintf_container(const char* fmt, const T& V); void stringListAsString( const std::vector<std::string>& lst, std::string& out, const std::string& newline = "\r\n" ); void stringListAsString( const std::deque<std::string>& lst, std::string& out, const std::string& newline = "\r\n" ); size_t nthOccurrence(const std::string& str, const std::string& strToFind, size_t nth); std::string firstNLines(const std::string& str, size_t n); void thread_name(const std::string& name, std::thread& theThread); void thread_name(const std::string& name); std::string thread_name(std::thread& theThread); std::string thread_name(); } // namespace system
Typedefs
typedef std::function<void(std::string_view msg, const mrpt::system::VerbosityLevel level, std::string_view loggerName, const mrpt::Clock::time_point timestamp)> output_logger_callback_t
Callback types for use with mrpt::system::COuputLogger.