From 27cd7111fbdd7a9d8316c59bef61794e5caf6260 Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Wed, 21 Oct 2026 09:18:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=A1=A5=E5=85=85=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E2=80=94=E2=80=94=E6=96=87=E4=BB=B6=E5=86=85?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E5=87=BD=E6=95=B0=E7=94=A8=E5=8C=BF=E5=90=8D?= =?UTF-8?q?=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CODEBUDDY.md 新增「编码规范」章节:只在一个 cpp 内使用的函数 放在该文件的匿名 namespace{} 中,不用文件级 static - CoreTools.cpp 的 MakeTempSatPath 按新规范改为匿名 namespace --- CODEBUDDY.md | 10 ++++++++++ SourceCode/Code2026/CoreCommand/CoreTools.cpp | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CODEBUDDY.md b/CODEBUDDY.md index a962f60..a853dbb 100644 --- a/CODEBUDDY.md +++ b/CODEBUDDY.md @@ -144,6 +144,16 @@ set_debug_post_build( "" ".arx") - 改完自检:`python -c "print(open('f.cpp','rb').read(3))"` 应为 `b'\xef\xbb\xbf'`;再查 `raw.count(b'\xef\xbf\xbd')`,非 0 说明中文已被写坏(不可逆),用 `git checkout HEAD -- ` 还原重做。 - 若遇到仍是 GBK/UTF-16 的老文件(从旧分支检出),先探明编码再改,不要假设。 +## 编码规范 + +- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件的匿名 `namespace { }` 中,不要写成文件级 `static`,也不要放进头文件。 + + ```cpp + namespace { + CString MakeTempSatPath() { ... } + } + ``` + ## 测试 / 静态检查 本仓库**没有单元测试框架**(无 gtest/Catch2),也没有 lint 配置。验证方式是编译对应 preset,并在 CAD 中加载 `.arx` / `.zrx` 实测。 diff --git a/SourceCode/Code2026/CoreCommand/CoreTools.cpp b/SourceCode/Code2026/CoreCommand/CoreTools.cpp index 2dbcc52..e26d1f1 100644 --- a/SourceCode/Code2026/CoreCommand/CoreTools.cpp +++ b/SourceCode/Code2026/CoreCommand/CoreTools.cpp @@ -3034,10 +3034,12 @@ AcDbRegion* CoreTools::createRegion(AcDbEntity *pEnt) return (AcDbRegion*)segs[0]; } +namespace +{ // 生成唯一的临时 SAT 文件路径。 // 用 PID + 进程内原子序号,避免多个 CAD 实例或多线程互相覆盖同名文件。 // 调用方负责在 acisOut/acisIn 结束后 DeleteFile。 -static CString MakeTempSatPath() +CString MakeTempSatPath() { static LONG s_nSeq = 0; LONG nSeq = ::InterlockedIncrement(&s_nSeq); @@ -3050,6 +3052,7 @@ static CString MakeTempSatPath() sName.Format(_T("\\x3d_%lu_%ld.sat"), (unsigned long)::GetCurrentProcessId(), nSeq); return sPath + sName; } +} Adesk::UInt64 CoreTools::RegionToString(const AcDbRegion *pReg, char *& pszTxt) {