Skip to content

Commit 4995dd7

Browse files
authored
refactor: consolidate string utilities on sstr and remove legacy SStr (#325)
This branch removes the parallel `SStr`/`sstr` string utility split and standardizes the codebase on `sstr` plus straightforward standard C++ helpers where custom wrappers were no longer needed. The goal is to reduce duplication, shrink the maintenance surface, and make string/path/env handling easier to follow and evolve. `SStr` and `sstr` had overlapping responsibilities, which made it unclear which API should be preferred and kept legacy patterns alive longer than necessary. This refactor migrates the remaining `SStr` call sites to `sstr`, `spath`, `ssys`, and simple `std::string`/stream-based code, then removes the obsolete `SStr` implementation, tests, and build references. The result is a smaller and more consistent utility layer with no intended functional change.
1 parent 220c075 commit 4995dd7

33 files changed

Lines changed: 372 additions & 2470 deletions

CSG/CSGFoundry.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "smeta.h"
2121
#include "SSim.hh"
22-
#include "SStr.hh"
2322

2423
// TODO: migrate to spath.h
2524
#include "SPath.hh"
@@ -1152,7 +1151,7 @@ void CSGFoundry::findSolidIdx(std::vector<unsigned>& solid_idx, const char* labe
11521151
std::vector<unsigned>& ss = solid_idx ;
11531152

11541153
std::vector<std::string> elem ;
1155-
SStr::Split(label, ',', elem );
1154+
sstr::Split(label, ',', elem);
11561155

11571156
for(unsigned i=0 ; i < elem.size() ; i++)
11581157
{
@@ -1161,7 +1160,7 @@ void CSGFoundry::findSolidIdx(std::vector<unsigned>& solid_idx, const char* labe
11611160
{
11621161
const CSGSolid& so = solid[j];
11631162

1164-
bool match = SStr::SimpleMatch(so.label, ele.c_str()) ;
1163+
bool match = sstr::SimpleMatch(so.label, ele.c_str());
11651164
unsigned count = std::count(ss.begin(), ss.end(), j ); // count if j is already collected
11661165
if(match && count == 0) ss.push_back(j) ;
11671166
}
@@ -1318,23 +1317,26 @@ std::string CSGFoundry::detailPrim(unsigned primIdx) const
13181317
float4 ce = pr->ce();
13191318

13201319
std::stringstream ss ;
1320+
1321+
auto label_value = [](const char* label, int value) {
1322+
return sstr::Format_("%s:%d", label, value);
1323+
};
13211324
ss
1322-
<< std::setw(10) << SStr::Format(" pri:%d", primIdx )
1323-
<< std::setw(10) << SStr::Format(" lpr:%d", pr_primIdx )
1324-
<< std::setw(8) << SStr::Format(" gas:%d", gasIdx )
1325-
<< std::setw(8) << SStr::Format(" msh:%d", meshIdx)
1326-
<< std::setw(8) << SStr::Format(" bnd:%d", boundary)
1327-
<< std::setw(8) << SStr::Format(" nno:%d", numNode )
1328-
<< std::setw(10) << SStr::Format(" nod:%d", nodeOffset )
1325+
<< std::setw(10) << label_value("pri", primIdx)
1326+
<< std::setw(10) << label_value("lpr", pr_primIdx)
1327+
<< std::setw(8) << label_value("gas", gasIdx)
1328+
<< std::setw(8) << label_value("msh", meshIdx)
1329+
<< std::setw(8) << label_value("bnd", boundary)
1330+
<< std::setw(8) << label_value("nno", numNode)
1331+
<< std::setw(10) << label_value("nod", nodeOffset)
13291332
<< " ce "
13301333
<< "(" << std::setw(10) << std::fixed << std::setprecision(2) << ce.x
13311334
<< "," << std::setw(10) << std::fixed << std::setprecision(2) << ce.y
13321335
<< "," << std::setw(10) << std::fixed << std::setprecision(2) << ce.z
13331336
<< "," << std::setw(10) << std::fixed << std::setprecision(2) << ce.w
13341337
<< ")"
1335-
<< " meshName " << std::setw(15) << ( meshName ? meshName : "-" )
1336-
<< " bndName " << std::setw(15) << ( bndName ? bndName : "-" )
1337-
;
1338+
<< " meshName " << std::setw(15) << (meshName ? meshName : "-")
1339+
<< " bndName " << std::setw(15) << (bndName ? bndName : "-");
13381340

13391341
std::string s = ss.str();
13401342
return s ;
@@ -4033,4 +4035,3 @@ void CSGFoundry::kludgeScalePrimBBox( unsigned solidIdx, float dscale )
40334035

40344036

40354037

4036-

CSG/tests/CSGFoundry_getCenterExtent_Test.cc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,28 @@ See also CSGTargetTest.cc
2020
2121
**/
2222

23-
#include <csignal>
24-
#include "SSys.hh"
25-
#include "SStr.hh"
26-
#include "SSim.hh"
2723
#include "CSGFoundry.h"
24+
#include "SSim.hh"
25+
#include "SSys.hh"
26+
#include "sstr.h"
27+
#include <csignal>
2828

2929
#include "OPTICKS_LOG.hh"
3030

3131
int main(int argc, char** argv)
3232
{
33-
OPTICKS_LOG(argc, argv);
33+
OPTICKS_LOG(argc, argv);
3434

35-
SSim::Create();
36-
CSGFoundry* fd = CSGFoundry::Load();
35+
SSim::Create();
36+
CSGFoundry* fd = CSGFoundry::Load();
3737

38-
LOG(info)
39-
<< "foundry " << fd->desc()
40-
;
41-
fd->summary();
38+
LOG(info)
39+
<< "foundry " << fd->desc();
40+
fd->summary();
4241

43-
const char* MOI = SSys::getenvvar("MOI", "sWorld:0:0");
44-
std::vector<std::string> vmoi ;
45-
SStr::Split(MOI, ',', vmoi );
42+
const char* MOI = SSys::getenvvar("MOI", "sWorld:0:0");
43+
std::vector<std::string> vmoi;
44+
sstr::Split(MOI, ',', vmoi);
4645
LOG(info) << " MOI " << MOI << " vmoi.size " << vmoi.size() ;
4746

4847
qat4 q ;
@@ -77,4 +76,3 @@ int main(int argc, char** argv)
7776

7877

7978

80-

CSG/tests/CSGNodeScanTest.cc

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ For lower level tests see::
1313
#include <vector>
1414
#include <cmath>
1515

16+
#include "NP.hh"
1617
#include "OPTICKS_LOG.hh"
17-
#include "SSys.hh"
18-
#include "SStr.hh"
1918
#include "SPath.hh"
20-
#include "NP.hh"
19+
#include "SSys.hh"
20+
#include "sstr.h"
2121

2222
#include "scuda.h"
2323
#include "squad.h"
@@ -28,42 +28,52 @@ For lower level tests see::
2828
#include "csg_intersect_node.h"
2929
#include "csg_intersect_tree.h"
3030

31+
namespace
32+
{
33+
std::vector<int>* ParseIntList(const char* spec, char delim)
34+
{
35+
auto* values = new std::vector<int>();
36+
if (spec)
37+
sstr::split<int>(*values, spec, delim);
38+
return values;
39+
}
40+
} // namespace
41+
3142
struct Scan
3243
{
33-
const char* geom ;
34-
CSGNode nd ;
35-
float t_min ;
36-
int num ;
37-
bool shifted ;
38-
const char* modes_ ;
39-
const char* axes_ ;
40-
std::vector<int>* modes ;
41-
std::vector<int>* axes ;
42-
43-
NP* simtrace ;
44-
quad4* qq ;
45-
const char* fold ;
46-
47-
Scan();
48-
void init();
49-
std::string desc() const ;
50-
void save() const ;
51-
};
52-
53-
Scan::Scan()
54-
:
44+
const char* geom;
45+
CSGNode nd;
46+
float t_min;
47+
int num;
48+
bool shifted;
49+
const char* modes_;
50+
const char* axes_;
51+
std::vector<int>* modes;
52+
std::vector<int>* axes;
53+
54+
NP* simtrace;
55+
quad4* qq;
56+
const char* fold;
57+
58+
Scan();
59+
void init();
60+
std::string desc() const;
61+
void save() const;
62+
};
63+
64+
Scan::Scan() :
5565
geom(SSys::getenvvar("CSGNodeScanTest_GEOM", "iphi")),
56-
nd(CSGNode::MakeDemo(geom)),
57-
t_min(SSys::getenvfloat("TMIN",0.f)),
66+
nd(CSGNode::MakeDemo(geom)),
67+
t_min(SSys::getenvfloat("TMIN", 0.f)),
5868
num(SSys::getenvint("NUM", 200)),
5969
shifted(true),
6070
modes_(SSys::getenvvar("MODES", "0,1,2,3")),
61-
axes_(SSys::getenvvar("AXES", "0,2,1")), // X,Z,Y 3rd gets set to zero
62-
modes(SStr::ISplit(modes_, ',')),
63-
axes(SStr::ISplit(axes_, ',')),
64-
simtrace(NP::Make<float>(modes->size(),num,4,4)),
71+
axes_(SSys::getenvvar("AXES", "0,2,1")), // X,Z,Y 3rd gets set to zero
72+
modes(ParseIntList(modes_, ',')),
73+
axes(ParseIntList(axes_, ',')),
74+
simtrace(NP::Make<float>(modes->size(), num, 4, 4)),
6575
qq((quad4*)simtrace->values<float>()),
66-
fold(SPath::Resolve("$TMP/CSGNodeScanTest", geom, DIRPATH ))
76+
fold(SPath::Resolve("$TMP/CSGNodeScanTest", geom, DIRPATH))
6777
{
6878
init();
6979
}

CSG/tests/CSGTargetGlobalTest.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ MOI=solidXJfixture:64 CSGTargetGlobalTest
1111
#include "SPath.hh"
1212
#include "SSys.hh"
1313
#include "SSim.hh"
14-
#include "SStr.hh"
1514
#include "OPTICKS_LOG.hh"
1615

1716
#include "scuda.h"
@@ -93,4 +92,3 @@ int main(int argc, char** argv)
9392
}
9493

9594

96-

CSG/tests/CSGTargetTest.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Check a few different iidx of midx 120::
2424
2525
2626
**/
27-
#include <csignal>
28-
#include "SSys.hh"
29-
#include "SStr.hh"
3027
#include "SSim.hh"
28+
#include "SSys.hh"
29+
#include "sstr.h"
30+
#include <csignal>
3131

3232
#include "OPTICKS_LOG.hh"
3333

@@ -69,8 +69,8 @@ CSGTargetTest::CSGTargetTest()
6969

7070
void CSGTargetTest::dumpMOI( const char* MOI )
7171
{
72-
std::vector<std::string> vmoi ;
73-
SStr::Split(MOI, ',', vmoi );
72+
std::vector<std::string> vmoi;
73+
sstr::Split(MOI, ',', vmoi);
7474

7575
LOG(info) << " MOI " << MOI << " vmoi.size " << vmoi.size() ;
7676

@@ -201,4 +201,3 @@ int main(int argc, char** argv)
201201
}
202202

203203

204-

CSG/tests/DemoGeo.cc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#include <iostream>
2-
#include <iomanip>
3-
#include <cstring>
1+
#include <algorithm>
42
#include <array>
5-
3+
#include <cstring>
4+
#include <iomanip>
5+
#include <iostream>
66

77
//#include <vector_types.h>
88

9-
#include "SStr.hh"
10-
#include "ssys.h"
119
#include "NP.hh"
1210
#include "SLOG.hh"
11+
#include "sstr.h"
12+
#include "ssys.h"
1313

1414
#include "scuda.h"
1515
#include "CSGFoundry.h"
@@ -19,6 +19,19 @@
1919
#include "DemoGeo.h"
2020
#include "DemoGrid.h"
2121

22+
namespace
23+
{
24+
void ParseGridSpec(std::array<int, 9>& grid, const char* spec)
25+
{
26+
std::vector<int> values;
27+
std::stringstream ss(spec ? spec : "");
28+
std::string item;
29+
while (std::getline(ss, item, ',')) sstr::split<int>(values, item.c_str(), ':');
30+
assert(values.size() == grid.size());
31+
std::copy(values.begin(), values.end(), grid.begin());
32+
}
33+
} // namespace
34+
2235
DemoGeo::DemoGeo(CSGFoundry* foundry_, const char* geom)
2336
:
2437
foundry(foundry_),
@@ -45,15 +58,15 @@ void DemoGeo::init(const char* geom)
4558
{
4659
init_parade();
4760
}
48-
else if(SStr::StartsWith(geom, "clustered_"))
61+
else if (sstr::StartsWith(geom, "clustered_"))
4962
{
5063
init_clustered( geom + strlen("clustered_"));
5164
}
52-
else if(SStr::StartsWith(geom, "scaled_"))
65+
else if (sstr::StartsWith(geom, "scaled_"))
5366
{
5467
init_scaled( geom, geom + strlen("scaled_"), outer, layers, numgas );
5568
}
56-
else if(SStr::StartsWith(geom, "layered_"))
69+
else if (sstr::StartsWith(geom, "layered_"))
5770
{
5871
init_layered( geom + strlen("layered_"), outer, layers );
5972
}
@@ -142,7 +155,7 @@ void DemoGeo::init_clustered(const char* name)
142155

143156
bool inbox = false ;
144157
std::array<int,9> cl ;
145-
SStr::ParseGridSpec(cl, clusterspec); // string parsed into array of 9 ints
158+
ParseGridSpec(cl, clusterspec);
146159
CSGSolid* so = maker->makeClustered(name, cl[0],cl[1],cl[2],cl[3],cl[4],cl[5],cl[6],cl[7],cl[8], unit, inbox );
147160
std::cout << "DemoGeo::init_layered" << name << " so.center_extent " << so->center_extent << std::endl ;
148161

@@ -218,4 +231,3 @@ std::string DemoGeo::desc() const
218231
std::string s = ss.str();
219232
return s ;
220233
}
221-

0 commit comments

Comments
 (0)