# foundation **Repository Path**: zhou_bing94/foundation ## Basic Information - **Project Name**: foundation - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-05 - **Last Updated**: 2026-10-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Foundation - 跨平台基础框架库 Foundation 是一个可独立移植的基础框架库,提供平台抽象、日志系统、配置管理、事件总线等核心功能,支持 Windows、Linux、Android、macOS 等平台。 ## 特性 | 特性 | 说明 | |------|------| | **PAL 层** | 平台抽象层,封装线程、互斥锁、时间、模块路径等差异 | | **日志系统** | 基于 spdlog 封装,支持分级日志、控制台和文件输出 | | **配置管理** | TOML 格式配置文件,支持热重载 | | **事件总线** | 发布-订阅模式,模块解耦 | | **基础工具** | 字节缓冲区、内存池、线程池、文件系统操作 | | **零外部依赖** | 只需 C++17 标准库,第三方库自包含 | ## 项目结构 ``` foundation/ ├── CMakeLists.txt # CMake 构建配置 ├── README.md # 项目说明 ├── docs/ # 文档目录 │ ├── 架构设计.md # 架构设计文档 │ ├── 使用指南.md # 使用指南 │ └── 接口参考.md # API 参考 ├── pal/ # 平台抽象层 (Platform Abstraction Layer) │ ├── include/ # 头文件 │ │ ├── types.h # 基础类型定义 │ │ ├── thread.h # 线程抽象 │ │ ├── mutex.h # 互斥锁抽象 │ │ ├── pal_time.h # 时间工具 │ │ ├── module.h # 模块路径 │ │ └── platform_detect.h # 平台检测宏 │ ├── thread_win.cpp # Windows 线程实现 │ ├── thread_unix.cpp # Unix/Linux 线程实现 │ ├── thread_android.cpp # Android 线程实现 │ ├── mutex_win.cpp # Windows 互斥锁实现 │ ├── mutex_unix.cpp # Unix/Linux 互斥锁实现 │ ├── mutex_android.cpp # Android 互斥锁实现 │ ├── time_win.cpp # Windows 时间实现 │ ├── time_unix.cpp # Unix/Linux 时间实现 │ ├── time_android.cpp # Android 时间实现 │ ├── module_win.cpp # Windows 模块路径实现 │ ├── module_unix.cpp # Unix/Linux 模块路径实现 │ └── module_android.cpp # Android 模块路径实现 ├── log/ # 日志系统 │ ├── include/ │ │ └── logger.h # 日志接口 │ └── logger.cpp # 日志实现 ├── context/ # 上下文管理 │ ├── context.h # 上下文接口 │ └── context.cpp # 上下文实现 ├── base/ # 基础工具集 │ ├── include/ │ │ ├── buffer.h # 字节缓冲区 │ │ ├── config.h # 配置管理 │ │ ├── event_bus.h # 事件总线 │ │ ├── file_system.h # 文件系统操作 │ │ ├── memory_pool.h # 内存池 │ │ ├── result.h # 错误处理 Result │ │ └── thread_pool.h # 线程池 │ ├── buffer.cpp │ ├── config.cpp │ ├── event_bus.cpp │ ├── file_system.cpp │ ├── memory_pool.cpp │ └── thread_pool.cpp └── third_party/ # 自包含第三方库 ├── spdlog/ # 日志库 (header-only) ├── toml++/ # TOML 解析器 (toml++ v3.4.0, header-only) └── nlohmann/ # JSON 解析器 (nlohmann_json 3.12.0, header-only) ``` ## 支持平台 | 平台 | 状态 | |------|------| | Windows (x86_64) | ✅ | | Linux (x86_64) | ✅ | | Android (arm64-v8a, armeabi-v7a, x86_64, x86) | ✅ | | macOS (x86_64, arm64) | ✅ | ## 快速开始 ### 作为 Git Submodule 使用 ```bash # 在你的项目中添加 foundation 为子仓库 git submodule add https://gitee.com/zhou_bing94/foundation.git foundation git submodule update --init --recursive ``` ### CMake 集成 ```cmake # 在你的 CMakeLists.txt 中添加 add_subdirectory(foundation) # 链接 foundation 库 target_link_libraries(your_target PRIVATE foundation) ``` ### 快速示例 ```cpp #include #include #include int main() { // 初始化上下文和日志 foundation::Context::GetInstance().Init(); foundation::log::Logger::GetInstance().SetLevel(foundation::log::LogLevel::Info); // 使用 PAL 层 auto now = foundation::pal::Time::GetCurrentTimestampMs(); foundation::pal::Time::MilliSleep(100); // 输出日志 LOG_INFO("Hello from foundation! Current time: {}", now); return 0; } ``` ## 构建 ### 独立构建 ```bash mkdir build && cd build cmake .. cmake --build . --config Release ``` ### 作为子模块构建 Foundation 设计为与你的项目一起编译,详见 [docs/使用指南.md](docs/使用指南.md)。 ## 文档 - [架构设计文档](docs/架构设计.md) - [使用指南](docs/使用指南.md) - [接口参考](docs/接口参考.md) ## 版本管理 当前版本:`2.1.1`,唯一事实源是本模块根目录的 `VERSION.txt`。生成版本头和运行时诊断信息均由该文件派生;构建日期、commit 和 Git tag 只用于发布追溯。 ## 许可证 MIT License