Merge pull request 'refactor: MakeTempSatPath 并入已有的 SAT 相关 namespace' (#24) from company-desktop-computer/chore/coding-convention-anon-namespace into main

Reviewed-on: #24
Reviewed-by: gjm <littleoldpan@163.com>
This commit was merged in pull request #24.
This commit is contained in:
gjm committed 2026-10-21 09:26:11 +08:00
commit fabaca58df
2 files changed
+74 -64

No files matched your search

+10
View File
@@ -144,6 +144,16 @@ set_debug_post_build(<target> "<Name>" ".arx")
- 改完自检:`python -c "print(open('f.cpp','rb').read(3))"` 应为 `b'\xef\xbb\xbf'`;再查 `raw.count(b'\xef\xbf\xbd')`,非 0 说明中文已被写坏(不可逆),用 `git checkout HEAD -- <file>` 还原重做。
- 若遇到仍是 GBK/UTF-16 的老文件(从旧分支检出),先探明编码再改,不要假设。
## 编码规范
- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件**已有的**匿名 `namespace { }` 中;只有整个文件没有匿名 namespace 时才新建一块。不要为每个函数单独开一块,也不要写成文件级 `static` 或放进头文件。
```cpp
namespace {
CString MakeTempSatPath() { ... }
}
```
## 测试 / 静态检查
本仓库**没有单元测试框架**(无 gtest/Catch2),也没有 lint 配置。验证方式是编译对应 preset,并在 CAD 中加载 `.arx` / `.zrx` 实测。
+64 -64
View File
@@ -3034,21 +3034,73 @@ AcDbRegion* CoreTools::createRegion(AcDbEntity *pEnt)
return (AcDbRegion*)segs[0];
}
// 生成唯一的临时 SAT 文件路径。
// 用 PID + 进程内原子序号,避免多个 CAD 实例或多线程互相覆盖同名文件。
// 调用方负责在 acisOut/acisIn 结束后 DeleteFile。
static CString MakeTempSatPath()
namespace
{
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<CString> 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)
@@ -3456,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<CString> 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);