Files
ViewDesignEngine/include/vde/core/version.h
T
茂之钳 5bfcbcb8e9
CI / Build & Test (push) Failing after 39s
CI / Release Build (push) Failing after 33s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
feat(v1.0.1): tangent_pull + error codes + version + license management
Remaining P3 item:
- tangent_pull: maintain G1 tangency when pulling faces

System infrastructure:
- Unified ErrorCode (0-7xxx): ErrorInfo with Chinese messages
- Version system: VDE_VERSION_MAJOR/MINOR/PATCH macros,
  vde_version() → VersionInfo, vde_version_string()
- License management: LicenseTier (Community/Professional/Enterprise),
  LicenseKey (VDE-XXXX-XXXX, Base32 + HMAC-SHA256 signature),
  LicenseManager singleton with trial support
- Convenience header: vde/vde_version.h

Tests: 43 total (26 license + 17 version)
2026-07-27 21:54:46 +08:00

177 lines
6.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
/**
* @file version.h
* @brief ViewDesignEngine 版本信息
*
* 提供编译时版本宏和运行时版本查询函数。
* 编译时间戳通过 CMake 的 configure_file 在构建时注入。
*
* @ingroup core
*/
#include <cstdint>
#include <string>
// 包含 CMake 生成的构建配置
#if __has_include("vde_build_config.h")
#include "vde_build_config.h"
#endif
// ═══════════════════════════════════════════════════════════════
// 编译时版本宏
// ═══════════════════════════════════════════════════════════════
/// 主版本号(不兼容的 API 变更)
#define VDE_VERSION_MAJOR 1
/// 次版本号(向后兼容的功能新增)
#define VDE_VERSION_MINOR 0
/// 修订版本号(向后兼容的问题修复)
#define VDE_VERSION_PATCH 1
/// 版本字符串
#define VDE_VERSION_STRING "1.0.1"
// ── 版本号整型(用于比较) ────────────────────────────
/// 版本号编码为大整数: VDE_VERSION(major, minor, patch) = major*10000 + minor*100 + patch
#define VDE_VERSION_CODE(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
/// 当前版本号整型编码
#define VDE_VERSION_NUM VDE_VERSION_CODE(1, 0, 1)
// ═══════════════════════════════════════════════════════════════
// 构建信息(由 CMake configure_file 注入)
// ═══════════════════════════════════════════════════════════════
#ifndef VDE_BUILD_TYPE
/// 构建类型:Debug / Release / RelWithDebInfo / MinSizeRel
#ifdef NDEBUG
#define VDE_BUILD_TYPE "Release"
#else
#define VDE_BUILD_TYPE "Debug"
#endif
#endif
#ifndef VDE_BUILD_TIMESTAMP
/// 构建时间戳(ISO 8601 格式,如 "2026-07-27T12:00:00Z"
/// 由 CMake 的 configure_file 注入
#define VDE_BUILD_TIMESTAMP "unknown"
#endif
#ifndef VDE_COMPILER_INFO
/// 编译器信息字符串
#if defined(__clang__)
#define VDE_COMPILER_INFO "Clang " __clang_version__
#elif defined(__GNUC__) || defined(__GNUG__)
#define VDE_COMPILER_INFO "GCC " __VERSION__
#elif defined(_MSC_VER)
#define VDE_COMPILER_INFO "MSVC " _MSC_VER_STR
#else
#define VDE_COMPILER_INFO "Unknown Compiler"
#endif
#endif
// ═══════════════════════════════════════════════════════════════
// C++ 标准信息
// ═══════════════════════════════════════════════════════════════
/// C++ 标准字符串(如 "C++20"
#if __cplusplus >= 202002L
#define VDE_CPP_STANDARD_STRING "C++20"
#elif __cplusplus >= 201703L
#define VDE_CPP_STANDARD_STRING "C++17"
#elif __cplusplus >= 201402L
#define VDE_CPP_STANDARD_STRING "C++14"
#elif __cplusplus >= 201103L
#define VDE_CPP_STANDARD_STRING "C++11"
#else
#define VDE_CPP_STANDARD_STRING "C++03"
#endif
namespace vde::core {
// ═══════════════════════════════════════════════════════════════
// VersionInfo 结构体
// ═══════════════════════════════════════════════════════════════
/**
* @brief 版本信息结构体
*
* 包含库版本号、构建类型、时间戳和编译器信息。
*/
struct VersionInfo {
int major; ///< 主版本号
int minor; ///< 次版本号
int patch; ///< 修订版本号
std::string version_string; ///< 版本字符串 "1.0.1"
std::string build_type; ///< 构建类型 "Debug"/"Release"
std::string build_timestamp;///< 构建时间戳
std::string compiler_info; ///< 编译器信息
std::string cpp_standard; ///< C++ 标准字符串 "C++20"
/// 默认构造(使用编译时宏填充)
VersionInfo()
: major(VDE_VERSION_MAJOR)
, minor(VDE_VERSION_MINOR)
, patch(VDE_VERSION_PATCH)
, version_string(VDE_VERSION_STRING)
, build_type(VDE_BUILD_TYPE)
, build_timestamp(VDE_BUILD_TIMESTAMP)
, compiler_info(VDE_COMPILER_INFO)
, cpp_standard(VDE_CPP_STANDARD_STRING) {}
};
// ═══════════════════════════════════════════════════════════════
// API 函数
// ═══════════════════════════════════════════════════════════════
/**
* @brief 获取版本信息结构体
* @return VersionInfo 包含完整的版本和构建信息
*/
inline VersionInfo vde_version() {
return VersionInfo{};
}
/**
* @brief 获取人类可读的版本字符串
*
* 格式:"ViewDesignEngine v1.0.1 (C++20, GCC 11.4)"
*
* @return 版本信息字符串
*/
inline std::string vde_version_string() {
std::string result = "ViewDesignEngine v";
result += VDE_VERSION_STRING;
result += " (";
result += VDE_CPP_STANDARD_STRING;
result += ", ";
result += VDE_COMPILER_INFO;
result += ")";
return result;
}
/**
* @brief 比较两个版本号
*
* 返回负值表示 lhs < rhs,零表示相等,正值表示 lhs > rhs。
*
* @param lhs_major 左主版本
* @param lhs_minor 左次版本
* @param lhs_patch 左修订版本
* @param rhs_major 右主版本
* @param rhs_minor 右次版本
* @param rhs_patch 右修订版本
* @return 比较结果
*/
inline int vde_version_compare(int lhs_major, int lhs_minor, int lhs_patch,
int rhs_major, int rhs_minor, int rhs_patch) {
int lhs = VDE_VERSION_CODE(lhs_major, lhs_minor, lhs_patch);
int rhs = VDE_VERSION_CODE(rhs_major, rhs_minor, rhs_patch);
return lhs - rhs;
}
} // namespace vde::core