From 3ba658ffc5d9a0323622c9ea24bf2cb32977460e Mon Sep 17 00:00:00 2001 From: company-desktop-computer Date: Wed, 21 Oct 2026 09:24:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20MakeTempSatPath=20=E5=B9=B6?= =?UTF-8?q?=E5=85=A5=E5=B7=B2=E6=9C=89=E7=9A=84=20SAT=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 不再为单个函数新建 namespace 块:把 SAT 相关的 find_nth_occurrence_reverse / fixACISFormat 整块上移到 RegionToString 之前, MakeTempSatPath 并入同一块,文件内 namespace 块数由 7 回到 6 - 编码规范补充:优先复用已有 namespace,整个文件没有时才新建 --- CODEBUDDY.md | 2 +- SourceCode/Code2026/CoreCommand/CoreTools.cpp | 129 +++++++++--------- 2 files changed, 64 insertions(+), 67 deletions(-) diff --git a/CODEBUDDY.md b/CODEBUDDY.md index a853dbb..a65f7a3 100644 --- a/CODEBUDDY.md +++ b/CODEBUDDY.md @@ -146,7 +146,7 @@ set_debug_post_build( "" ".arx") ## 编码规范 -- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件的匿名 `namespace { }` 中,不要写成文件级 `static`,也不要放进头文件。 +- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件**已有的**匿名 `namespace { }` 中;只有整个文件没有匿名 namespace 时才新建一块。不要为每个函数单独开一块,也不要写成文件级 `static` 或放进头文件。 ```cpp namespace { diff --git a/SourceCode/Code2026/CoreCommand/CoreTools.cpp b/SourceCode/Code2026/CoreCommand/CoreTools.cpp index e26d1f1..f53d7a9 100644 --- a/SourceCode/Code2026/CoreCommand/CoreTools.cpp +++ b/SourceCode/Code2026/CoreCommand/CoreTools.cpp @@ -3036,22 +3036,71 @@ AcDbRegion* CoreTools::createRegion(AcDbEntity *pEnt) namespace { -// 生成唯一的临时 SAT 文件路径。 -// 用 PID + 进程内原子序号,避免多个 CAD 实例或多线程互相覆盖同名文件。 -// 调用方负责在 acisOut/acisIn 结束后 DeleteFile。 -CString MakeTempSatPath() -{ - static LONG s_nSeq = 0; - LONG nSeq = ::InterlockedIncrement(&s_nSeq); + // 生成唯一的临时 SAT 文件路径。 + // 用 PID + 进程内原子序号,避免多个 CAD 实例或多线程互相覆盖同名文件。 + // 调用方负责在 acisOut/acisIn 结束后 DeleteFile。 + CString MakeTempSatPath() + { + static LONG s_nSeq = 0; + LONG nSeq = ::InterlockedIncrement(&s_nSeq); - CString sPath = FilePath::getSystemTemporaryFolder(); - if (sPath.IsEmpty()) - sPath = _T("."); + CString sPath = FilePath::getSystemTemporaryFolder(); + if (sPath.IsEmpty()) + sPath = _T("."); - CString sName; - sName.Format(_T("\\x3d_%lu_%ld.sat"), (unsigned long)::GetCurrentProcessId(), nSeq); - return sPath + sName; -} + CString sName; + sName.Format(_T("\\x3d_%lu_%ld.sat"), (unsigned long)::GetCurrentProcessId(), nSeq); + return sPath + sName; + } + + size_t find_nth_occurrence_reverse(const std::string &str, char target, size_t n) + { + size_t pos = str.size(); + size_t count = 0; + + while (pos > 0) + { + pos = str.rfind(target, pos - 1); // 从 pos-1 开始反向查找 + if (pos == std::string::npos) break; + count++; + if (count == n) return pos; + } + + return std::string::npos; + } + + // 整理sat文件格式,使其符合规范 + bool fixACISFormat(const char *pszReg, std::string &sOut) + { + // 先取第一行,得到data record 的数量 + std::string ss; + std::stringstream eam(pszReg); + std::getline(eam, ss); + if (ss.empty()) return false; + + std::vector nums; + CoreTools::SplitString(CString(ss.c_str()), _T(" "), nums); + if (nums.size() < 2) return false; + int countOfRecord = _ttoi((LPCTSTR)nums[1]); + + ss = pszReg; + int sharpCount = std::count(ss.begin() ,ss.end(), '#'); + + size_t pos(std::string::npos); + if (sharpCount > countOfRecord) + { + // 如果 sharpCount 大于 countOfRecord,从头部取到第sharpCount个‘#’位置 + pos = find_nth_occurrence_reverse(ss, '#', (sharpCount - countOfRecord + 1)); + } + else // <= + { + // 如果 sharpCount 小于等于 countOfRecord,直接从头部取到最后一个‘#’位置 + pos = ss.rfind('#'); + } + sOut = ss.substr(0, pos + 1); + sOut += "\n\r"; + return true; + } } Adesk::UInt64 CoreTools::RegionToString(const AcDbRegion *pReg, char *& pszTxt) @@ -3459,58 +3508,6 @@ bool CoreTools::CurveToString(const AcDbCurve * pCurve, CString & sScr2) return false; } -namespace -{ - size_t find_nth_occurrence_reverse(const std::string &str, char target, size_t n) - { - size_t pos = str.size(); - size_t count = 0; - - while (pos > 0) - { - pos = str.rfind(target, pos - 1); // 从 pos-1 开始反向查找 - if (pos == std::string::npos) break; - count++; - if (count == n) return pos; - } - - return std::string::npos; - } - - // 整理sat文件格式,使其符合规范 - bool fixACISFormat(const char *pszReg, std::string &sOut) - { - // 先取第一行,得到data record 的数量 - std::string ss; - std::stringstream eam(pszReg); - std::getline(eam, ss); - if (ss.empty()) return false; - - std::vector nums; - CoreTools::SplitString(CString(ss.c_str()), _T(" "), nums); - if (nums.size() < 2) return false; - int countOfRecord = _ttoi((LPCTSTR)nums[1]); - - ss = pszReg; - int sharpCount = std::count(ss.begin() ,ss.end(), '#'); - - size_t pos(std::string::npos); - if (sharpCount > countOfRecord) - { - // 如果 sharpCount 大于 countOfRecord,从头部取到第sharpCount个‘#’位置 - pos = find_nth_occurrence_reverse(ss, '#', (sharpCount - countOfRecord + 1)); - } - else // <= - { - // 如果 sharpCount 小于等于 countOfRecord,直接从头部取到最后一个‘#’位置 - pos = ss.rfind('#'); - } - sOut = ss.substr(0, pos + 1); - sOut += "\n\r"; - return true; - } -} - AcDbRegion* CoreTools::StringToRegion(const CString & sRegionScrp) { std::string sUtf8 = CoreTools::unicode2Ansii((LPCTSTR)sRegionScrp, CP_UTF8);