// io_utils.h - 通用 IO 工具:时间/目录/日志清理/GBK转码/文件保存 #ifndef IO_UTILS_H #define IO_UTILS_H #include #include #include // 去除字符串首尾空白(空格/tab/回车/换行) std::string trim_str(const std::string& s); // GBK(ANSI) → UTF-8(日志文件按UTF-8写入,避免编辑器乱码) std::string gbk_to_utf8(const std::string& s); // 递归创建目录(支持 "a/b/c",已存在则返回 true) bool make_dirs(const std::string& path); // 创建本次任务输出目录并返回完整路径: data/日期/时间_taskId // taskId 为空时返回 data/日期/时间_ (调用方需自行创建 data 根目录) std::string make_task_dir(const std::string& task_id); // 按配置 cfg.log.retain_days 清理 data/日期 下的过期日期目录(保留最近 N 天) // 在程序启动与每日 log.clean_time 时刻调用 void clean_expired_log_dirs(); // 保存 ASCII PCD 点云(一次性构建字符串写入,避免逐行IO) void save_pcd_ascii(const std::string& filename, const std::vector& xs, const std::vector& ys, const std::vector& zs); // 保存灰度 JPG(灰度转RGB后压缩为JPEG,quality=90) bool save_jpg_gray(const std::string& filename, int width, int height, const std::vector& pixels, int quality = 90); #endif // IO_UTILS_H