ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
tools_sys.h File Reference

系统和文件系统辅助函数 More...

Namespaces

namespace  ngl::tools
 工具函数命名空间。

Functions

std::string ngl::tools::time2str (int autc, const char *aformat)
 将UTC时间戳转换为格式化字符串
const std::string & ngl::tools::server_name ()
 获取当前服务器名称
int ngl::tools::rand ()
 生成随机整数
bool ngl::tools::directories_exists (const std::string &apath)
 检查目录是否存在
bool ngl::tools::file_exists (const std::string &apath)
 检查文件是否存在
bool ngl::tools::create_dir (const std::string &apath)
 创建目录(包括父目录)
bool ngl::tools::file_remove (const std::string &afile)
 删除文件
void ngl::tools::dir (const std::string &apath, std::vector< std::string > &afiles, bool aiter)
 获取目录下的所有文件
void ngl::tools::no_core_dump (bool anocreate)
 终止程序(用于致命错误)
std::function< void()> ngl::tools::send_mail (const std::string &acontent, bool asynchronize)
 创建邮件发送函数
int64_t ngl::tools::nguidstr2int64 (const char *anguid)
 将GUID字符串转换为int64_t

Detailed Description

系统和文件系统辅助函数

提供系统级工具函数,包括:

  • 时间格式化转换
  • 文件和目录操作
  • 随机数生成
  • 邮件发送功能
  • GUID字符串转换
    Note
    所有函数均位于 ngl::tools 命名空间下。
    // 时间格式化示例
    std::string time_str = ngl::tools::time2str(time(nullptr), "%Y-%m-%d %H:%M:%S");
    // 文件操作示例
    if (ngl::tools::file_exists("/path/to/file")) {
    // 文件存在
    }
    // 目录遍历示例
    std::vector<std::string> files;
    ngl::tools::dir("/path/to/dir", files, true); // 递归遍历