diff --git a/CSG/CSGFoundry.cc b/CSG/CSGFoundry.cc index 3feff7f740..82634d6dff 100644 --- a/CSG/CSGFoundry.cc +++ b/CSG/CSGFoundry.cc @@ -19,7 +19,6 @@ #include "smeta.h" #include "SSim.hh" -#include "SStr.hh" // TODO: migrate to spath.h #include "SPath.hh" @@ -1152,7 +1151,7 @@ void CSGFoundry::findSolidIdx(std::vector& solid_idx, const char* labe std::vector& ss = solid_idx ; std::vector elem ; - SStr::Split(label, ',', elem ); + sstr::Split(label, ',', elem ); for(unsigned i=0 ; i < elem.size() ; i++) { @@ -1161,7 +1160,7 @@ void CSGFoundry::findSolidIdx(std::vector& solid_idx, const char* labe { const CSGSolid& so = solid[j]; - bool match = SStr::SimpleMatch(so.label, ele.c_str()) ; + bool match = sstr::SimpleMatch(so.label, ele.c_str()) ; unsigned count = std::count(ss.begin(), ss.end(), j ); // count if j is already collected if(match && count == 0) ss.push_back(j) ; } @@ -1318,14 +1317,18 @@ std::string CSGFoundry::detailPrim(unsigned primIdx) const float4 ce = pr->ce(); std::stringstream ss ; + auto label_value = [](const char* label, int value) + { + return sstr::Format_("%s:%d", label, value); + }; ss - << std::setw(10) << SStr::Format(" pri:%d", primIdx ) - << std::setw(10) << SStr::Format(" lpr:%d", pr_primIdx ) - << std::setw(8) << SStr::Format(" gas:%d", gasIdx ) - << std::setw(8) << SStr::Format(" msh:%d", meshIdx) - << std::setw(8) << SStr::Format(" bnd:%d", boundary) - << std::setw(8) << SStr::Format(" nno:%d", numNode ) - << std::setw(10) << SStr::Format(" nod:%d", nodeOffset ) + << std::setw(10) << label_value("pri", primIdx) + << std::setw(10) << label_value("lpr", pr_primIdx) + << std::setw(8) << label_value("gas", gasIdx) + << std::setw(8) << label_value("msh", meshIdx) + << std::setw(8) << label_value("bnd", boundary) + << std::setw(8) << label_value("nno", numNode) + << std::setw(10) << label_value("nod", nodeOffset) << " ce " << "(" << std::setw(10) << std::fixed << std::setprecision(2) << ce.x << "," << std::setw(10) << std::fixed << std::setprecision(2) << ce.y @@ -4033,4 +4036,3 @@ void CSGFoundry::kludgeScalePrimBBox( unsigned solidIdx, float dscale ) - diff --git a/CSG/tests/CSGFoundry_getCenterExtent_Test.cc b/CSG/tests/CSGFoundry_getCenterExtent_Test.cc index d4fe218f28..6839d2e547 100644 --- a/CSG/tests/CSGFoundry_getCenterExtent_Test.cc +++ b/CSG/tests/CSGFoundry_getCenterExtent_Test.cc @@ -22,7 +22,7 @@ See also CSGTargetTest.cc #include #include "SSys.hh" -#include "SStr.hh" +#include "sstr.h" #include "SSim.hh" #include "CSGFoundry.h" @@ -42,7 +42,7 @@ int main(int argc, char** argv) const char* MOI = SSys::getenvvar("MOI", "sWorld:0:0"); std::vector vmoi ; - SStr::Split(MOI, ',', vmoi ); + sstr::Split(MOI, ',', vmoi ); LOG(info) << " MOI " << MOI << " vmoi.size " << vmoi.size() ; qat4 q ; @@ -77,4 +77,3 @@ int main(int argc, char** argv) - diff --git a/CSG/tests/CSGNodeScanTest.cc b/CSG/tests/CSGNodeScanTest.cc index 266203895e..07f9aca1d7 100644 --- a/CSG/tests/CSGNodeScanTest.cc +++ b/CSG/tests/CSGNodeScanTest.cc @@ -15,7 +15,7 @@ For lower level tests see:: #include "OPTICKS_LOG.hh" #include "SSys.hh" -#include "SStr.hh" +#include "sstr.h" #include "SPath.hh" #include "NP.hh" @@ -28,6 +28,16 @@ For lower level tests see:: #include "csg_intersect_node.h" #include "csg_intersect_tree.h" +namespace +{ + std::vector* ParseIntList(const char* spec, char delim) + { + auto* values = new std::vector(); + if(spec) sstr::split(*values, spec, delim); + return values; + } +} + struct Scan { const char* geom ; @@ -59,8 +69,8 @@ Scan::Scan() shifted(true), modes_(SSys::getenvvar("MODES", "0,1,2,3")), axes_(SSys::getenvvar("AXES", "0,2,1")), // X,Z,Y 3rd gets set to zero - modes(SStr::ISplit(modes_, ',')), - axes(SStr::ISplit(axes_, ',')), + modes(ParseIntList(modes_, ',')), + axes(ParseIntList(axes_, ',')), simtrace(NP::Make(modes->size(),num,4,4)), qq((quad4*)simtrace->values()), fold(SPath::Resolve("$TMP/CSGNodeScanTest", geom, DIRPATH )) diff --git a/CSG/tests/CSGTargetGlobalTest.cc b/CSG/tests/CSGTargetGlobalTest.cc index 7049e9c070..62764ced75 100644 --- a/CSG/tests/CSGTargetGlobalTest.cc +++ b/CSG/tests/CSGTargetGlobalTest.cc @@ -11,7 +11,6 @@ MOI=solidXJfixture:64 CSGTargetGlobalTest #include "SPath.hh" #include "SSys.hh" #include "SSim.hh" -#include "SStr.hh" #include "OPTICKS_LOG.hh" #include "scuda.h" @@ -93,4 +92,3 @@ int main(int argc, char** argv) } - diff --git a/CSG/tests/CSGTargetTest.cc b/CSG/tests/CSGTargetTest.cc index f212785e54..3473117daf 100644 --- a/CSG/tests/CSGTargetTest.cc +++ b/CSG/tests/CSGTargetTest.cc @@ -26,7 +26,7 @@ Check a few different iidx of midx 120:: **/ #include #include "SSys.hh" -#include "SStr.hh" +#include "sstr.h" #include "SSim.hh" #include "OPTICKS_LOG.hh" @@ -70,7 +70,7 @@ CSGTargetTest::CSGTargetTest() void CSGTargetTest::dumpMOI( const char* MOI ) { std::vector vmoi ; - SStr::Split(MOI, ',', vmoi ); + sstr::Split(MOI, ',', vmoi ); LOG(info) << " MOI " << MOI << " vmoi.size " << vmoi.size() ; @@ -201,4 +201,3 @@ int main(int argc, char** argv) } - diff --git a/CSG/tests/DemoGeo.cc b/CSG/tests/DemoGeo.cc index 606766ea8b..6470af5fb3 100644 --- a/CSG/tests/DemoGeo.cc +++ b/CSG/tests/DemoGeo.cc @@ -2,11 +2,12 @@ #include #include #include +#include //#include -#include "SStr.hh" +#include "sstr.h" #include "ssys.h" #include "NP.hh" #include "SLOG.hh" @@ -19,6 +20,19 @@ #include "DemoGeo.h" #include "DemoGrid.h" +namespace +{ + void ParseGridSpec(std::array& grid, const char* spec) + { + std::vector values; + std::stringstream ss(spec ? spec : ""); + std::string item; + while(std::getline(ss, item, ',')) sstr::split(values, item.c_str(), ':'); + assert(values.size() == grid.size()); + std::copy(values.begin(), values.end(), grid.begin()); + } +} + DemoGeo::DemoGeo(CSGFoundry* foundry_, const char* geom) : foundry(foundry_), @@ -45,15 +59,15 @@ void DemoGeo::init(const char* geom) { init_parade(); } - else if(SStr::StartsWith(geom, "clustered_")) + else if(sstr::StartsWith(geom, "clustered_")) { init_clustered( geom + strlen("clustered_")); } - else if(SStr::StartsWith(geom, "scaled_")) + else if(sstr::StartsWith(geom, "scaled_")) { init_scaled( geom, geom + strlen("scaled_"), outer, layers, numgas ); } - else if(SStr::StartsWith(geom, "layered_")) + else if(sstr::StartsWith(geom, "layered_")) { init_layered( geom + strlen("layered_"), outer, layers ); } @@ -142,7 +156,7 @@ void DemoGeo::init_clustered(const char* name) bool inbox = false ; std::array cl ; - SStr::ParseGridSpec(cl, clusterspec); // string parsed into array of 9 ints + ParseGridSpec(cl, clusterspec); 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 ); std::cout << "DemoGeo::init_layered" << name << " so.center_extent " << so->center_extent << std::endl ; @@ -218,4 +232,3 @@ std::string DemoGeo::desc() const std::string s = ss.str(); return s ; } - diff --git a/CSG/tests/DemoGrid.cc b/CSG/tests/DemoGrid.cc index 46f8d4762b..625bedc461 100644 --- a/CSG/tests/DemoGrid.cc +++ b/CSG/tests/DemoGrid.cc @@ -1,8 +1,10 @@ +#include #include #include #include -#include "SStr.hh" +#include "ssys.h" +#include "sstr.h" #include "scuda.h" #include "saabb.h" @@ -11,6 +13,26 @@ #include "SLOG.hh" #include "CSGFoundry.h" +namespace +{ + void ParseGridSpec(std::array& grid, const char* spec) + { + std::vector values; + std::stringstream ss(spec ? spec : ""); + std::string item; + while(std::getline(ss, item, ',')) sstr::split(values, item.c_str(), ':'); + assert(values.size() == grid.size()); + std::copy(values.begin(), values.end(), grid.begin()); + } + + void GridMinMax(const std::array& grid, glm::ivec3& mn, glm::ivec3& mx) + { + mn.x = grid[0] ; mx.x = grid[1] ; + mn.y = grid[3] ; mx.y = grid[4] ; + mn.z = grid[6] ; mx.z = grid[7] ; + } +} + float4 DemoGrid::AddInstances( CSGFoundry* foundry_, unsigned ias_idx_, unsigned num_solid_ ) // static { @@ -23,17 +45,17 @@ DemoGrid::DemoGrid( CSGFoundry* foundry_, unsigned ias_idx_, unsigned num_solid_ foundry(foundry_), ias_idx(ias_idx_), num_solid(num_solid_), - gridscale(SStr::GetEValue("GRIDSCALE", 1.f)) + gridscale(ssys::getenvfloat("GRIDSCALE", 1.f)) { - std::string gridspec = SStr::GetEValue("GRIDSPEC","-10:11,2,-10:11:2,-10:11,2") ; - SStr::ParseGridSpec(grid, gridspec.c_str()); // string parsed into array of 9 ints - SStr::GetEVector(solid_modulo, "GRIDMODULO", "0,1" ); - SStr::GetEVector(solid_single, "GRIDSINGLE", "2" ); + std::string gridspec = ssys::getenv_("GRIDSPEC", "-10:11,2,-10:11:2,-10:11,2") ; + ParseGridSpec(grid, gridspec.c_str()); + ssys::fill_evec(solid_modulo, "GRIDMODULO", "0,1", ','); + ssys::fill_evec(solid_single, "GRIDSINGLE", "2", ','); LOG(info) << "GRIDSPEC " << gridspec ; LOG(info) << "GRIDSCALE " << gridscale ; - LOG(info) << "GRIDMODULO " << SStr::Present(solid_modulo) ; - LOG(info) << "GRIDSINGLE " << SStr::Present(solid_single) ; + LOG(info) << "GRIDMODULO " << ssys::desc_vec(&solid_modulo) ; + LOG(info) << "GRIDSINGLE " << ssys::desc_vec(&solid_single) ; init(); // add qat4 instances to foundry } @@ -43,7 +65,7 @@ const float4 DemoGrid::center_extent() const { glm::ivec3 imn(0,0,0); glm::ivec3 imx(0,0,0); - SStr::GridMinMax(grid, imn, imx); + GridMinMax(grid, imn, imx); float3 mn = gridscale*make_float3( float(imn.x), float(imn.y), float(imn.z) ) ; float3 mx = gridscale*make_float3( float(imx.x), float(imx.y), float(imx.z) ) ; @@ -105,4 +127,3 @@ void DemoGrid::init() } } } - diff --git a/CSGOptiX/CSGOptiX.cc b/CSGOptiX/CSGOptiX.cc index bd413e73b6..fef7dbbaa8 100644 --- a/CSGOptiX/CSGOptiX.cc +++ b/CSGOptiX/CSGOptiX.cc @@ -30,7 +30,7 @@ OptiX 7+ implementation of CSGFoundry geometry upload and launch. #include "SEventConfig.hh" #include "SGeoConfig.hh" #include "SSim.hh" -#include "SStr.hh" +#include "sstr.h" #include "SEvt.hh" #include "SMeta.hh" #include "SPath.hh" @@ -1370,7 +1370,7 @@ void CSGOptiX::snap(const char* path_, const char* bottom_line, const char* top_ LOG(LEVEL) << " path " << path ; const char* top_extra = pip->desc(); - const char* topline = SStr::Concat(top_line, top_extra); + const std::string topline = sstr::Concat_(top_line, top_extra); LOG(LEVEL) << " path_ [" << path_ << "]" ; LOG(LEVEL) << " topline " << topline ; @@ -1387,14 +1387,14 @@ void CSGOptiX::snap(const char* path_, const char* bottom_line, const char* top_ LOG(LEVEL) << "] frame.download " ; LOG(LEVEL) << "[ frame.annotate " ; - framebuf->annotate( bottom_line, topline, line_height ); + framebuf->annotate( bottom_line, topline.c_str(), line_height ); LOG(LEVEL) << "] frame.annotate " ; LOG(LEVEL) << "[ frame.snap " ; framebuf->snap( path ); LOG(LEVEL) << "] frame.snap " ; - if(!flight || SStr::Contains(path,"00000")) + if(!flight || sstr::Contains(path,"00000")) { saveMeta(path); } @@ -1416,7 +1416,7 @@ int CSGOptiX::render_flightpath() // for making mp4 movies void CSGOptiX::saveMeta(const char* jpg_path) const { - const char* json_path = SStr::ReplaceEnd(jpg_path, ".jpg", ".json"); + const std::string json_path = sstr::ReplaceEnd_(jpg_path, ".jpg", ".json"); LOG(LEVEL) << "[ json_path " << json_path ; nlohmann::json& js = meta->js ; @@ -1442,7 +1442,7 @@ void CSGOptiX::saveMeta(const char* jpg_path) const js["av"] = av ; } - meta->save(json_path); + meta->save(json_path.c_str()); LOG(LEVEL) << "] json_path " << json_path ; } diff --git a/CSGOptiX/Frame.cc b/CSGOptiX/Frame.cc index f70221ed78..2e5e5d3d6a 100644 --- a/CSGOptiX/Frame.cc +++ b/CSGOptiX/Frame.cc @@ -7,7 +7,7 @@ #include "SFrameConfig.hh" #include "SComp.h" -#include "SStr.hh" +#include "ssys.h" #include "SPath.hh" #include "SLOG.hh" #include "NP.hh" @@ -58,7 +58,7 @@ Frame::Frame(int width_, int height_, int depth_, uchar4* d_pixel_, float4* d_is height(height_), depth(depth_), channels(4), - jpg_quality(SStr::GetEValue("QUALITY", 50)), + jpg_quality(ssys::getenv_("QUALITY", 50)), img(new SIMG(width, height, channels, nullptr )), num_pixels(width*height), d_pixel(d_pixel_ == nullptr ? DeviceAlloc(num_pixels, mask & SCOMP_PIXEL ) : d_pixel_ ), diff --git a/qudarap/tests/QCKTest.cc b/qudarap/tests/QCKTest.cc index b63058070c..aaaae9fe6a 100644 --- a/qudarap/tests/QCKTest.cc +++ b/qudarap/tests/QCKTest.cc @@ -12,7 +12,6 @@ by both lookup sampling and for comparison by the traditional rejection sampling #include #include -#include "SStr.hh" #include "SRng.hh" #include "SPath.hh" #include "QCK.hh" @@ -198,4 +197,3 @@ int main(int argc, char** argv) return 0 ; } - diff --git a/sysrap/CMakeLists.txt b/sysrap/CMakeLists.txt index 3e742c9b56..db0e04ceef 100644 --- a/sysrap/CMakeLists.txt +++ b/sysrap/CMakeLists.txt @@ -24,8 +24,6 @@ set(SOURCES SProf.cc SMeta.cc - - SStr.cc SPath.cc SSeq.cc STranche.cc @@ -147,7 +145,6 @@ set(HEADERS SSys.hh sstr.h - SStr.hh schrono.h stimer.h diff --git a/sysrap/SEnabled.cc b/sysrap/SEnabled.cc index 68ca30c5ee..eaa9f16d5e 100644 --- a/sysrap/SEnabled.cc +++ b/sysrap/SEnabled.cc @@ -1,5 +1,5 @@ #include -#include "SStr.hh" +#include "sstr.h" #include "SEnabled.hh" template @@ -9,7 +9,7 @@ SEnabled::SEnabled(const char* spec) { char delim = ',' ; std::vector ivec ; - SStr::ISplit( spec, ivec, delim ); + sstr::split( ivec, spec, delim ); for(unsigned i=0 ; i < ivec.size() ; i++) { @@ -40,4 +40,3 @@ template struct SEnabled<256>; template struct SEnabled<512>; template struct SEnabled<1024>; - diff --git a/sysrap/SOpticks.cc b/sysrap/SOpticks.cc index 731bdca3f6..15a6ff3a0c 100644 --- a/sysrap/SOpticks.cc +++ b/sysrap/SOpticks.cc @@ -1,7 +1,7 @@ #include "SArgs.hh" #include "s_time.h" -#include "SStr.hh" +#include "spath.h" #include "sproc.h" #include "SOpticks.hh" #include "SEventConfig.hh" @@ -56,10 +56,7 @@ const char* SOpticks::getOutDir() const const char* SOpticks::CFBaseScriptPath() { - std::stringstream ss ; - ss << "/tmp/CFBASE.sh" ; - std::string s = ss.str(); - return strdup(s.c_str()); + return strdup("/tmp/CFBASE.sh"); } std::string SOpticks::CFBaseScriptString(const char* cfbase, const char* msg ) @@ -95,7 +92,7 @@ void SOpticks::WriteCFBaseScript(const char* cfbase, const char* msg) << "]" ; - SStr::Save(sh_path, sh.c_str()) ; + spath::Write(sh.c_str(), sh_path) ; } @@ -121,8 +118,8 @@ void SOpticks::WriteOutputDirScript() // static void SOpticks::WriteOutputDirScript(const char* outdir) // static { const char* exename = sproc::ExecutableName() ; - const char* envvar = SStr::Concat(exename, "_OUTPUT_DIR" ); - const char* sh_path = SStr::Concat(exename, "_OUTPUT_DIR" , ".sh") ; + const std::string envvar = std::string(exename) + "_OUTPUT_DIR" ; + const std::string sh_path = envvar + ".sh" ; std::stringstream ss ; ss @@ -143,10 +140,9 @@ void SOpticks::WriteOutputDirScript(const char* outdir) // static << "]" ; - SStr::Save(sh_path, sh.c_str()) ; + spath::Write(sh.c_str(), sh_path.c_str()) ; } - diff --git a/sysrap/SOpticksKey.cc b/sysrap/SOpticksKey.cc index 047fb0c995..c20326a459 100644 --- a/sysrap/SOpticksKey.cc +++ b/sysrap/SOpticksKey.cc @@ -27,7 +27,7 @@ #include "SAr.hh" #include "SSys.hh" #include "SDigest.hh" -#include "SStr.hh" +#include "sstr.h" #include "SPath.hh" #include "SOpticksKey.hh" @@ -64,7 +64,7 @@ SOpticksKey* SOpticksKey::GetKey() const char* SOpticksKey::StemName( const char* ext, const char* sep ) { - return SStr::Concat(IDSTEM, sep, ext ); + return sstr::Concat(IDSTEM, sep, ext ); } @@ -152,7 +152,7 @@ SOpticksKey::SOpticksKey(const char* spec) m_live(false) { std::vector elem ; - SStr::Split(spec, '.', elem ); + sstr::Split(spec, '.', elem ); bool four = elem.size() == 4 ; LOG_IF(fatal, !four) << " expecting 4 element spec delimited by dot [" << spec << "]" ; @@ -262,4 +262,3 @@ const char* SOpticksKey::getIdPath(const char* base) const - diff --git a/sysrap/SOpticksResource.cc b/sysrap/SOpticksResource.cc index 3d4d896dd1..b1e735af0f 100644 --- a/sysrap/SOpticksResource.cc +++ b/sysrap/SOpticksResource.cc @@ -5,7 +5,6 @@ #include "SSys.hh" #include "ssys.h" -#include "SStr.hh" #include "sstr.h" #include "spath.h" @@ -547,14 +546,14 @@ const char* SOpticksResource::Get(const char* key) // static std::string SOpticksResource::Desc() { std::vector keys ; - SStr::Split(KEYS, ' ', keys); + sstr::Split(KEYS, ' ', keys); std::stringstream ss ; ss << "SOpticksResource::Desc" << std::endl ; for(unsigned i=0 ; i < keys.size() ; i++ ) { const char* key = keys[i].c_str() ; - std::string lab = SStr::Format("SOpticksResource::Get(\"%s\") ", key) ; + std::string lab = sstr::Format_("SOpticksResource::Get(\"%s\") ", key) ; const char* val = Get(key); ss << std::setw(70) << lab.c_str() @@ -592,4 +591,3 @@ std::string SOpticksResource::Desc() std::string s = ss.str(); return s ; } - diff --git a/sysrap/SPPM.cc b/sysrap/SPPM.cc index d81fb48bc3..d053ac87dc 100644 --- a/sysrap/SPPM.cc +++ b/sysrap/SPPM.cc @@ -22,7 +22,7 @@ #include #include "SLOG.hh" -#include "SStr.hh" +#include "sstr.h" #include "SColor.hh" #include "SPPM.hh" @@ -222,7 +222,7 @@ void SPPM::dumpHeader( const char* path ) int SPPM::readHeader( const char* path, unsigned& width, unsigned& height, unsigned& mode, unsigned& bits ) { - assert(SStr::EndsWith(path, ".ppm")); + assert(sstr::EndsWith(path, ".ppm")); std::ifstream f(path, std::ios::binary); if(f.fail()) { @@ -277,7 +277,7 @@ A row of an image is horizontal. A column is vertical. The pixels in the image a int SPPM::read( const char* path, std::vector& img, unsigned& width, unsigned& height, const unsigned ncomp, const bool yflip ) { - assert(SStr::EndsWith(path, ".ppm")); + assert(sstr::EndsWith(path, ".ppm")); std::ifstream f(path, std::ios::binary); if(f.fail()) @@ -481,17 +481,17 @@ unsigned char* SPPM::MakeTestImage(const int width, const int height, const int unsigned char jj = (1.-fj)*255.f ; SColor col = SColors::white ; - if( SStr::Contains(config, "checkerboard") ) + if( sstr::Contains(config, "checkerboard") ) { if( mi < 4 ) col = SColors::black ; else if (mj < 4 ) col = SColors::red ; else col = { jj, jj, jj } ; } - else if( SStr::Contains(config, "horizontal_gradient") ) + else if( sstr::Contains(config, "horizontal_gradient") ) { col = { jj , jj, jj } ; } - else if( SStr::Contains(config, "vertical_gradient") ) + else if( sstr::Contains(config, "vertical_gradient") ) { col = { ii , ii, ii } ; } @@ -503,9 +503,9 @@ unsigned char* SPPM::MakeTestImage(const int width, const int height, const int } - bool add_border = SStr::Contains(config, "add_border") ; - bool add_midline = SStr::Contains(config, "add_midline") ; - bool add_quadline = SStr::Contains(config, "add_quadline") ; + bool add_border = sstr::Contains(config, "add_border") ; + bool add_midline = sstr::Contains(config, "add_midline") ; + bool add_quadline = sstr::Contains(config, "add_quadline") ; if(add_border) SPPM::AddBorder(imgdata, width, height, ncomp, yflip); if(add_midline) SPPM::AddMidline(imgdata, width, height, ncomp, yflip); @@ -568,4 +568,3 @@ unsigned SPPM::ImageCompare(const int width, const int height, const int ncomp, } - diff --git a/sysrap/SPath.cc b/sysrap/SPath.cc index eb2a091c34..a577a91e67 100644 --- a/sysrap/SPath.cc +++ b/sysrap/SPath.cc @@ -36,7 +36,8 @@ #include // for chdir -#include "SStr.hh" +#include + #include "SPath.hh" #include "SOpticksResource.hh" #include "SLOG.hh" @@ -44,6 +45,25 @@ const plog::Severity SPath::LEVEL = SLOG::EnvLevel("SPath", "DEBUG"); +namespace +{ + std::string FormatResolveIndex(int idx, bool prefix, int wid=3) + { + std::stringstream ss ; + if(prefix) ss << ( idx == 0 ? 'z' : ( idx < 0 ? 'n' : 'p' ) ); + ss << std::setfill('0') << std::setw(wid) << std::abs(idx) ; + return ss.str(); + } + + template + std::string FormatFixedReal(const T value, int w, int p, char fill='0') + { + std::stringstream ss ; + ss << std::fixed << std::setfill(fill) << std::setw(w) << std::setprecision(p) << value ; + return ss.str(); + } +} + const char* SPath::Stem( const char* name ) // static { @@ -325,17 +345,20 @@ const char* SPath::Resolve(const char* dir, const char* reldir, const char* rel2 const char* SPath::Resolve(const char* dir, int idx, int create_dirs) { bool prefix = true ; - return SPath::Resolve(dir, SStr::FormatIndex(idx, prefix), create_dirs); + const std::string name = FormatResolveIndex(idx, prefix); + return SPath::Resolve(dir, name.c_str(), create_dirs); } const char* SPath::Resolve(const char* dir, const char* name, int idx, int create_dirs) { bool prefix = true ; - return SPath::Resolve(dir, name, SStr::FormatIndex(idx, prefix), create_dirs); + const std::string leaf = FormatResolveIndex(idx, prefix); + return SPath::Resolve(dir, name, leaf.c_str(), create_dirs); } const char* SPath::Resolve(const char* dir, const char* reldir, const char* name, int idx, int create_dirs) { bool prefix = true ; - return SPath::Resolve(dir, reldir, name, SStr::FormatIndex(idx, prefix), create_dirs); + const std::string leaf = FormatResolveIndex(idx, prefix); + return SPath::Resolve(dir, reldir, name, leaf.c_str(), create_dirs); } @@ -509,9 +532,9 @@ int SPath::mtime(const char* path) template const char* SPath::MakePath( const char* prefix, const char* reldir, const T real, const char* name) // static { - const char* sreal = SStr::FormatReal(real, 6, 4, '0'); + const std::string sreal = FormatFixedReal(real, 6, 4, '0'); int create_dirs = 2 ; // 2:dirpath - const char* fold = SPath::Resolve(prefix, reldir, sreal, create_dirs ); + const char* fold = SPath::Resolve(prefix, reldir, sreal.c_str(), create_dirs ); const char* path = SPath::Resolve(fold, name, 0 ) ; // 0:create_dirs nop return path ; } @@ -543,13 +566,15 @@ std::string SPath::MakeName( const char* stem, int index, const char* ext ) std::string name ; if( index > -1 ) { + std::stringstream ss ; + ss << std::setfill('0') << std::setw(5) << index ; if( stem && ext ) { - name = SStr::Format("%s%0.5d%s", stem, index, ext ) ; + name = std::string(stem) + ss.str() + ext ; } else if( stem == nullptr && ext ) { - name = SStr::Format("%0.5d%s", index, ext ) ; + name = ss.str() + ext ; } } else @@ -671,4 +696,3 @@ template const char* SPath::Join( const char*, const char* ); template const char* SPath::Join( const char*, const char*, const char* ); template const char* SPath::Join( const char*, const char*, const char*, const char* ); - diff --git a/sysrap/SSim.cc b/sysrap/SSim.cc index 3d07f03ec4..a5fe937b81 100644 --- a/sysrap/SSim.cc +++ b/sysrap/SSim.cc @@ -8,7 +8,7 @@ #include "stree.h" #include "SLOG.hh" -#include "SStr.hh" +#include "sstr.h" #include "ssys.h" #include "spath.h" #include "sstamp.h" @@ -724,9 +724,9 @@ NP* SSim::AddOptical( for(unsigned b=0 ; b < num_add ; b++) { - const char* spec = SStr::Trim(specs[b].c_str()); + const std::string spec = sstr::TrimString(specs[b]); std::vector elem ; - SStr::Split(spec, '/', elem ); + sstr::Split(spec.c_str(), '/', elem ); bool four_elem = elem.size() == 4 ; LOG_IF(fatal, four_elem == false) << " expecting four elem spec [" << spec << "] elem.size " << elem.size() ; @@ -853,11 +853,11 @@ NP* SSim::AddBoundary( const NP* dsrc, const std::vector& specs ) / for(unsigned b=0 ; b < specs.size() ; b++) { - const char* spec = SStr::Trim(specs[b].c_str()); + const std::string spec = sstr::TrimString(specs[b]); dst_names.push_back(spec); std::vector elem ; - SStr::Split(spec, '/', elem ); + sstr::Split(spec.c_str(), '/', elem ); bool four_elem = elem.size() == 4 ; LOG_IF(fatal, four_elem == false) << " expecting four elem spec [" << spec << "] elem.size " << elem.size() ; @@ -1029,7 +1029,7 @@ std::string SSim::DescOptical(const NP* optical, const NP* bnd ) { elem.clear(); const std::string& spec = bnd->names[b] ; - SStr::Split( spec.c_str(), '/', elem ); + sstr::Split( spec.c_str(), '/', elem ); ss << std::setw(4) << b << " " << spec<< std::endl ; } @@ -1079,4 +1079,3 @@ bool SSim::findName( int& i, int& j, const char* qname ) const - diff --git a/sysrap/SStr.cc b/sysrap/SStr.cc deleted file mode 100644 index c7b874a0b7..0000000000 --- a/sysrap/SStr.cc +++ /dev/null @@ -1,1136 +0,0 @@ -/* - * Copyright (c) 2019 Opticks Team. All Rights Reserved. - * - * This file is part of Opticks - * (see https://bitbucket.org/simoncblyth/opticks). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#include "SStr.hh" -#include "SPath.hh" -#include "spath.h" -#include "SLOG.hh" - - -const plog::Severity SStr::LEVEL = SLOG::EnvLevel("SStr", "DEBUG"); - - -/** - -In [15]: s = "hello" - -In [18]: encode_ = lambda s:sum(map(lambda ic:ord(ic[1]) << 8*ic[0], enumerate(s[:8]) )) - -In [19]: encode_(s) -Out[19]: 478560413032 - -In [40]: decode_ = lambda v:"".join(map( lambda c:str(unichr(c)), filter(None,map(lambda i:(v >> i*8) & 0xff, range(8))) )) - -In [41]: decode_(478560413032) -Out[41]: 'hello' - -Hmm presumably base64 code might do this at a higher level ? - -**/ - - - - -void SStr::Save(const char* path_, const std::vector& a, char delim ) // static -{ - bool in_pwd = strchr(path_, '/' ) == nullptr ; - int create_dirs = in_pwd ? NOOP : FILEPATH ; - const char* path = SPath::Resolve(path_, create_dirs); // - LOG(info) << "SPath::Resolve " << path_ << " to " << path ; - std::ofstream fp(path); - for(std::vector::const_iterator i = a.begin(); i != a.end(); ++i) fp << *i << delim ; -} - - -/** -SStr::Save ------------ - -Formerly when saving into PWD it was necessary to manually set create_dirs to 0 -otherwise the file is not written but rather an empty directory was created and no file written. - -This issue has been fixed by checking for a "/" in the path and setting create_dirs accordingly. - -**/ - -void SStr::Save(const char* path_, const char* txt ) -{ - bool in_pwd = strchr(path_, '/' ) == nullptr ; - int create_dirs = in_pwd ? NOOP : FILEPATH ; - - const char* path = SPath::Resolve(path_, create_dirs ); - LOG(LEVEL) << "SPath::Resolve " << path_ << " to " << path << " create_dirs " << create_dirs << " in_pwd " << in_pwd ; - std::ofstream fp(path); - fp << txt ; -} - -const char* SStr::Load(const char* path_ ) -{ - int create_dirs = 0 ; // 0:do nothing - const char* path = SPath::Resolve(path_, create_dirs); // - LOG(LEVEL) << "SPath::Resolve " << path_ << " to " << path ; - std::ifstream fp(path); - - std::stringstream ss ; - ss << fp.rdbuf() ; - std::string txt = ss.str(); - return strdup(txt.c_str()) ; -} - -/** -SStr::LoadList ----------------- - -Interprets the arg as either a filepath with lines to be loaded -or a comma delimited string to be split into lines. - -**/ - -void SStr::LoadList(const char* arg, std::vector& lines, char delim ) -{ - if(arg == nullptr) return ; - - if(spath::LooksLikePath(arg) && delim == '\n' ) // eg starts with slash - { - std::ifstream ifs(arg); - std::string line; - while(std::getline(ifs, line)) lines.push_back(line) ; - } - else if( delim == ',' ) - { - SStr::Split( arg, delim, lines ); - LOG(LEVEL) << "split " << arg << " into " << lines.size() ; - } - else - { - lines.push_back(arg); - } -} - -std::vector* SStr::LoadList( const char* arg, char delim ) -{ - if(arg == nullptr) return nullptr ; - typedef std::vector VS ; - VS* lines = new VS ; - LoadList(arg, *lines, delim ); - return lines ; -} - - - - - - - - - -void SStr::FillFromULL( char* dest, unsigned long long value, char unprintable) -{ - dest[8] = '\0' ; - for( ULL w=0 ; w < 8 ; w++) - { - ULL ullc = (value & (0xffull << w*8)) >> w*8 ; - char c = static_cast(ullc) ; - bool printable = c >= ' ' && c <= '~' ; - dest[w] = printable ? c : unprintable ; - } -} - -const char* SStr::FromULL( unsigned long long value, char unprintable) -{ - assert( sizeof(ULL) == 8 ); - char* s = new char[8+1] ; - FillFromULL(s, value, unprintable) ; - return s ; -} - - -unsigned long long SStr::ToULL( const char* s ) -{ - assert( sizeof(ULL) == 8 ); - - unsigned len = s ? strlen(s) : 0 ; - ULL mxw = len < 8 ? len : 8 ; - - ULL v = 0ull ; - for(ULL w=0 ; w < mxw ; w++) - { - ULL c = s[w] ; - v |= ( c << 8ull*w ) ; - } - return v ; -} - - - - -template -const char* SStr::FormatInt( const char* fmt, int value ) -{ - char buf[SIZE]; - size_t cx = snprintf( buf, SIZE, fmt, value ); - bool expect = cx < SIZE ; - if(!expect) std::cerr << "SStr::FormatInt TRUNCATION " << std::endl; - assert( expect && "snprintf truncation detected" ); - return strdup(buf); -} - -template const char* SStr::FormatInt<8>( const char* , int ); -template const char* SStr::FormatInt<64>( const char* , int ); - - -const char* SStr::FormatIndex( int idx, bool prefix, int wid ) -{ - std::stringstream ss ; - if(prefix) ss << ( idx == 0 ? "z" : ( idx < 0 ? "n" : "p" ) ) ; - ss << std::setfill('0') << std::setw(wid) << std::abs(idx) ; - std::string s = ss.str(); - return strdup(s.c_str()); -} - - - - -template -const char* SStr::Format1( const char* fmt, const char* value ) -{ - char buf[SIZE]; - size_t cx = snprintf( buf, SIZE, fmt, value ); - bool expect = cx < SIZE ; - if(!expect) std::cerr << "SStr::Format1 TRUNCATION " << std::endl; - assert( expect && "snprintf truncation detected" ); - return strdup(buf); -} - -template -const char* SStr::Format2( const char* fmt, const char* value1, const char* value2 ) -{ - char buf[SIZE]; - size_t cx = snprintf( buf, SIZE, fmt, value1, value2 ); - bool expect = cx < SIZE ; - if(!expect) std::cerr << "SStr::Format2 TRUNCATION " << std::endl; - assert( expect && "snprintf truncation detected" ); - return strdup(buf); -} - -template -const char* SStr::Format3( const char* fmt, const char* value1, const char* value2, const char* value3 ) -{ - char buf[SIZE]; - size_t cx = snprintf( buf, SIZE, fmt, value1, value2, value3 ); - bool expect = cx < SIZE ; - if(!expect) std::cerr << "SStr::Format3 TRUNCATION " << std::endl; - assert( expect && "snprintf truncation detected" ); - return strdup(buf); -} - - - -template const char* SStr::Format1<256>( const char* , const char* ); -template const char* SStr::Format2<256>( const char* , const char*, const char* ); -template const char* SStr::Format3<256>( const char* , const char*, const char* , const char* ); - -template const char* SStr::Format1<16>( const char* , const char* ); - - -template -const char* SStr::FormatReal(const T value, int w, int p, char fill ) -{ - std::stringstream ss ; - ss << std::fixed << std::setfill(fill) << std::setw(w) << std::setprecision(p) << value ; - std::string s = ss.str(); - return strdup(s.c_str()) ; -} - -template const char* SStr::FormatReal(const float, int, int, char ); -template const char* SStr::FormatReal(const double, int, int, char ); - - -template -std::string SStr::Format_( const char* fmt, Args ... args ) -{ - // see sysrap/tests/StringFormatTest.cc - int sz = std::snprintf( nullptr, 0, fmt, args ... ) + 1; // +1 for null termination - assert( sz > 0 ); - std::vector buf(sz) ; - std::snprintf( buf.data(), sz, fmt, args ... ); - return std::string( buf.begin(), buf.begin() + sz - 1 ); // exclude null termination -} - -template std::string SStr::Format_( const char*, const char* ); -template std::string SStr::Format_( const char* , int, double ); -template std::string SStr::Format_( const char* , int ); -template std::string SStr::Format_( const char* , int, const char* ); -template std::string SStr::Format_( const char* , unsigned ); -template std::string SStr::Format_( const char*, const char* , const char* ); -template std::string SStr::Format_( const char*, const char* , int, const char* ); - - -template -const char* SStr::Format( const char* fmt, Args ... args ) -{ - std::string s = Format_(fmt, args...) ; - return strdup(s.c_str()); -} - -template const char* SStr::Format( const char*, const char* ); -template const char* SStr::Format( const char* , int, double ); -template const char* SStr::Format( const char* , int ); -template const char* SStr::Format( const char* , int, const char* ); -template const char* SStr::Format( const char* , unsigned ); -template const char* SStr::Format( const char*, const char* , const char* ); -template const char* SStr::Format( const char*, const char* , int, const char* ); - - - -/** - -replace with spath::Name - -template -const char* SStr::Name( Args ... elem_ ) -{ - std::vector elem = {elem_...}; - std::stringstream ss ; - for(unsigned i=0 ; i < elem.size() ; i++) ss << elem[i] ; - std::string s = ss.str(); - return strdup(s.c_str()) ; -} - -template const char* SStr::Name( const char* ); -template const char* SStr::Name( const char*, const char* ); -template const char* SStr::Name( const char*, const char*, const char* ); - -**/ - - - -bool SStr::Blank( const char* s ) -{ - unsigned n = strlen(s) ; - return n == 0 || All(s, ' ') ; -} - -bool SStr::All( const char* s , char q ) -{ - unsigned n = strlen(s) ; - return n > 0 && Count(s, q) == n ; - -} -unsigned SStr::Count( const char* s , char q ) -{ - unsigned n = strlen(s) ; - unsigned count = 0 ; - for(unsigned i=0 ; i < n ; i++) if( s[i] == q ) count += 1 ; - return count ; -} - -bool SStr::Contains( const char* s_ , const char* q_ ) -{ - std::string s(s_); - std::string q(q_); - return s.find(q) != std::string::npos ; -} - -/** -SStr::EndsWith ---------------- - -eg:: - - SStr::EndsWith("name.npy", ".npy") == true - - -**/ -bool SStr::EndsWith( const char* s, const char* q) -{ - int pos = strlen(s) - strlen(q) ; - return pos > 0 && strncmp(s + pos, q, strlen(q)) == 0 ; -} - -const char* SStr::StripPrefix_(const char* s, const char* pfx ) -{ - const char* ss = pfx && StartsWith(s, pfx ) ? s + strlen(pfx) : s ; - return strdup(ss); -} - - - - -const char* SStr::StripPrefix(const char* s, const char* pfx0, const char* pfx1, const char* pfx2 ) -{ - if( pfx0 && StartsWith(s,pfx0) ) return StripPrefix_(s, pfx0) ; - else if( pfx1 && StartsWith(s,pfx1) ) return StripPrefix_(s, pfx1) ; - else if( pfx2 && StartsWith(s,pfx2) ) return StripPrefix_(s, pfx2) ; - return strdup(s); -} - -const char* SStr::MaterialBaseName(const char* s ) -{ - return StripPrefix(s, "/dd/Materials/", "_dd_Materials_" ); -} - -/** -SStr::StartsWith ------------------- - -The 2nd query string must be less than or equal to the length of the first string and -all the characters of the query string must match with the first string in order -to return true. - -**/ - -bool SStr::StartsWith( const char* s, const char* q) -{ - return s && q && strlen(q) <= strlen(s) && strncmp(s, q, strlen(q)) == 0 ; -} - - - - -const char* SStr::AZaz = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ; - -bool SStr::StartsWithLetterAZaz(const char* q ) -{ - const char* p = q != nullptr && strlen(q) > 0 ? strchr(AZaz, q[0]) : nullptr ; - return p != nullptr ; -} - - - - - -/** -SStr::SimpleMatch ---------------------- - -Return if the argument string s matches the query string q -If q ends with '$' require a full match otherwise allow -StartsWith match. - -**/ -bool SStr::SimpleMatch(const char* s, const char* q ) -{ - unsigned ls = strlen(s); - unsigned lq = strlen(q); - - if(ls == 0 ) return false ; - if(lq == 0 ) return false ; - - bool qed = q[lq-1] == '$' || q[lq-1] == '@' ; - bool qed_match = 0 == strncmp(s, q, lq - 1) && ls == lq - 1 ; // exact match up to the dollar - return qed ? qed_match : StartsWith(s, q) ; -} - - - -/** -SStr::Match -------------- - -Based on https://www.geeksforgeeks.org/wildcard-character-matching/ - -See tests/match.cc - - -The second argument string can contain wildcard tokens: - -`*` - matches with 0 or more of any char (NB '**' not supported) -`?` - matches any one character. -`$` or '@' - when appearing at end of q requires the end of s to match - -**/ - -bool SStr::Match(const char* s, const char* q) -{ - if (*q == '\0' && *s == '\0') return true; - - if (*q == '*' && *(q+1) != '\0' && *s == '\0') return false; // reached end of s but still q chars coming - - if ( (*q == '$' || *q == '@') && *(q+1) == '\0' && *s == '\0' ) return true ; - - if (*q == '?' || *q == *s) return SStr::Match(s+1, q+1); // on to next char - - if (*q == '*') return SStr::Match(s, q+1) || SStr::Match(s+1, q); // '*' can match nothing or anything in s, including literal '*' - - return false; -} - -/** - -SStr::HasPointerSuffix ------------------------ - -Typically see 12 hexdigit pointers, as even though have 64 bits it is normal to only use 48 bits in an address space - 0x7ff46e500520 - -But with G4 are seeing only 9 hexdigits ?? - - -**/ - -bool SStr::HasPointerSuffix( const char* name, unsigned hexdigits ) -{ - // eg Det0x110d9a820 why 9 hex digits vs - // 0x7ff46e500520 - // - std::string s(name); - unsigned l = s.size() ; - if(l < hexdigits+2 ) return false ; - - for(unsigned i=0 ; i < hexdigits+2 ; i++) - { - char c = s[l-11+i] ; - bool ok = false ; - switch(i) - { - case 0: ok = c == '0' ; break ; - case 1: ok = c == 'x' ; break ; - default: ok = ( c >= '0' && c <= '9' ) || ( c >= 'a' && c <= 'f' ) ; break ; - } - if(!ok) return false ; - } - return true ; -} - - -/** -SStr::GetPointerSuffixDigits ------------------------------- - -Check for hexdigits backwards, until reach first non-hexdigit the 'x':: - - World0x7fc10641cbb0 -> 12 - Det0x110fa38b0 -> 9 - Hello -> -1 - -**/ - -int SStr::GetPointerSuffixDigits( const char* name ) -{ - if( name == NULL ) return -1 ; - int l = strlen(name) ; - int num = 0 ; - for(int i=0 ; i < l ; i++ ) - { - char c = *(name + l - 1 - i) ; // reverse order chars - bool hexdigit = ( c >= '0' && c <= '9' ) || ( c >= 'a' && c <= 'f' ) ; - if(!hexdigit) break ; - num += 1 ; - } - //std::cout << std::endl ; - if(l - num - 1 < 0 ) return -1 ; - if(l - num - 2 < 0 ) return -1 ; - - char c1 = *(name + l - num - 1); - char c2 = *(name + l - num - 2); - - return c1 == 'x' && c2 == '0' ? num : -1 ; -} - -/** -SStr::HasPointerSuffix ------------------------- - -Returns true when the number of hex digits is within the inclusive min-max range. - -**/ - -bool SStr::HasPointerSuffix( const char* name, unsigned min_hexdigits, unsigned max_hexdigits ) -{ - int num_hexdigits = GetPointerSuffixDigits( name ); - return num_hexdigits > -1 && num_hexdigits >= int(min_hexdigits) && num_hexdigits <= int(max_hexdigits) ; -} - -/** -SStr::TrimPointerSuffix -------------------------- - -For an input name such as "SomeName0xdeadbeef" returns "SomeName" - -**/ -const char* SStr::TrimPointerSuffix( const char* name ) -{ - int num_hexdigits = GetPointerSuffixDigits( name ); // char-by-char look back - char* trim = strdup(name); - - if( num_hexdigits >= 6 && num_hexdigits <= 12 ) // sanity check for the pointer suffix - { - int ip = strlen(name) - num_hexdigits - 2 ; // offset to land on the '0' of "SomeName0xdeadbeef" - assert( ip >= 0 ); - char* p = trim + ip ; - assert( *p == '0' ); - *p = '\0' ; // terminate string chopping off the suffix eg "0xdeadbeef" - } - return trim ; -} - - - -const char* SStr::TrimLeading(const char* s) -{ - char* p = strdup(s); - while( *p && ( *p == ' ' || *p == '\n' )) p++ ; - return p ; -} -const char* SStr::TrimTrailing(const char* s) -{ - char* p = strdup(s); - char* e = p + strlen(p) - 1 ; - while(e > p && ( *e == ' ' || *e == '\n' )) e-- ; - e[1] = '\0' ; - return p ; -} -const char* SStr::Trim(const char* s) // trim leading and trailing whitespace -{ - char* p = strdup(s); - char* e = p + strlen(p) - 1 ; - while(e > p && ( *e == ' ' || *e == '\n' )) e-- ; - *(e+1) = '\0' ; - while( *p && ( *p == ' ' || *p == '\n')) p++ ; - return p ; -} - -/** -SStr::HeadFirst ------------------ - -Returns string up until the first occurence of the char -or the entire string of the char does not occur. - -For example:: - - SStr::HeadFirst("AltXJFixtureConstruction_XZ", '_') -> "AltXJFixtureConstruction" - -**/ - -const char* SStr::HeadFirst(const char* s_, char c ) -{ - char* s = strdup(s_); - char* p = strchr(s, c ); - if(p) *p = '\0' ; // terminate string at first occurence of c - return s ; -} - -/** -SStr::HeadLast ------------------ - -Returns string up until the last occurence of the char -or the entire string of the char does not occur. - -For example:: - - SStr::HeadLast("AltXJFixtureConstruction_OtherSuffix_XZ", '_') -> "AltXJFixtureConstruction_OtherSuffix" - -**/ - -const char* SStr::HeadLast(const char* s_, char c ) -{ - char* s = strdup(s_); - char* p = strrchr(s, c ); - if(p) *p = '\0' ; // terminate string at last occurence of c - return s ; -} - - - -const char* SStr::Concat( const char* a, const char* b, const char* c ) -{ - std::stringstream ss ; - if(a) ss << a ; - if(b) ss << b ; - if(c) ss << c ; - std::string s = ss.str(); - return strdup(s.c_str()); -} - -const char* SStr::Concat( const char* a, unsigned b, const char* c ) -{ - std::stringstream ss ; - if(a) ss << a ; - ss << b ; - if(c) ss << c ; - std::string s = ss.str(); - return strdup(s.c_str()); -} - -const char* SStr::Concat( const char* a, unsigned b, const char* c, unsigned d, const char* e ) -{ - std::stringstream ss ; - - if(a) ss << a ; - ss << b ; - if(c) ss << c ; - ss << d ; - if(e) ss << e ; - - std::string s = ss.str(); - return strdup(s.c_str()); -} - - -template -const char* SStr::Concat_( const char* a, T b, const char* c ) -{ - std::stringstream ss ; - if(a) ss << a ; - ss << b ; - if(c) ss << c ; - std::string s = ss.str(); - return strdup(s.c_str()); -} - - - -const char* SStr::Replace( const char* s, char a, char b ) -{ - std::stringstream ss ; - for(unsigned i=0 ; i < strlen(s) ; i++) - { - char c = *(s+i) ; - ss << ( c == a ? b : c ) ; - } - std::string r = ss.str(); - return strdup(r.c_str()); -} - - -/** -SStr::ReplaceEnd ------------------- - -String s is required to have ending q. -New string n is returned with the ending q replaced with r. - -**/ - -const char* SStr::ReplaceEnd( const char* s, const char* q, const char* r ) -{ - int pos = strlen(s) - strlen(q) ; - assert( pos > 0 && strncmp(s + pos, q, strlen(q)) == 0 ); - - std::stringstream ss ; - for(int i=0 ; i < pos ; i++) ss << *(s+i) ; - ss << r ; - - std::string n = ss.str(); - return strdup(n.c_str()); -} - - - - - - -void SStr::Split( const char* str, char delim, std::vector& elem ) -{ - std::stringstream ss; - ss.str(str) ; - std::string s; - while (std::getline(ss, s, delim)) elem.push_back(s) ; -} - -/** -SStr::ISplit -------------- - -Usage:: - - std::vector pos ; - SStr::ISplit( spec_, pos, ',' ); - -Replace with:: - - sstr::split( pos, spec_ , ',' ) - -**/ - -int SStr::ISplit( const char* line, std::vector& ivec, char delim ) -{ - std::stringstream ss; - ss.str(line) ; - - std::string s; - while (std::getline(ss, s, delim)) ivec.push_back(std::atoi(s.c_str())) ; - - return ivec.size(); -} - -std::vector* SStr::ISplit( const char* line, char delim ) -{ - std::vector* ivec = new std::vector() ; - ISplit(line, *ivec, delim ); - return ivec ; -} - - - -template const char* SStr::Concat_( const char* , unsigned , const char* ); -template const char* SStr::Concat_( const char* , unsigned long long , const char* ); -template const char* SStr::Concat_( const char* , int , const char* ); -template const char* SStr::Concat_( const char* , long , const char* ); - - - - -void SStr::ParseGridSpec( std::array& grid, const char* spec) // static -{ - int idx = 0 ; - std::stringstream ss(spec); - std::string s; - while (std::getline(ss, s, ',')) - { - std::stringstream tt(s); - std::string t; - while (std::getline(tt, t, ':')) grid[idx++] = std::atoi(t.c_str()) ; - } - - std::stringstream uu ; - uu << spec << " : " ; - for(int i=0 ; i < 9 ; i++) uu << grid[i] << " " ; - uu << std::endl ; - - std::string u = ss.str(); - LOG(info) << u ; -} - - -void SStr::DumpGrid(const std::array& cl) -{ - int i0 = cl[0] ; - int i1 = cl[1] ; - int is = cl[2] ; - int j0 = cl[3] ; - int j1 = cl[4] ; - int js = cl[5] ; - int k0 = cl[6] ; - int k1 = cl[7] ; - int ks = cl[8] ; - - unsigned num = 0 ; - for(int i=i0 ; i < i1 ; i+=is ) - for(int j=j0 ; j < j1 ; j+=js ) - for(int k=k0 ; k < k1 ; k+=ks ) - { - std::cout << std::setw(2) << num << " (i,j,k) " << "(" << i << "," << j << "," << k << ") " << std::endl ; - num += 1 ; - } -} - - - - - - -template -void SStr::GetEVector(std::vector& vec, const char* key, const char* fallback ) -{ - const char* sval = getenv(key); - std::stringstream ss(sval ? sval : fallback); - std::string s ; - while(getline(ss, s, ',')) vec.push_back(ato_(s.c_str())); -} - -template void SStr::GetEVector(std::vector& vec, const char* key, const char* fallback ); -template void SStr::GetEVector(std::vector& vec, const char* key, const char* fallback ); - -void SStr::GetEVec(glm::vec3& v, const char* key, const char* fallback ) -{ - std::vector vec ; - SStr::GetEVector(vec, key, fallback); - std::cout << key << SStr::Present(vec) << std::endl ; - assert( vec.size() == 3 ); - for(int i=0 ; i < 3 ; i++) v[i] = vec[i] ; -} - -void SStr::GetEVec(glm::vec4& v, const char* key, const char* fallback ) -{ - std::vector vec ; - SStr::GetEVector(vec, key, fallback); - std::cout << key << SStr::Present(vec) << std::endl ; - assert( vec.size() == 4 ); - for(int i=0 ; i < 4 ; i++) v[i] = vec[i] ; -} - - - - -template -std::string SStr::Present(std::vector& vec) -{ - std::stringstream ss ; - for(unsigned i=0 ; i < vec.size() ; i++) ss << vec[i] << " " ; - return ss.str(); -} - - -template std::string SStr::Present(std::vector& ); -template std::string SStr::Present(std::vector& ); -template std::string SStr::Present(std::vector& ); - - - -template -T SStr::GetEValue(const char* key, T fallback) // static -{ - const char* sval = getenv(key); - T val = sval ? ato_(sval) : fallback ; - return val ; -} - - - -unsigned SStr::Encode4(const char* s) // static -{ - unsigned u4 = 0u ; - for(unsigned i=0 ; i < std::min(4ul, strlen(s)) ; i++ ) - { - unsigned u = unsigned(s[i]) ; - u4 |= ( u << (i*8) ) ; - } - return u4 ; -} - - -template float SStr::GetEValue(const char* key, float fallback); -template int SStr::GetEValue(const char* key, int fallback); -template unsigned SStr::GetEValue(const char* key, unsigned fallback); -template std::string SStr::GetEValue(const char* key, std::string fallback); -template bool SStr::GetEValue(const char* key, bool fallback); - - -/** -Str::PTXPath -------------- - -Instead can use:: - - spath::Resolve("$OPTICKS_PREFIX/ptx/CSGOptiX_generated_CSGOptiX7.cu.ptx") - - -const char* SStr::PTXPath( const char* install_prefix, const char* cmake_target, const char* cu_stem, const char* cu_ext ) // static -{ - std::stringstream ss ; - ss << install_prefix - << "/ptx/" - << cmake_target - << "_generated_" - << cu_stem - << cu_ext - << ".ptx" - ; - std::string path = ss.str(); - return strdup(path.c_str()); -} -**/ - - - - -template -T SStr::ato_( const char* a ) // static -{ - std::string s(a); - std::istringstream iss(s); - T v ; - iss >> v ; - return v ; -} - - -template double SStr::ato_( const char* ); -template float SStr::ato_( const char* ); -template int SStr::ato_( const char* ); -template unsigned SStr::ato_( const char* ); - - -void SStr::GridMinMax(const std::array& grid, glm::ivec3&mn, glm::ivec3& mx) // static -{ - mn.x = grid[0] ; mx.x = grid[1] ; - mn.y = grid[3] ; mx.y = grid[4] ; - mn.z = grid[6] ; mx.z = grid[7] ; -} - -void SStr::GridMinMax(const std::array& grid, int&mn, int& mx) // static -{ - for(int a=0 ; a < 3 ; a++) - for(int i=grid[a*3+0] ; i < grid[a*3+1] ; i+=grid[a*3+2] ) - { - if( i > mx ) mx = i ; - if( i < mn ) mn = i ; - } - std::cout << "SStr::GridMinMax " << mn << " " << mx << std::endl ; -} - - - -int SStr::AsInt(const char* arg, int fallback ) -{ - char* end ; - char** endptr = &end ; - int base = 10 ; - unsigned long ul = strtoul(arg, endptr, base); - bool end_points_to_terminator = end == arg + strlen(arg) ; - return end_points_to_terminator ? int(ul) : fallback ; -} - - -int SStr::ExtractInt(const char* arg, int start, unsigned num, int fallback) -{ - unsigned pos = start < 0 ? strlen(arg) + start : start ; - unsigned len = strlen(arg) ; - if(pos > len) return fallback ; - if(pos + num > len) return fallback ; - - std::string s(arg+pos,num) ; - return SStr::AsInt(s.c_str(), fallback); -} - - -/** -SStr::ReplaceChars --------------------- - -Duplicate the input string and change all occurences of *repl* chars within the string into *to* - -**/ - -const char* SStr::ReplaceChars(const char* str, const char* repl, char to ) -{ - char* s = strdup(str); - for(unsigned i=0 ; i < strlen(s) ; i++) if(strchr(repl, s[i]) != nullptr) s[i] = to ; - return s ; -} - -long SStr::ExtractLong( const char* s, long fallback ) -{ - std::vector vals; - Extract(vals, s); - return vals.size() == 1 ? vals[0] : fallback ; -} - - -/** -SStr::Extract OBSOLETE : REPLACE WITH sstr::Extract -------------------------------------------------------- - -Some str with other uses of + - would trip this up. - - -**/ -void SStr::Extract( std::vector& vals, const char* s ) -{ - char* s0 = strdup(s); - char* p = s0 ; - while (*p) - { - if( (*p >= '0' && *p <= '9') || *p == '+' || *p == '-') vals.push_back(strtol(p, &p, 10)) ; - else p++ ; - } - free(s0); -} - -void SStr::Extract_( std::vector& vals, const char* s ) -{ - char* p = const_cast(s) ; - while (*p) - { - if( (*p >= '0' && *p <= '9') || *p == '+' || *p == '-') vals.push_back(strtol(p, &p, 10)) ; - else p++ ; - } -} - -void SStr::Extract_( std::vector& vals, const char* s ) -{ - char* p = const_cast(s) ; - while (*p) - { - if( (*p >= '0' && *p <= '9') || *p == '+' || *p == '-' || *p == '.') vals.push_back(strtof(p, &p)) ; - else p++ ; - } -} - - - - -int SStr::ekv_split( std::vector > & ekv, const char* line_, char edelim, char kvdelim) -{ - int err = 0 ; - bool warn = true ; - const char* line = strdup(line_); - typedef std::pair KV ; - std::istringstream f(line); - std::string s; - while (getline(f, s, edelim)) - { - std::vector kv ; - SStr::Split( s.c_str(), kvdelim, kv ); - - if(kv.size() == 2) - { - ekv.push_back(KV(kv[0],kv[1])); - } - else - { - if(warn) - { - LOG(error) << "ignoring malformed kv [" << s.c_str() << "]" ; - LOG(error) << "line [" << line << "]" ; - } - err++ ; - std::raise(SIGINT); - } - } - return err ; -} - - - - -const char* SStr::ParseStringIntInt( const char* triplet, int& y, int& z, char delim ) -{ - std::stringstream ss; - ss.str(triplet) ; - std::string s; - std::vector elem ; - while (std::getline(ss, s, delim)) elem.push_back(s) ; - assert(elem.size() == 3 ); - y = AsInt( elem[1].c_str() ); - z = AsInt( elem[2].c_str() ); - return strdup(elem[0].c_str()); -} - - diff --git a/sysrap/SStr.hh b/sysrap/SStr.hh deleted file mode 100644 index 50ceba7042..0000000000 --- a/sysrap/SStr.hh +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2019 Opticks Team. All Rights Reserved. - * - * This file is part of Opticks - * (see https://bitbucket.org/simoncblyth/opticks). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/** -SStr -====== - -Static string utilities. - - - -**/ - - -#include -#include -#include -#include -#include -#include "plog/Severity.h" - - -#include "SYSRAP_API_EXPORT.hh" - -class SYSRAP_API SStr { - - typedef unsigned long long ULL ; - - public: - static const plog::Severity LEVEL ; - static void Save(const char* path, const std::vector& a, char delim='\n' ); - static void Save(const char* path_, const char* txt ); - static const char* Load(const char* path_ ); - static void LoadList(const char* path, std::vector& lines, char delim='\n' ) ; - static std::vector* LoadList( const char* arg, char delim='\n' ); - public: - static void FillFromULL( char* dest, unsigned long long value, char unprintable='.') ; - static const char* FromULL(unsigned long long value, char unprintable='.'); - static unsigned long long ToULL(const char* s8 ); - - - template - static const char* Format1( const char* fmt, const char* value ); - - template - static const char* Format2( const char* fmt, const char* value1, const char* value2 ); - - template - static const char* Format3( const char* fmt, const char* value1, const char* value2, const char* value3 ); - - - template - static const char* FormatInt( const char* fmt, int value ); - - - static const char* FormatIndex( int idx, bool prefix=false, int wid=3 ); - - - template - static const char* FormatReal(const T value, int w, int p, char fill='0' ) ; - - static bool Blank(const char* s ); - static bool All(const char* s, char q ); - static unsigned Count(const char* s, char q ); - - static bool Contains(const char* s, const char* q ); - static bool EndsWith( const char* s, const char* q); - static bool StartsWith( const char* s, const char* q); - - static const char* AZaz ; - static bool StartsWithLetterAZaz(const char* q ); // A-Za-z - - static bool SimpleMatch(const char* s, const char* q ); - static bool Match(const char* s, const char* q); // q may contain wildcard chars '?' for 1 character and '*' for several - - static const char* StripPrefix_(const char* s, const char* pfx0 ); - static const char* StripPrefix(const char* s, const char* pfx0, const char* pfx1=nullptr, const char* pfx2=nullptr ); - static const char* MaterialBaseName(const char* s ) ; - - - static bool HasPointerSuffix( const char* name, unsigned hexdigits ) ; // 12 typically, 9 with Geant4 ??? - static bool HasPointerSuffix( const char* name, unsigned min_hexdigits, unsigned max_hexdigits ) ; - static int GetPointerSuffixDigits( const char* name ); - static const char* TrimPointerSuffix( const char* name ); - - static const char* TrimLeading(const char* s); - static const char* TrimTrailing(const char* s); - static const char* Trim(const char* s); // Trim leading and trailing whitespace - - static const char* HeadFirst(const char* s, char c); - static const char* HeadLast( const char* s, char c); - - static const char* Concat( const char* a, const char* b, const char* c=NULL ); - static const char* Concat( const char* a, unsigned b , const char* c=NULL ); - static const char* Concat( const char* a, unsigned b, const char* c, unsigned d, const char* e ) ; - - template - static const char* Concat_( const char* a, T b , const char* c ); - - - - - static const char* Replace( const char* s, char a, char b ); - static const char* ReplaceEnd( const char* s, const char* q, const char* r ); - - static void Split( const char* str, char delim, std::vector& elem ) ; - static int ISplit( const char* line, std::vector& ivec, char delim ) ; - static std::vector* ISplit( const char* line, char delim ); - - - static void ParseGridSpec( std::array& grid, const char* spec); - static void DumpGrid( const std::array& grid ) ; - - - static void GetEVec(glm::vec3& v, const char* key, const char* fallback ); - static void GetEVec(glm::vec4& v, const char* key, const char* fallback ); - - template - static void GetEVector(std::vector& vec, const char* key, const char* fallback ); - - template - static std::string Present(std::vector& vec); - - - //static const char* PTXPath( const char* install_prefix, const char* cmake_target, const char* cu_stem, const char* cu_ext=".cu" ); - - static void GridMinMax( const std::array& grid, int& mn, int& mx ) ; - static void GridMinMax( const std::array& grid, glm::ivec3& mn, glm::ivec3& mx) ; - - static unsigned Encode4(const char* s); - - template - static T ato_( const char* a ); - - template - static T GetEValue(const char* key, T fallback); - - - static int AsInt(const char* arg, int fallback=-1 ) ; - static int ExtractInt(const char* arg, int start, unsigned num, int fallback=-1) ; - - - static const char* ReplaceChars(const char* str, const char* repl="(),[]", char to=' ') ; - - static long ExtractLong( const char* s, long fallback ); - static void Extract( std::vector& vals, const char* s ); - static void Extract_( std::vector& vals, const char* s ); - static void Extract_( std::vector& vals, const char* s ); - - static int ekv_split( std::vector > & ekv, const char* line_, char edelim, char kvdelim); - - template - static std::string Format_( const char* fmt, Args ... args ); - - template - static const char* Format( const char* fmt, Args ... args ); - - // template - // static const char* Name( Args ... args ); - // replace with spath::Name - - static const char* ParseStringIntInt( const char* triplet, int& y, int& z, char delim=':' ); -}; - - - diff --git a/sysrap/SSys.cc b/sysrap/SSys.cc index 17f663086e..bf792ce789 100644 --- a/sysrap/SSys.cc +++ b/sysrap/SSys.cc @@ -33,7 +33,6 @@ #include #include "SSys.hh" -#include "SStr.hh" #include "SLOG.hh" #include "scuda.h" @@ -768,6 +767,8 @@ so that will often be the HOME directory, eg /home/blyth int SSys::RunPythonCode(const char* code) { + if(code == nullptr) return 101 ; + const char* python_executable = SSys::ResolvePython() ; LOG(info) << " code [" << code << "]" @@ -775,9 +776,9 @@ int SSys::RunPythonCode(const char* code) ; const char* arg1 = "-c" ; - const char* arg2 = SStr::Concat("'", code, "'") ; + const std::string arg2 = std::string("'") + code + "'" ; - int RC = code == NULL ? 101 : SSys::exec(python_executable,arg1, arg2) ; + int RC = SSys::exec(python_executable,arg1, arg2.c_str()) ; LOG(info) << " RC " << RC ; return RC ; } @@ -790,4 +791,3 @@ void SSys::Exit(int rc) } - diff --git a/sysrap/SVec.cc b/sysrap/SVec.cc index 8ec8baf604..26ee5a82b3 100644 --- a/sysrap/SVec.cc +++ b/sysrap/SVec.cc @@ -28,7 +28,6 @@ #include #include -#include "SStr.hh" #include "SVec.hh" @@ -144,7 +143,8 @@ template void SVec::Extract(std::vector& a, const char* str0, const char* ignore ) { char swap = ' '; - const char* str1 = SStr::ReplaceChars(str0, ignore, swap); + std::string str1(str0 ? str0 : ""); + for(char& c : str1) if(std::strchr(ignore, c) != nullptr) c = swap ; std::stringstream ss(str1); std::string s ; T value ; @@ -166,4 +166,3 @@ template struct SVec; template struct SVec; template struct SVec; - diff --git a/sysrap/sstr.h b/sysrap/sstr.h index 4e1f9d918c..97567c60b8 100644 --- a/sysrap/sstr.h +++ b/sysrap/sstr.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -26,6 +27,7 @@ struct sstr static bool MatchAll( const char* s, const char* q); static bool MatchStart( const char* s, const char* q); static bool StartsWith( const char* s, const char* q); + static bool SimpleMatch(const char* s, const char* q); static bool MatchEnd( const char* s, const char* q); static bool EndsWith( const char* s, const char* q); @@ -199,8 +201,8 @@ inline bool sstr::MatchAll( const char* s, const char* q) } /** -sstr::MatchStart (NB this can replace SStr::StartsWith with same args) -------------------------------------------------------------------------- +sstr::MatchStart +----------------- The 2nd query string must be less than or equal to the length of the first string and all the characters of the query string must match with the first string in order @@ -235,6 +237,31 @@ inline bool sstr::StartsWith( const char* s, const char* q) // synonym for sstr return s && q && strlen(q) <= strlen(s) && strncmp(s, q, strlen(q)) == 0 ; } +/** +sstr::SimpleMatch +------------------- + +When *q* ends with '$' or '@' require an exact full-string match of the +preceding characters, otherwise treat *q* as a prefix. + +**/ + +inline bool sstr::SimpleMatch(const char* s, const char* q) +{ + if(s == nullptr || q == nullptr) return false ; + + std::string_view sv(s); + std::string_view qv(q); + + if(sv.empty() || qv.empty()) return false ; + + const bool require_exact = qv.back() == '$' || qv.back() == '@' ; + if(require_exact) qv.remove_suffix(1); + + if(require_exact) return sv == qv ; + return sv.size() >= qv.size() && sv.substr(0, qv.size()) == qv ; +} + inline bool sstr::MatchEnd( const char* s, const char* q) { @@ -1360,4 +1387,3 @@ inline std::vector* sstr::LoadList( const char* arg, char delim ) return lines ; } - diff --git a/sysrap/tests/CMakeLists.txt b/sysrap/tests/CMakeLists.txt index 8b44c3c917..ca2cb18ae7 100644 --- a/sysrap/tests/CMakeLists.txt +++ b/sysrap/tests/CMakeLists.txt @@ -13,7 +13,6 @@ set(TEST_SOURCES SSysTest.cc SSys2Test.cc SSys3Test.cc - SStrTest.cc SPathTest.cc STrancheTest.cc SVecTest.cc diff --git a/sysrap/tests/SEvtTest.cc b/sysrap/tests/SEvtTest.cc index 953590b633..5c79a4f74d 100644 --- a/sysrap/tests/SEvtTest.cc +++ b/sysrap/tests/SEvtTest.cc @@ -172,9 +172,9 @@ int SEvtTest::InputPhoton0() NP* fr = NP::Make(1,4,4); memcpy( fr->bytes(), q->cdata(), fr->arr_bytes() ); - fr->save(FOLD, SStr::Name("fr", ipf, ".npy" )); + fr->save(FOLD, spath::Name("fr", ipf, ".npy" )); - tr->save( FOLD, SStr::Name("tr",ipf, ".npy" )) ; + tr->save( FOLD, spath::Name("tr",ipf, ".npy" )) ; */ return 0 ; diff --git a/sysrap/tests/SEvt__LoadTest.sh b/sysrap/tests/SEvt__LoadTest.sh index 11ea0a4359..98f95f0b49 100755 --- a/sysrap/tests/SEvt__LoadTest.sh +++ b/sysrap/tests/SEvt__LoadTest.sh @@ -42,7 +42,6 @@ if [ "${arg/build}" != "$arg" ]; then ../OpticksPhoton.cc \ ../SBit.cc \ ../SAr.cc \ - ../SStr.cc \ ../SSys.cc \ ../SGenstep.cc \ ../SLOG.cc \ @@ -73,4 +72,3 @@ if [ "${arg/ana}" != "$arg" ]; then fi exit 0 - diff --git a/sysrap/tests/SPathTest.cc b/sysrap/tests/SPathTest.cc index d5ae2a24f9..49fe9dbdc7 100644 --- a/sysrap/tests/SPathTest.cc +++ b/sysrap/tests/SPathTest.cc @@ -28,7 +28,7 @@ #include #include "SPath.hh" -#include "SStr.hh" +#include "spath.h" #include "sdigest.h" #include "OPTICKS_LOG.hh" @@ -380,7 +380,7 @@ void test_Copy() const char* srcn = "src.txt" ; const char* dstn = "dst2.txt" ; - SStr::Save(src, "SPathTest test_Copy src text\n" ); + spath::Write("SPathTest test_Copy src text\n", src ); SPath::Copy(dst, src ) ; SPath::Copy(dstn, srcn, "/tmp" ) ; diff --git a/sysrap/tests/SStrTest.cc b/sysrap/tests/SStrTest.cc deleted file mode 100644 index e71c1c1d06..0000000000 --- a/sysrap/tests/SStrTest.cc +++ /dev/null @@ -1,876 +0,0 @@ -/* - * Copyright (c) 2019 Opticks Team. All Rights Reserved. - * - * This file is part of Opticks - * (see https://bitbucket.org/simoncblyth/opticks). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// om-;TEST=SStrTest om-t - -#include -#include -#include -#include -#include - -#include "SStr.hh" -#include "SPath.hh" - -#include "OPTICKS_LOG.hh" - - -void test_ToULL() -{ - char* s = new char[8+1] ; - s[0] = '\1' ; - s[1] = '\2' ; - s[2] = '\3' ; - s[3] = '\4' ; - s[4] = '\5' ; - s[5] = '\6' ; - s[6] = '\7' ; - s[7] = '\7' ; - s[8] = '\0' ; - - typedef unsigned long long ULL ; - - ULL v = SStr::ToULL(s ); - - LOG(info) << " v " << std::hex << v ; - - assert( 0x707060504030201ull == v ); -} - -void test_FromULL() -{ - typedef unsigned long long ULL ; - const char* s0 = "0123456789" ; - ULL v = SStr::ToULL(s0); - - const char* s1 = SStr::FromULL( v ); - LOG(info) - << " s0 " << std::setw(16) << s0 - << " s1 " << std::setw(16) << s1 - ; - - ULL v0 = SStr::ToULL(NULL) ; - bool v0_expect = v0 == 0ull ; - assert( v0_expect); - if(!v0_expect) std::raise(SIGINT); - -} - - - - -void test_Format1() -{ - const char* fmt = "hello %s hello" ; - const char* value = "world" ; - const char* result = SStr::Format1<256>(fmt, value ); - const char* expect = "hello world hello" ; - - bool result_expect = strcmp( result, expect) == 0 ; - assert(result_expect ); - if(!result_expect) std::raise(SIGINT); - - // this asserts from truncation - //const char* result2 = SStr::Format1<16>(fmt, value ); - //LOG(info) << " result2 " << result2 ; - -} - - -void test_FormatInt() -{ - const char* fmt = "/tmp/Frame%0.3d.ppm" ; - LOG(info) << fmt ; - for(int i=-10 ; i < 10 ; i++ ) - { - const char* result = SStr::FormatInt<64>(fmt, i ); - std::cout << result << std::endl ; - } -} - - - - - -void test_FormatInt_2() -{ - const char* fmt = "%d" ; - LOG(info) << fmt ; - for(int i=-10 ; i < 10 ; i++ ) - { - const char* result = SStr::FormatInt<8>(fmt, i ); - std::cout << result << std::endl ; - } -} - - -void test_FormatIndex() -{ - for(int i=-10 ; i <= 10 ; i++ ) - { - const char* result = SStr::FormatIndex(i); - std::cout << " i " << std::setw(4) << i << "[" << result << "]" << std::endl ; - } -} - - - - -void test_Contains() -{ - const char* s = "/hello/there/Cathode/World" ; - - bool expect = SStr::Contains(s, "Cathode") == true && SStr::Contains(s, "cathode") == false ; - assert( expect ); - if(!expect) std::raise(SIGINT); -} -void test_EndsWith() -{ - const char* s = "/hello/there/Cathode/World" ; - bool expect = SStr::EndsWith(s, "Cathode") == false && SStr::EndsWith(s, "World") == true ; - assert( expect ); - if(!expect) std::raise(SIGINT); -} - -void test_StartsWith() -{ - const char* s = "/hello/there/Cathode/World" ; - bool expect = SStr::StartsWith(s, "/hello") == true && SStr::StartsWith(s, "World") == false ; - assert( expect ); - if(!expect) std::raise(SIGINT); -} - - - - - -void test_HasPointerSuffix() -{ - - std::vector yes = - { - "det0x110d9a820", - "0x110d9a820" , - "0xdeadbeef0" - } - ; - - std::vector no = - { - "tooshort", - "0xdeadbeef", - "0xdeadbeef" - } - ; - - for( unsigned i=0 ; i < yes.size() ; i++) - { - std::cout << "y: " << yes[i] << std::endl ; - assert( SStr::HasPointerSuffix(yes[i].c_str(), 9) == true ); - } - for( unsigned i=0 ; i < no.size() ; i++) - { - std::cout << "n: " << no[i] << std::endl ; - assert( SStr::HasPointerSuffix(no[i].c_str(), 9) == false ); - } - -} - - -void test_HasPointerSuffix2() -{ - const char* name = "World0x7fc10641cbb0" ; - bool expect = SStr::HasPointerSuffix( name, 9, 12 ) == true ; - assert(expect) ; - if(!expect) std::raise(SIGINT) ; - - assert( SStr::GetPointerSuffixDigits("World0x7fc10641cbb0") == 12 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc10641cbb") == 11 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc10641cb") == 10 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc10641c") == 9 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc10641") == 8 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc1064") == 7 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc106") == 6 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc10") == 5 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc1") == 4 ); - assert( SStr::GetPointerSuffixDigits("World0x7fc") == 3 ); - assert( SStr::GetPointerSuffixDigits("World0x7f") == 2 ); - assert( SStr::GetPointerSuffixDigits("World0x7") == 1 ); - assert( SStr::GetPointerSuffixDigits("World0x") == 0 ); - assert( SStr::GetPointerSuffixDigits("World0") == -1 ); - assert( SStr::GetPointerSuffixDigits("World") == -1 ); - assert( SStr::GetPointerSuffixDigits("") == -1 ); - assert( SStr::GetPointerSuffixDigits(NULL) == -1 ); -} - - -void test_Replace() -{ - const char* name = "TITAN RTX " ; - const char* xname2 = "TITAN_RTX_" ; - const char* name2 = SStr::Replace(name, ' ', '_' ); - - bool expect = strcmp(name2, xname2) == 0 ; - assert(expect); - if(!expect) std::raise(SIGINT) ; -} - -void test_ReplaceEnd() -{ - const char* name = "/some/path/to/hello.ppm" ; - const char* xname2 = "/some/path/to/hello.npy" ; - const char* name2 = SStr::ReplaceEnd(name, ".ppm", ".npy" ); - bool expect = strcmp(name2, xname2) == 0 ; - assert(expect); - if(!expect) std::raise(SIGINT) ; -} - -void test_ArrayToString() -{ - // thinking about optix7c- and embedded_ptx_code from bin2c - // observe that without NULL termination get garbage on the end of the string - // which is why must use "--padd 0" which sets trailing bytes:: - // - // bin2c --name data_variable_name --padd 0 inputfile > data.c - // - const char imageBytes[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x00 } ; - std::string s = imageBytes ; - std::cout << "[" << s << "]" << std::endl ; - assert( s.compare("ABCDEF") == 0 ); - assert( 'A' == 0x41 ); -} - - - - - -void test_Save() -{ - std::vector v = { "red", "green", "blue", "cyan", "magenta", "yellow", "green" } ; - const char* path = "$TMP/SStrTest_test_Save.txt" ; - SStr::Save(path, v ); -} - - -void test_LoadList() -{ - std::vector v0 = { "red", "green", "blue", "cyan", "magenta", "yellow", "green" } ; - - const char* path = SPath::Resolve("$TMP/SStrTest/test_LoadList.txt", FILEPATH) ; - SStr::Save(path, v0 ); - - std::vector v1 ; - SStr::LoadList(path, v1 ); - assert( v0.size() == v1.size() ); - - - std::vector* v2p = SStr::LoadList(path); - assert( v2p ); - const std::vector& v2 = *v2p ; - - assert( v2.size() == v0.size() ); - - - for( unsigned i=0 ; i < v0.size() ; i++) - std::cout - << std::setw(20) << v0[i] - << " : " - << std::setw(20) << v1[i] - << " : " - << std::setw(20) << v2[i] - << " : " - << std::endl - ; -} - - - - - - - - - -const char* TXT = R"LITERAL( -red -green -blue -cyan -magenta -yellow -)LITERAL" ; - -void test_Save_Load() -{ - const char* path = "$TMP/SStrTest/test_Save_Load.txt" ; - SStr::Save(path, TXT ); - - const char* txt = SStr::Load(path); - - LOG(info) << " TXT [" << TXT << "]" ; - LOG(info) << " txt [" << txt << "]" ; - - assert( strcmp(txt, TXT) == 0 ); -} - -void test_Save_PWD() -{ - const char* path = "test_Save_PWD.txt" ; - SStr::Save(path, TXT ); -} - - - - -void test_Split() -{ - std::vector elem ; - const char* str = "red,green,blue,cyan,magenta,yellow" ; - SStr::Split(str, ',', elem ); - assert( elem.size() == 6 ); - for(int i=0 ; i < int(elem.size()) ; i++) std::cout << elem[i] << std::endl ; -} - - -void test_Concat_() -{ - std::cout << SStr::Concat_("hello/", 1, ".npy" ) << std::endl ; -} - - -void test_AsInt() -{ - const char* arg = "00000" ; - int i = SStr::AsInt(arg); - bool i_expect = i == 0 ; - assert( i_expect ); - if(!i_expect) std::raise(SIGINT); -} - - -void test_ExtractInt() -{ - const char* path = "/some/long/path/with_00000.jpg" ; - int i = SStr::ExtractInt(path, -9, 5 ); - std::cout << "path " << path << " i " << i << std::endl ; - assert( i == 0 ); -} - -void test_SimpleMatch_WildMatch() -{ - std::vector labels = { - "r0", - "r1", - "r2", - "r3", - "r1p0","r1p1","r1p2","r1p3", - "r2p0","r2p1","r2p2","r2p3", - "R3P0N0", - "R3P0N1", - "R3P0N2", - "R3P1N0", - "R3P1N1", - "R3P1N2", - "R3P1N3", - }; - - std::vector querys = { - "r2", - "r2$", - "r2p", - "r2p$", - "r2p2$", - "R3P1", - "R3P1*", - "R3P1N", - "R3P1N?", - "R3P1N2$", - "R3P?N0", - "R3P1*", - } ; - - for(int i=0 ; i < int(querys.size()) ; i++) - { - const char* q = querys[i].c_str() ; - unsigned lq = strlen(q); - bool qed = q[lq-1] == '$' ; - - std::cout - << " q " << q - << " lq " << lq - << " qed: " << ( qed ? "Y" : "N" ) - << std::endl - ; - - - for(int j=0 ; j < int(labels.size()) ; j++) - { - const char* s = labels[j].c_str(); - bool sm = SStr::SimpleMatch(s,q); - bool wm = SStr::Match(s,q); - std::cout - << " SStr::SimpleMatch(" - << std::setw(7) << s - << " , " - << std::setw(7) << q - << " ) : " - << ( sm ? "Y" : " " ) - ; - - std::cout - << " SStr::Match(" - << std::setw(7) << s - << " , " - << std::setw(7) << q - << " ) : " - << ( wm ? "Y" : " " ) - ; - - std::cout << std::endl ; - - - - - } - } -} - - -void test_ISplit() -{ - LOG(info); - - { - const char* wavelength = "380,400,420,440,460" ; - std::vector inm ; - SStr::ISplit(wavelength, inm, ',' ); - assert( inm.size() == 5 ); - assert( inm[0] == 380 ); - assert( inm[1] == 400 ); - assert( inm[2] == 420 ); - assert( inm[3] == 440 ); - assert( inm[4] == 460 ); - } - { - const char* wavelength = "0" ; - std::vector inm ; - SStr::ISplit(wavelength, inm, ',' ); - assert( inm.size() == 1 ); - assert( inm[0] == 0 ); - } - { - const char* wavelength = "440" ; - std::vector inm ; - SStr::ISplit(wavelength, inm, ',' ); - assert( inm.size() == 1 ); - assert( inm[0] == 440 ); - } - -} - - -void test_FormatReal() -{ - double value = 1.1 ; - const char* s = SStr::FormatReal(value, 6, 4, '0'); - - std::cout - << " value " << value - << " s [" << s << "]" - << std::endl - ; -} - -void test_StripPrefix() -{ - const char* lines = R"LITERAL( -/dd/Materials/red -/dd/Materials/green -/dd/Materials/blue -_dd_Materials_red -_dd_Materials_green -_dd_Materials_blue -red -green -blue -)LITERAL" ; - - std::stringstream ss(lines) ; - std::string line ; - while (std::getline(ss, line)) - { - if(line.empty()) continue ; - - const char* s = line.c_str(); - const char* sp = SStr::StripPrefix(s, "/dd/Materials/", "_dd_Materials_" ); - const char* sp2 = SStr::MaterialBaseName(s); - - bool sp_expect = strcmp( sp, sp2 ) == 0 ; - assert(sp_expect); - if(!sp_expect) std::raise(SIGINT); - - std::cout - << std::setw(50) << line - << " : " - << std::setw(50) << sp - << std::endl - ; - } -} - - -void test_TrimPointerSuffix() -{ - const char* lines = R"LITERAL( -Hello0xdeadbeef -Hello0xnope -Hello0xnope1 -Hello0xnope1 -Hello0x0123 -Hello0x01234 -Hello0x012345 -Hello0x0123456 -Hello0x01234567 -Hello0x012345678 -Hello0x0123456789 -Hello0x0123456789a -Hello0xa -Hello0xab -Hello0xabc -Hello0xabcd -Hello0xabcde -Hello0xabcdef -Hello0xabcdef0 -Hello0xabcdef01 -Hello0xabcdef012 -0xcafecafe -0xdeadbeef -a0xcafecafe -a0xdeadbeef -)LITERAL" ; - - // the suffix chars must be valid hexdigits - - std::stringstream ss(lines) ; - std::string line ; - while (std::getline(ss, line)) - { - if(line.empty()) continue ; - - const char* s = line.c_str(); - const char* sp = SStr::TrimPointerSuffix(s); - std::cout - << std::setw(50) << s - << " : " - << std::setw(50) << sp - << std::endl - ; - } -} - - -void test_ReplaceChars() -{ - const char* str0 = "(-0.585,-0.805, 0.098, 0.000) (-0.809, 0.588, 0.000, 0.000) (-0.057,-0.079,-0.995, 0.000) (1022.116,1406.822,17734.953, 1.000)" ; - const char* str1 = SStr::ReplaceChars(str0); - - std::cout - << " str0 " << str0 << std::endl - << " str1 " << str1 << std::endl - ; -} - -void test_ato_() -{ - const char* a = "104.25" ; - - float f = SStr::ato_(a); - double d = SStr::ato_(a); - int i = SStr::ato_(a); - unsigned u = SStr::ato_(a); - - - LOG(info) - << " a " << a - << " f " << std::setw(10) << std::fixed << std::setprecision(4) << f - << " d " << std::setw(10) << std::fixed << std::setprecision(4) << d - << " i " << std::setw(10) << i - << " u " << std::setw(10) << u - ; -} - -void test_Extract() -{ - const char* s = "asjdhajsdhas-100 -200 300 sajdasjdhakjHDKJ +66 21 23 45 1001 -10 akjdshaHD -42 " ; - LOG(info) << s ; - std::vector vals ; - SStr::Extract_(vals, s ); - - for(unsigned i=0 ; i < vals.size() ; i++ ) std::cout << vals[i] << std::endl; - -} - -void test_Extract_float() -{ - const char* s = "asjdhajsdhas-0.1 -.2 +30.5 sajdasjdhakjHDKJ +66 21 23.6 45 1001 -10.2 akjdshaHD -42.5 " ; - LOG(info) << s ; - std::vector vals ; - SStr::Extract_(vals, s ); - - for(unsigned i=0 ; i < vals.size() ; i++ ) std::cout << vals[i] << std::endl; -} - -void test_Trim(const char* s) -{ - std::cout - << "s [" << s << "]" << std::endl - << "SStr::TrimTrailing(s)[" << SStr::TrimTrailing(s) << "]" << std::endl - << "SStr::TrimLeading(s) [" << SStr::TrimLeading(s) << "]" << std::endl - << "SStr::Trim(s) [" << SStr::Trim(s) << "]" << std::endl - ; - -} - - -void test_Trim() -{ - const char* s0 = " contents with gaps before whitespace " ; - test_Trim(s0); - - const char* s1 = R"LITERAL( - -red -green -blue cyan magenta -yellow - - -)LITERAL" ; - - test_Trim(s1); - - -} - -void test_Count() -{ - assert( SStr::Count("a bcdefg", ' ') == 1 ); - assert( SStr::Count("a bcdefg", ' ') == 2 ); - assert( SStr::Count(" ", ' ') == 1 ); - assert( SStr::Count(" ", ' ') == 2 ); - assert( SStr::Count("", ' ') == 0 ); -} -void test_All() -{ - assert( SStr::All("aaaaa", 'a') == true ); - assert( SStr::All("aabaa", 'a') == false ); - assert( SStr::All("", 'a') == false ); - assert( SStr::All(" ", ' ') == true ); - assert( SStr::All(" ", ' ') == true ); -} -void test_Blank() -{ - assert( SStr::Blank("aaaaa") == false ); - assert( SStr::Blank("") == true ); - assert( SStr::Blank(" ") == true ); - assert( SStr::Blank(" ") == true ); - assert( SStr::Blank(" ") == true ); - assert( SStr::Blank("\n") == false ); -} - - - - - -void test_ExtractLong() -{ - - const char* lines = R"LITERAL( - -red1 -green2 -blue2 cyan magenta -yellow3 - - -)LITERAL" ; - - - std::stringstream ss(lines) ; - std::string line ; - while (std::getline(ss, line)) - { - if(line.empty()) continue ; - - const char* s = line.c_str(); - long l = SStr::ExtractLong(s, 0); - - LOG(info) << std::setw(40) << s << " l: " << l ; - } -} - - -void test_HeadFirst_HeadLast() -{ - const char* lines = R"LITERAL( -SomeName_suffix -green2WithoutSuffix -MultipleUnderscoreblue2_cyan_magenta -)LITERAL" ; - - std::stringstream ss(lines) ; - std::string line ; - while (std::getline(ss, line)) - { - if(line.empty()) continue ; - - const char* s = line.c_str(); - const char* f = SStr::HeadFirst(s, '_'); - const char* l = SStr::HeadLast(s, '_'); - - std::cout - << " s[" << std::setw(40) << ( s ? s : "-" ) << "]" << std::setw(3) << strlen(s) - << " f[" << std::setw(40) << ( f ? f : "-" ) << "]" << std::setw(3) << strlen(f) - << " l[" << std::setw(40) << ( l ? l : "-" ) << "]" << std::setw(3) << strlen(l) - << std::endl - ; - } -} - - -void test_Format_Ellipsis() -{ - LOG(info) << SStr::Format_("Hello %d World %10.4f", 101, 50.5 ); - LOG(info) << SStr::Format("Hello %d World %10.4f", 101, 50.5 ); - - for(int i=0 ; i < 1000 ; i+= 100 ) - { - std::cout - << " before " - << std::setw(7) << SStr::Format("key:%d", i ) - << " after " - << std::endl - ; - } - - -} - - -void test_StartsWithLetterAZaz() -{ - assert( SStr::StartsWithLetterAZaz(nullptr) == false ); - assert( SStr::StartsWithLetterAZaz("") == false ); - assert( SStr::StartsWithLetterAZaz(" ") == false ); - assert( SStr::StartsWithLetterAZaz("0") == false ); - assert( SStr::StartsWithLetterAZaz("0a") == false ); - assert( SStr::StartsWithLetterAZaz(" a") == false ); - - assert( SStr::StartsWithLetterAZaz("a") == true ); - assert( SStr::StartsWithLetterAZaz("abcd") == true ); - assert( SStr::StartsWithLetterAZaz("Abcd") == true ); -} - - -void test_ParseStringIntInt() -{ - const char* x0 = "Hello" ; - int y0 = 10 ; - int z0 = 1000 ; - std::stringstream ss ; - ss << x0 << ":" << y0 << ":" << z0 ; - - std::string s = ss.str(); - const char* triplet = s.c_str(); - - int y1 = 0 ; - int z1 = 0 ; - const char* x1 = SStr::ParseStringIntInt(triplet, y1, z1); - - bool x_expect = strcmp(x0,x1) == 0 ; - bool y_expect = y0 == y1 ; - bool z_expect = z0 == z1 ; - - assert( x_expect ); - assert( y_expect ); - assert( z_expect ); - - if(!x_expect) std::raise(SIGINT); - if(!y_expect) std::raise(SIGINT); - if(!z_expect) std::raise(SIGINT); - - LOG(info); -} - - - -// om- ; TEST=SStrTest om-t - - -int main(int argc , char** argv ) -{ - OPTICKS_LOG(argc, argv); - - /* - test_ToULL(); - test_FromULL(); - test_Format1(); - test_Contains(); - test_EndsWith(); - test_HasPointerSuffix(); - test_HasPointerSuffix2(); - test_StartsWith(); - test_Replace(); - test_ReplaceEnd(); - test_ArrayToString(); - test_Save(); - test_Split(); - test_Concat_(); - test_AsInt(); - test_ExtractInt(); - test_SimpleMatch_WildMatch(); - test_ISplit(); - test_FormatReal(); - test_StripPrefix(); - test_TrimPointerSuffix(); - test_ReplaceChars(); - test_ato_(); - test_Save_Load(); - test_Save_PWD(); - test_Extract(); - test_Extract_float(); - test_Trim(); - test_Count(); - test_All(); - test_Blank(); - test_ExtractLong(); - test_HeadFirst_HeadLast(); - test_FormatInt(); - test_LoadList(); - test_Format_Ellipsis(); - test_StartsWithLetterAZaz(); - test_FormatInt_2(); - test_ParseStringIntInt(); - */ - test_FormatIndex(); - - - return 0 ; -} -// om-;TEST=SStrTest om-t diff --git a/u4/U4.cc b/u4/U4.cc index 096068beed..a75dd247ee 100644 --- a/u4/U4.cc +++ b/u4/U4.cc @@ -18,7 +18,6 @@ #include "OpticksGenstep.h" #include "SPath.hh" -#include "SStr.hh" #include "NP.hh" #include "SLOG.hh" #include "sscint.h" @@ -427,4 +426,3 @@ void U4::GenPhotonSecondaries( const G4Track* , const G4VParticleChange* ) { // do nothing } - diff --git a/u4/U4Material.cc b/u4/U4Material.cc index 177795f0fb..5e5872f98e 100644 --- a/u4/U4Material.cc +++ b/u4/U4Material.cc @@ -10,7 +10,6 @@ #include "SDir.h" -#include "SStr.hh" #include "sstr.h" #include "SSim.hh" #include "SBnd.h" @@ -324,7 +323,8 @@ NPFold* U4Material::MakePropertyFold_flat() const char* propname = propnames[j].c_str() ; G4MaterialPropertyVector* prop = GetProperty(mat, propname ); NP* a = U4MaterialPropertyVector::ConvertToArray(prop); - fold->add( SStr::Format("%s/%s", material, propname), a ); + const std::string key = sstr::Format_("%s/%s", material, propname); + fold->add( key.c_str(), a ); } } return fold ; @@ -497,30 +497,30 @@ G4MaterialPropertiesTable* U4Material::MakeMaterialPropertiesTable(const char* m for(unsigned i=0 ; i < names.size() ; i++) { const char* name = names[i].c_str(); - const char* key = SStr::HeadFirst(name, '.'); + const std::string key = names[i].substr(0, names[i].find('.')); NP* a = NP::Load(matdir, name ); char type = Classify(a); double* values = a->values() ; - ss << Desc(key, a) << std::endl ; + ss << Desc(key.c_str(), a) << std::endl ; // guessed version fork #if G4VERSION_NUMBER < 1100 switch(type) { - case 'C': mpt->AddConstProperty(key, values[1]) ; break ; - case 'P': mpt->AddProperty(key, MakeProperty(a)) ; break ; - case 'F': mpt->AddProperty(key, MakeProperty(a)) ; break ; + case 'C': mpt->AddConstProperty(key.c_str(), values[1]) ; break ; + case 'P': mpt->AddProperty(key.c_str(), MakeProperty(a)) ; break ; + case 'F': mpt->AddProperty(key.c_str(), MakeProperty(a)) ; break ; } #else G4bool createNewKey = true ; // Geant4 11.2.1 throws exception for new keys without this switch(type) { - case 'C': mpt->AddConstProperty(key, values[1], createNewKey) ; break ; - case 'P': mpt->AddProperty(key, MakeProperty(a), createNewKey) ; break ; - case 'F': mpt->AddProperty(key, MakeProperty(a), createNewKey) ; break ; + case 'C': mpt->AddConstProperty(key.c_str(), values[1], createNewKey) ; break ; + case 'P': mpt->AddProperty(key.c_str(), MakeProperty(a), createNewKey) ; break ; + case 'F': mpt->AddProperty(key.c_str(), MakeProperty(a), createNewKey) ; break ; } #endif } @@ -554,15 +554,15 @@ G4MaterialPropertiesTable* U4Material::MakeMaterialPropertiesTable(const char* m //const char* matdir = SPath::Resolve(matdir_, NOOP); std::vector keys ; - SStr::Split( keys_, delim, keys ); + sstr::Split( keys_, delim, keys ); G4MaterialPropertiesTable* mpt = new G4MaterialPropertiesTable(); for(unsigned i=0 ; i < keys.size() ; i++) { const std::string& key_ = keys[i]; const char* key = key_.c_str(); - const char* name = SStr::Format("%s.npy", key ); - NP* a = NP::Load(matdir, name ); + const std::string name = sstr::Format_("%s.npy", key ); + NP* a = NP::Load(matdir, name.c_str() ); assert(a); LOG(info) @@ -888,8 +888,8 @@ succeed to load. G4Material* U4Material::LoadOri(const char* name) { - const char* matdir = SStr::Format("%s/%s_ori", LIBDIR, name ); - G4Material* mat = MakeMaterial(name, matdir ); + const std::string matdir = sstr::Format_("%s/%s_ori", LIBDIR, name ); + G4Material* mat = MakeMaterial(name, matdir.c_str() ); return mat ; } @@ -1067,5 +1067,3 @@ void U4Material::KludgeRemoveRockRINDEX() // static { RemoveProperty( "RINDEX", G4Material::GetMaterial("Rock") ); } - - diff --git a/u4/tests/U4MaterialPropertyVectorTest.cc b/u4/tests/U4MaterialPropertyVectorTest.cc index 5ec26aa1eb..e32c3273ef 100644 --- a/u4/tests/U4MaterialPropertyVectorTest.cc +++ b/u4/tests/U4MaterialPropertyVectorTest.cc @@ -1,7 +1,6 @@ #include "OPTICKS_LOG.hh" #include "SPath.hh" #include "SSys.hh" -#include "SStr.hh" #include "NPFold.h" #include "G4Material.hh"