From 7b4a51529b255efa67f8a38e591e0bbb7ef67379 Mon Sep 17 00:00:00 2001 From: Seb James Date: Tue, 26 Nov 2024 17:00:20 +0000 Subject: [PATCH] change morph::Tools class of static functions into morph::tools; a namespace --- buildtools/process_colourmap.cpp | 6 +- buildtools/process_colourtables.cpp | 14 +- examples/Ermentrout2009/erm.cpp | 12 +- examples/LotkaVolterra/lv.cpp | 16 +- examples/SimpsonGoodhill/sg.cpp | 2 +- examples/schnakenberg/schnak_whisk.cpp | 17 +- examples/schnakenberg/schnakenberg.cpp | 17 +- morph/ColourMap.h | 2 +- morph/Config.h | 2 +- morph/HdfData.h | 2 +- morph/RD_Base.h | 2 +- morph/Random.h | 2 +- morph/ReadCurves.h | 20 +- morph/RecurrentNetworkModel.h | 2 +- morph/Visual.h | 8 +- morph/VisualFace.h | 2 +- morph/bn/Genome.h | 2 +- morph/bn/GradGenome.h | 2 +- morph/gl/shaders.h | 2 +- morph/tools.h | 795 +++++++++--------- standalone_examples/neuralnet/ff_xor.cpp | 4 +- .../schnakenberg/schnakenberg.cpp | 16 +- standalone_examples/template/model.cpp | 2 +- tests/CMakeLists.txt | 2 +- tests/testDirichlet.cpp | 2 +- tests/testDirichlet2.cpp | 2 +- tests/testDirichlet4.cpp | 2 +- tests/testDirichlet5.cpp | 2 +- tests/testTools.cpp | 4 +- tests/test_circleboundary.cpp | 2 +- tests/test_ellipseboundary.cpp | 2 +- tests/testbighexgrid.cpp | 2 +- tests/testdirs.cpp | 4 +- tests/testhexbounddist.cpp | 4 +- tests/testhexgrid2.cpp | 4 +- tests/testhexgrid3.cpp | 4 +- tests/testhexgridsave.cpp | 12 +- 37 files changed, 490 insertions(+), 507 deletions(-) diff --git a/buildtools/process_colourmap.cpp b/buildtools/process_colourmap.cpp index 1b9dcfae..51d1a19f 100644 --- a/buildtools/process_colourmap.cpp +++ b/buildtools/process_colourmap.cpp @@ -19,8 +19,8 @@ int main (int argc, char** argv) // Obtain name from fpath std::string name = fpath; - morph::Tools::stripUnixPath (name); - morph::Tools::stripFileSuffix (name); + morph::tools::stripUnixPath (name); + morph::tools::stripFileSuffix (name); if (name.empty()) { std::cerr << "No name.\n"; return -1; @@ -53,7 +53,7 @@ int main (int argc, char** argv) unsigned int lastline = nlines - 1; for (std::string line; std::getline(ifile, line);) { // Process line into csv - std::vector tokens = morph::Tools::stringToVector (line, (commas ? "," : " ")); + std::vector tokens = morph::tools::stringToVector (line, (commas ? "," : " ")); if (tokens.size() != 3) { std::cerr << "text format error: != 3 values in line '" << line << "', (got "<< tokens.size() << ")\n"; return -1; diff --git a/buildtools/process_colourtables.cpp b/buildtools/process_colourtables.cpp index 5c6e2dcb..a2def69e 100644 --- a/buildtools/process_colourtables.cpp +++ b/buildtools/process_colourtables.cpp @@ -21,9 +21,9 @@ int main () { ctabletype tt = ctabletype::unknown; // First get a directory listing and make sure we're in the Crameri folder - if (morph::Tools::fileExists ("+README_ScientificColourMaps.pdf")) { + if (morph::tools::fileExists ("+README_ScientificColourMaps.pdf")) { tt = ctabletype::Crameri; - } else if (morph::Tools::fileExists ("CET-C1.csv")) { + } else if (morph::tools::fileExists ("CET-C1.csv")) { tt = ctabletype::CET; } else { std::cerr << "Run this program within the Crameri OR CET colour table directories\n"; @@ -35,7 +35,7 @@ int main () std::vector table_files; std::string basedir = "./"; std::string subdir = ""; - morph::Tools::readDirectoryTree (dirs, basedir, subdir); + morph::tools::readDirectoryTree (dirs, basedir, subdir); if (tt == ctabletype::Crameri) { for (auto dir : dirs) { std::cerr << "Got file " << dir << std::endl; @@ -90,14 +90,14 @@ int main () // Obtain name from fpath std::string name = fpath; - morph::Tools::stripUnixPath (name); - morph::Tools::stripFileSuffix (name); + morph::tools::stripUnixPath (name); + morph::tools::stripFileSuffix (name); if (name.empty()) { std::cerr << "No name.\n"; return -1; } std::string name_lower = name; - morph::Tools::toLowerCase (name_lower); + morph::tools::toLowerCase (name_lower); std::ifstream ifile (fpath, std::ios::in); if (!ifile.is_open()) { @@ -135,7 +135,7 @@ int main () unsigned int lastline = nlines - 1; for (std::string line; std::getline(ifile, line);) { // Process line into csv - std::vector tokens = morph::Tools::stringToVector (line, (commas ? "," : " ")); + std::vector tokens = morph::tools::stringToVector (line, (commas ? "," : " ")); if (tokens.size() != 3) { std::cerr << "text format error: != 3 values in line '" << line << "', (got "<< tokens.size() << ")\n"; return -1; diff --git a/examples/Ermentrout2009/erm.cpp b/examples/Ermentrout2009/erm.cpp index 688bc3a2..f061e089 100644 --- a/examples/Ermentrout2009/erm.cpp +++ b/examples/Ermentrout2009/erm.cpp @@ -104,9 +104,9 @@ int main (int argc, char **argv) bool do_autoscale = conf.getBool ("autoscale", false); // Now create a log directory if necessary, and exit on any failures. - if (morph::Tools::dirExists (logpath) == false) { - morph::Tools::createDir (logpath); - if (morph::Tools::dirExists (logpath) == false) { + if (morph::tools::dirExists (logpath) == false) { + morph::tools::createDir (logpath); + if (morph::tools::dirExists (logpath) == false) { std::cerr << "Failed to create the logpath directory " << logpath << " which does not exist.\n"; return 1; @@ -115,8 +115,8 @@ int main (int argc, char **argv) // Directory DOES exist. See if it contains a previous run and // exit without overwriting to avoid confusion. if (overwrite_logs == false - && (morph::Tools::fileExists (logpath + "/params.json") == true - || morph::Tools::fileExists (logpath + "/positions.h5") == true)) { + && (morph::tools::fileExists (logpath + "/params.json") == true + || morph::tools::fileExists (logpath + "/positions.h5") == true)) { std::cerr << "Seems like a previous simulation was logged in " << logpath << ".\n" << "Please clean it out manually, choose another directory or set\n" << "overwrite_logs to true in your parameters config JSON file.\n"; @@ -261,7 +261,7 @@ int main (int argc, char **argv) // Add simulation runtime information to the config, before saving it out as params.json conf.set ("float_width", (unsigned int)sizeof(FLT)); - std::string tnow = morph::Tools::timeNow(); + std::string tnow = morph::tools::timeNow(); conf.set ("sim_ran_at_time", tnow.substr(0,tnow.size()-1)); conf.set ("final_step", RD.stepCount); conf.set ("hextohex_d", RD.hextohex_d); diff --git a/examples/LotkaVolterra/lv.cpp b/examples/LotkaVolterra/lv.cpp index 85d76a25..746d6bde 100644 --- a/examples/LotkaVolterra/lv.cpp +++ b/examples/LotkaVolterra/lv.cpp @@ -111,9 +111,9 @@ int main (int argc, char **argv) // Using json filename as logpath std::string justfile = paramsfile; // Remove trailing .json and leading directories - std::vector pth = morph::Tools::stringToVector (justfile, "/"); + std::vector pth = morph::tools::stringToVector (justfile, "/"); justfile = pth.back(); - morph::Tools::searchReplace (".json", "", justfile); + morph::tools::searchReplace (".json", "", justfile); // Use logbase as the subdirectory into which this should go logbase = conf.getString ("logbase", "logs/"); if (logbase.back() != '/') { logbase += '/'; } @@ -217,9 +217,9 @@ int main (int argc, char **argv) * Now create a log directory if necessary, and exit on any * failures. */ - if (morph::Tools::dirExists (logpath) == false) { - morph::Tools::createDir (logpath); - if (morph::Tools::dirExists (logpath) == false) { + if (morph::tools::dirExists (logpath) == false) { + morph::tools::createDir (logpath); + if (morph::tools::dirExists (logpath) == false) { std::cerr << "Failed to create the logpath directory " << logpath << " which does not exist.\n"; return 1; @@ -228,8 +228,8 @@ int main (int argc, char **argv) // Directory DOES exist. See if it contains a previous run and // exit without overwriting to avoid confusion. if (overwrite_logs == false - && (morph::Tools::fileExists (logpath + "/params.json") == true - || morph::Tools::fileExists (logpath + "/positions.h5") == true)) { + && (morph::tools::fileExists (logpath + "/params.json") == true + || morph::tools::fileExists (logpath + "/positions.h5") == true)) { std::cerr << "Seems like a previous simulation was logged in " << logpath << ".\n" << "Please clean it out manually, choose another directory or set\n" << "overwrite_logs to true in your parameters config JSON file.\n"; @@ -319,7 +319,7 @@ int main (int argc, char **argv) // results were computed with single precision, if 8, then double // precision was used. Also save various parameters from the RD system. conf.set ("float_width", (unsigned int)sizeof(FLT)); - std::string tnow = morph::Tools::timeNow(); + std::string tnow = morph::tools::timeNow(); conf.set ("sim_ran_at_time", tnow.substr(0,tnow.size()-1)); conf.set ("hextohex_d", RD.hextohex_d); conf.set ("dt", RD.get_dt()); diff --git a/examples/SimpsonGoodhill/sg.cpp b/examples/SimpsonGoodhill/sg.cpp index d68284fc..d0d7ce24 100644 --- a/examples/SimpsonGoodhill/sg.cpp +++ b/examples/SimpsonGoodhill/sg.cpp @@ -220,7 +220,7 @@ int main (int argc, char **argv) } else { // Create an empty/default json file paramsfile = "./sg.json"; - morph::Tools::copyStringToFile ("{}\n", paramsfile); + morph::tools::copyStringToFile ("{}\n", paramsfile); } morph::Config conf(paramsfile); diff --git a/examples/schnakenberg/schnak_whisk.cpp b/examples/schnakenberg/schnak_whisk.cpp index 109259be..54b7c8ec 100644 --- a/examples/schnakenberg/schnak_whisk.cpp +++ b/examples/schnakenberg/schnak_whisk.cpp @@ -79,7 +79,6 @@ using morph::scale; using morph::vec; #endif using morph::Config; -using morph::Tools; using std::string; using std::stringstream; using std::cerr; @@ -133,9 +132,9 @@ int main (int argc, char **argv) // Using json filename as logpath string justfile = paramsfile; // Remove trailing .json and leading directories - vector pth = Tools::stringToVector (justfile, "/"); + vector pth = morph::tools::stringToVector (justfile, "/"); justfile = pth.back(); - Tools::searchReplace (".json", "", justfile); + morph::tools::searchReplace (".json", "", justfile); // Use logbase as the subdirectory into which this should go logbase = conf.getString ("logbase", "logs/"); if (logbase.back() != '/') { @@ -237,9 +236,9 @@ int main (int argc, char **argv) * Now create a log directory if necessary, and exit on any * failures. */ - if (Tools::dirExists (logpath) == false) { - Tools::createDir (logpath); - if (Tools::dirExists (logpath) == false) { + if (morph::tools::dirExists (logpath) == false) { + morph::tools::createDir (logpath); + if (morph::tools::dirExists (logpath) == false) { cerr << "Failed to create the logpath directory " << logpath << " which does not exist."<< endl; return 1; @@ -248,8 +247,8 @@ int main (int argc, char **argv) // Directory DOES exist. See if it contains a previous run and // exit without overwriting to avoid confusion. if (overwrite_logs == false - && (Tools::fileExists (logpath + "/params.json") == true - || Tools::fileExists (logpath + "/positions.h5") == true)) { + && (morph::tools::fileExists (logpath + "/params.json") == true + || morph::tools::fileExists (logpath + "/positions.h5") == true)) { cerr << "Seems like a previous simulation was logged in " << logpath << ".\n" << "Please clean it out manually, choose another directory or set\n" << "overwrite_logs to true in your parameters config JSON file." << endl; @@ -347,7 +346,7 @@ int main (int argc, char **argv) // results were computed with single precision, if 8, then double // precision was used. Also save various parameters from the RD system. conf.set ("float_width", (unsigned int)sizeof(FLT)); - string tnow = Tools::timeNow(); + string tnow = morph::tools::timeNow(); conf.set ("sim_ran_at_time", tnow.substr(0,tnow.size()-1)); conf.set ("hextohex_d", RD.hextohex_d); conf.set ("D_A", RD.D_A); diff --git a/examples/schnakenberg/schnakenberg.cpp b/examples/schnakenberg/schnakenberg.cpp index 1579fce7..1a719fd6 100644 --- a/examples/schnakenberg/schnakenberg.cpp +++ b/examples/schnakenberg/schnakenberg.cpp @@ -79,7 +79,6 @@ using morph::scale; using morph::vec; #endif using morph::Config; -using morph::Tools; using std::string; using std::stringstream; using std::cerr; @@ -133,9 +132,9 @@ int main (int argc, char **argv) // Using json filename as logpath string justfile = paramsfile; // Remove trailing .json and leading directories - vector pth = Tools::stringToVector (justfile, "/"); + vector pth = morph::tools::stringToVector (justfile, "/"); justfile = pth.back(); - Tools::searchReplace (".json", "", justfile); + morph::tools::searchReplace (".json", "", justfile); // Use logbase as the subdirectory into which this should go logbase = conf.getString ("logbase", "logs/"); if (logbase.back() != '/') { @@ -239,9 +238,9 @@ int main (int argc, char **argv) * Now create a log directory if necessary, and exit on any * failures. */ - if (Tools::dirExists (logpath) == false) { - Tools::createDir (logpath); - if (Tools::dirExists (logpath) == false) { + if (morph::tools::dirExists (logpath) == false) { + morph::tools::createDir (logpath); + if (morph::tools::dirExists (logpath) == false) { cerr << "Failed to create the logpath directory " << logpath << " which does not exist."<< endl; return 1; @@ -250,8 +249,8 @@ int main (int argc, char **argv) // Directory DOES exist. See if it contains a previous run and // exit without overwriting to avoid confusion. if (overwrite_logs == false - && (Tools::fileExists (logpath + "/params.json") == true - || Tools::fileExists (logpath + "/positions.h5") == true)) { + && (morph::tools::fileExists (logpath + "/params.json") == true + || morph::tools::fileExists (logpath + "/positions.h5") == true)) { cerr << "Seems like a previous simulation was logged in " << logpath << ".\n" << "Please clean it out manually, choose another directory or set\n" << "overwrite_logs to true in your parameters config JSON file." << endl; @@ -355,7 +354,7 @@ int main (int argc, char **argv) // results were computed with single precision, if 8, then double // precision was used. Also save various parameters from the RD system. conf.set ("float_width", (unsigned int)sizeof(FLT)); - string tnow = Tools::timeNow(); + string tnow = morph::tools::timeNow(); conf.set ("sim_ran_at_time", tnow.substr(0,tnow.size()-1)); conf.set ("hextohex_d", RD.hextohex_d); conf.set ("D_A", RD.D_A); diff --git a/morph/ColourMap.h b/morph/ColourMap.h index 92d69a4b..4b0df0db 100644 --- a/morph/ColourMap.h +++ b/morph/ColourMap.h @@ -578,7 +578,7 @@ namespace morph { { ColourMapType cmt = morph::ColourMapType::Plasma; std::string _s = s; - morph::Tools::toLowerCase (_s); + morph::tools::toLowerCase (_s); if (_s == "fixed") { cmt = morph::ColourMapType::Fixed; } else if (_s == "trichrome") { diff --git a/morph/Config.h b/morph/Config.h index d2b765a7..2251b548 100644 --- a/morph/Config.h +++ b/morph/Config.h @@ -279,7 +279,7 @@ namespace morph { if ((pos = arg.find ("-co:")) == 0) { std::string arg_ss = arg.substr (4); // Split arg based on '=' - std::vector co = morph::Tools::stringToVector (arg_ss, std::string("=")); + std::vector co = morph::tools::stringToVector (arg_ss, std::string("=")); if (co.size() >= 2) { std::cout << "Override parameter '" << co[0] << "' with value '" << co[1] << "'\n"; //...so stick with using a map diff --git a/morph/HdfData.h b/morph/HdfData.h index 3edb079b..32c9f7f7 100644 --- a/morph/HdfData.h +++ b/morph/HdfData.h @@ -719,7 +719,7 @@ namespace morph { */ void process_groups (const char* path) { - std::vector pbits = morph::Tools::stringToVector (path, "/"); + std::vector pbits = morph::tools::stringToVector (path, "/"); unsigned int numgroups = pbits.size() - 1; if (numgroups > 1) { // There's always the first, empty (root) group std::string groupstr(""); diff --git a/morph/RD_Base.h b/morph/RD_Base.h index 32c02485..900c93f9 100644 --- a/morph/RD_Base.h +++ b/morph/RD_Base.h @@ -164,7 +164,7 @@ namespace morph { void setLogpath (const std::string p) { this->logpath = p; // Ensure log directory exists - morph::Tools::createDir (this->logpath); + morph::tools::createDir (this->logpath); } /*! diff --git a/morph/Random.h b/morph/Random.h index dfc8b2cb..92fb796f 100644 --- a/morph/Random.h +++ b/morph/Random.h @@ -44,7 +44,7 @@ * exponential). * * See tests/testRandom.cpp for a variety of usage examples. Here is a single, simple - * example to replace the old (and now removed) morph::Tools::randDouble(): + * example: * * \code * #include diff --git a/morph/ReadCurves.h b/morph/ReadCurves.h index 7af8c8e4..1e105e30 100644 --- a/morph/ReadCurves.h +++ b/morph/ReadCurves.h @@ -366,9 +366,9 @@ namespace morph // Extract the length of the line in mm from the layer name // _x33_mm means .33 mm std::string mm(g_id); - morph::Tools::searchReplace ("x", ".", mm); - morph::Tools::searchReplace ("_", "", mm); - morph::Tools::searchReplace ("m", "", mm); + morph::tools::searchReplace ("x", ".", mm); + morph::tools::searchReplace ("_", "", mm); + morph::tools::searchReplace ("m", "", mm); float mmf = std::atof (mm.c_str()); // dl is the length of the scale bar line float dl = 0.0f; @@ -404,7 +404,7 @@ namespace morph std::stringstream ss; ss << s.substr(p0, p1-p0); std::string ccs = ss.str(); - if (morph::Tools::containsOnlyWhitespace (ccs)) { + if (morph::tools::containsOnlyWhitespace (ccs)) { // Do nothing } else { ss >> n; @@ -516,7 +516,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string lCmd = d.substr (p1+1, p2-p1-1); - if (morph::Tools::containsOnlyWhitespace (lCmd)) { + if (morph::tools::containsOnlyWhitespace (lCmd)) { p3 = lCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (lCmd, cmd, 10000, p3); @@ -542,7 +542,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string lCmd = d.substr (p1+1, p2-p1-1); - if (morph::Tools::containsOnlyWhitespace (lCmd)) { + if (morph::tools::containsOnlyWhitespace (lCmd)) { p3 = lCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (lCmd, cmd, 10000, p3); @@ -568,7 +568,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string lCmd = d.substr (p1+1, p2-p1-1); - if (morph::Tools::containsOnlyWhitespace (lCmd)) { + if (morph::tools::containsOnlyWhitespace (lCmd)) { p3 = lCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (lCmd, cmd, 10000, p3); @@ -599,7 +599,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string mCmd = d.substr (p1+1, p2-p1-1); - if (morph::Tools::containsOnlyWhitespace (mCmd)) { + if (morph::tools::containsOnlyWhitespace (mCmd)) { p3 = mCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (mCmd, cmd, 10000, p3); @@ -639,7 +639,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string cCmd = d.substr (p1+1, p2-p1-1); // cCmd may be either a single command (6 params) or a great long line. - if (morph::Tools::containsOnlyWhitespace (cCmd)) { + if (morph::tools::containsOnlyWhitespace (cCmd)) { p3 = cCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (cCmd, cmd, 6, p3); @@ -669,7 +669,7 @@ namespace morph { p2 = d.find_first_of (svgCmds, p1+1); std::string sCmd = d.substr (p1+1, p2-p1-1); - if (morph::Tools::containsOnlyWhitespace (sCmd)) { + if (morph::tools::containsOnlyWhitespace (sCmd)) { p3 = sCmd.size()-1; } else { std::vector v = this->splitSvgCmdString (sCmd, cmd, 4, p3); diff --git a/morph/RecurrentNetworkModel.h b/morph/RecurrentNetworkModel.h index a07a1666..06f5ab2c 100644 --- a/morph/RecurrentNetworkModel.h +++ b/morph/RecurrentNetworkModel.h @@ -257,7 +257,7 @@ namespace morph { // setup log file this->logpath = logpath; - morph::Tools::createDir (logpath); + morph::tools::createDir (logpath); { std::stringstream ss; ss << logpath << "/log.txt"; logfile.open(ss.str());} logfile<<"Hello."<title); - morph::Tools::stripFileSuffix (fname); + morph::tools::stripFileSuffix (fname); fname += ".png"; // Make fname 'filename safe' - morph::Tools::conditionAsFilename (fname); + morph::tools::conditionAsFilename (fname); this->saveImage (fname); std::cout << "Saved image to '" << fname << "'\n"; } @@ -1236,9 +1236,9 @@ namespace morph { // Save gltf 3D file if (_key == key::m && (mods & keymod::control) && action == keyaction::press) { std::string gltffile = this->title; - morph::Tools::stripFileSuffix (gltffile); + morph::tools::stripFileSuffix (gltffile); gltffile += ".gltf"; - morph::Tools::conditionAsFilename (gltffile); + morph::tools::conditionAsFilename (gltffile); this->savegltf (gltffile); std::cout << "Saved 3D file '" << gltffile << "'\n"; } diff --git a/morph/VisualFace.h b/morph/VisualFace.h index 24ea85b5..3f4d570e 100644 --- a/morph/VisualFace.h +++ b/morph/VisualFace.h @@ -486,7 +486,7 @@ namespace morph { void makeTempFontFile (const std::string& fontpath, T* file_start, T* file_stop) { T* p; - if (!morph::Tools::fileExists (fontpath)) { + if (!morph::tools::fileExists (fontpath)) { std::ofstream fout; fout.open (fontpath.c_str(), std::ios::out | std::ios::trunc | std::ios::binary); if (fout.is_open()) { diff --git a/morph/bn/Genome.h b/morph/bn/Genome.h index 39430f77..20126036 100644 --- a/morph/bn/Genome.h +++ b/morph/bn/Genome.h @@ -88,7 +88,7 @@ namespace morph { void set (const std::string& hexstr) { // 1 split string by the '-' character - std::vector parts = morph::Tools::stringToVector (hexstr, "-"); + std::vector parts = morph::tools::stringToVector (hexstr, "-"); // 2 Make sure there are N sections if (parts.size() != N) { diff --git a/morph/bn/GradGenome.h b/morph/bn/GradGenome.h index 1968ea88..8ca55f8e 100644 --- a/morph/bn/GradGenome.h +++ b/morph/bn/GradGenome.h @@ -279,7 +279,7 @@ namespace morph { void set (const std::string& hexstr) { // 1 split string by the '-' character - std::vector parts = morph::Tools::stringToVector (hexstr, "-"); + std::vector parts = morph::tools::stringToVector (hexstr, "-"); // 2 Make sure there are N sections if (parts.size() != N) { diff --git a/morph/gl/shaders.h b/morph/gl/shaders.h index 0536c7f9..3f5eea45 100644 --- a/morph/gl/shaders.h +++ b/morph/gl/shaders.h @@ -127,7 +127,7 @@ namespace morph { if constexpr (debug_shaders == true) { std::cout << "Check file exists for " << entry.filename << std::endl; } - if (morph::Tools::fileExists (entry.filename)) { + if (morph::tools::fileExists (entry.filename)) { std::cout << "Using " << morph::gl::shader_type_str(entry.type) << " shader from the file " << entry.filename << std::endl; source = morph::gl::ReadShader (entry.filename); diff --git a/morph/tools.h b/morph/tools.h index 75b78ffd..2b970cc4 100644 --- a/morph/tools.h +++ b/morph/tools.h @@ -88,14 +88,13 @@ namespace morph //! Allows use of transform and toupper() on strings with GNU compiler struct to_upper { char operator() (const char c) const { return toupper(c); } }; - class Tools + namespace tools { - public: /*! * For mixing up bits of three args; used to generate a good random seed using * time() getpid() and clock(). */ - static unsigned int mix (unsigned int a, unsigned int b, unsigned int c) + unsigned int mix (unsigned int a, unsigned int b, unsigned int c) { a=a-b; a=a-c; a=a^(c >> 13); b=b-c; b=b-a; b=b^(a << 8); @@ -114,16 +113,16 @@ namespace morph * Using clock(), time() and getpid() along with the mix utility function, * generate a decently random seed for seeding your RNG. */ - static unsigned int randomSeed() + unsigned int randomSeed() { - unsigned int rsd = morph::Tools::mix(clock(), time(NULL), getpid()); + unsigned int rsd = morph::tools::mix(clock(), time(NULL), getpid()); return rsd; } #endif /*! * return indices of descending value in unsorted */ - static std::vector sort (std::vector unsorted) + std::vector sort (std::vector unsorted) { std::vector unsortID; for(int i=0;i(unsorted.size());i++){ @@ -156,7 +155,7 @@ namespace morph * characters which are present will be removed, whether or not they are * followed by a '\\n' character. */ - static int ensureUnixNewlines (std::string& input) + int ensureUnixNewlines (std::string& input) { int num = 0; @@ -173,7 +172,7 @@ namespace morph /*! * Get the working directory */ - static std::string getPwd() + std::string getPwd() { char b[FILENAME_MAX]; char* rtn = GetCurrentDir (b, FILENAME_MAX); @@ -188,7 +187,7 @@ namespace morph * * \return 0 on success, -1 & sets errno otherwise */ - static int setPwd (const std::string& directory) + int setPwd (const std::string& directory) { int rtn = SetCurrentDir (directory.c_str()); return rtn; @@ -198,7 +197,7 @@ namespace morph * If the last character of input is a carriage return ('\\r' 0xd), then it is * erased from input. */ - static int stripTrailingCarriageReturn (std::string& input) + int stripTrailingCarriageReturn (std::string& input) { if (input[input.size()-1] == '\r') { input.erase(input.size()-1, 1); @@ -207,18 +206,10 @@ namespace morph return 0; } - /*! - * Erase trailing spaces from input. Return the number of spaces removed. - */ - static int stripTrailingSpaces (std::string& input) - { - return Tools::stripTrailingChars (input); - } - /*! * Erase trailing chars c from input. Return the number of chars removed. */ - static int stripTrailingChars (std::string& input, const char c = ' ') + int stripTrailingChars (std::string& input, const char c = ' ') { int i = 0; while (input.size()>0 && input[input.size()-1] == c) { @@ -228,11 +219,19 @@ namespace morph return i; } + /*! + * Erase trailing spaces from input. Return the number of spaces removed. + */ + int stripTrailingSpaces (std::string& input) + { + return tools::stripTrailingChars (input); + } + /*! * Erase trailing whitespace from input. Return the number of whitespace * characters removed. */ - static int stripTrailingWhitespace (std::string& input) + int stripTrailingWhitespace (std::string& input) { char c; std::string::size_type len = input.size(), pos = len; @@ -247,18 +246,10 @@ namespace morph return (len - pos); } - /*! - * Erase leading spaces from input. Return the number of spaces removed. - */ - static int stripLeadingSpaces (std::string& input) - { - return Tools::stripLeadingChars (input); - } - /*! * Erase any leading character c from input. Return the number of chars removed. */ - static int stripLeadingChars (std::string& input, const char c = ' ') + int stripLeadingChars (std::string& input, const char c = ' ') { int i = 0; while (input.size()>0 && input[0] == c) { @@ -268,11 +259,19 @@ namespace morph return i; } + /*! + * Erase leading spaces from input. Return the number of spaces removed. + */ + int stripLeadingSpaces (std::string& input) + { + return tools::stripLeadingChars (input); + } + /*! * Erase leading whitespace from input. Return the number of whitespace * characters removed. */ - static int stripLeadingWhitespace (std::string& input) + int stripLeadingWhitespace (std::string& input) { char c; std::string::size_type pos = 0; @@ -291,17 +290,17 @@ namespace morph * Erase leading and trailing whitespace from input. Return the number of * whitespace characters removed. */ - static int stripWhitespace (std::string& input) + int stripWhitespace (std::string& input) { - int n = Tools::stripLeadingWhitespace (input); - n += Tools::stripTrailingWhitespace (input); + int n = tools::stripLeadingWhitespace (input); + n += tools::stripTrailingWhitespace (input); return n; } /*! * Return true if input contains only space, tab, newline chars. */ - static bool containsOnlyWhitespace (std::string& input) + bool containsOnlyWhitespace (std::string& input) { bool rtn = true; for (std::string::size_type i = 0; i < input.size(); ++i) { @@ -318,7 +317,7 @@ namespace morph /*! * Strip any occurrences of the characters in charList from input. */ - static int stripChars (std::string& input, const std::string& charList) + int stripChars (std::string& input, const std::string& charList) { int rtn(0); std::string::size_type pos(0); @@ -332,7 +331,7 @@ namespace morph /*! * Strip any occurrences of the characters in charList from input. */ - static int stripChars (std::string& input, const char charList) + int stripChars (std::string& input, const char charList) { int rtn(0); std::string::size_type pos(0); @@ -350,7 +349,7 @@ namespace morph * * \return The number of hex sequences replaced in \param input. */ - static int convertCHexCharSequences (std::string& input) + int convertCHexCharSequences (std::string& input) { // This converts a string containing C style hex sequences like // "\x41\x42\x43" into the corresponding characters ("ABC" for the example). @@ -540,10 +539,10 @@ namespace morph * * \return the number of terms replaced. */ - static int searchReplace (const std::string& searchTerm, - const std::string& replaceTerm, - std::string& data, - const bool replaceAll = true) + int searchReplace (const std::string& searchTerm, + const std::string& replaceTerm, + std::string& data, + const bool replaceAll = true) { int count = 0; std::string::size_type pos = 0; @@ -579,7 +578,7 @@ namespace morph /*! * Return the number of instances of the character c in line. */ - static unsigned int countChars (const std::string& line, const char c) + unsigned int countChars (const std::string& line, const char c) { unsigned int count(0); std::string::const_iterator i = line.begin(); @@ -590,13 +589,13 @@ namespace morph } //! Convert str to lower case - static void toLowerCase (std::string& str) + void toLowerCase (std::string& str) { std::transform (str.begin(), str.end(), str.begin(), morph::to_lower()); } //! Convert str to upper case - static void toUpperCase (std::string& str) + void toUpperCase (std::string& str) { std::transform (str.begin(), str.end(), str.begin(), morph::to_upper()); } @@ -605,7 +604,7 @@ namespace morph * Remove filename-forbidden characters from str (including directory specifiers * '\' and '/'. */ - static void conditionAsFilename (std::string& str) + void conditionAsFilename (std::string& str) { std::string::size_type ptr = std::string::npos; while ((ptr = str.find_last_not_of (COMMON_FILE_SAFE_CHARS, ptr)) != std::string::npos) { @@ -619,7 +618,7 @@ namespace morph * replacing disallowed characters with '_' and making sure it doesn't start * with a numeral. */ - static void conditionAsXmlTag (std::string& str) + void conditionAsXmlTag (std::string& str) { // 1) Replace chars which are disallowed in an XML tag std::string::size_type ptr = std::string::npos; @@ -658,9 +657,9 @@ namespace morph * separator with nothing after it will NOT cause an additional empty value in * the returned vector. See also splitStringWithEncs */ - static std::vector stringToVector (const std::string& s, - const std::string& separator, - const bool ignoreTrailingEmptyVal = true) + std::vector stringToVector (const std::string& s, + const std::string& separator, + const bool ignoreTrailingEmptyVal = true) { if (separator.empty()) { throw std::runtime_error ("Can't split the string; the separator is empty."); @@ -697,7 +696,7 @@ namespace morph * Stat a file Windows style, return true if the file exists and is any kind of * file except a directory. */ - static bool fileExists (const std::string& path) + bool fileExists (const std::string& path) { struct _stat* buf = NULL; @@ -720,14 +719,14 @@ namespace morph } // Check if a directory exists, windows style - static bool dirExists (const std::string& path) + bool dirExists (const std::string& path) { struct stat buffer; return (stat (path.c_str(), &buffer) == 0); } // Create a directory, C++17 style. Hardly needs a wrapper. Could replace unix createDir with this. - static void createDir (const std::string& path) + void createDir (const std::string& path) { std::filesystem::create_directories (path); } @@ -738,7 +737,7 @@ namespace morph * Stat a file, return true if the file exists and is any kind of file except a * directory. */ - static bool fileExists (const std::string& path) + bool fileExists (const std::string& path) { struct stat * buf = NULL; @@ -773,7 +772,7 @@ namespace morph * is a hanging symlink, fileExists returns false, if file is a symlink pointing * to a regular file, fileExists returns true. */ - static bool regfileExists (const std::string& path) + bool regfileExists (const std::string& path) { struct stat * buf = NULL; @@ -798,7 +797,7 @@ namespace morph * Like regfileExists, but also checks if the file has the "executable by user" * bit set (chmod u+x). */ - static bool userExefileExists (const std::string& path) + bool userExefileExists (const std::string& path) { struct stat * buf = NULL; @@ -822,7 +821,7 @@ namespace morph /*! * Like regfileExists, but for block devices */ - static bool blockdevExists (const std::string& path) + bool blockdevExists (const std::string& path) { struct stat * buf = NULL; @@ -846,7 +845,7 @@ namespace morph /*! * Like regfileExists, but for sockets */ - static bool socketExists (const std::string& path) + bool socketExists (const std::string& path) { struct stat * buf = NULL; @@ -870,7 +869,7 @@ namespace morph /*! * Like regfileExists, but for fifos */ - static bool fifoExists (const std::string& path) + bool fifoExists (const std::string& path) { struct stat * buf = NULL; @@ -894,7 +893,7 @@ namespace morph /*! * Like regfileExists, but for char devices */ - static bool chardevExists (const std::string& path) + bool chardevExists (const std::string& path) { struct stat * buf = NULL; @@ -918,7 +917,7 @@ namespace morph /*! * Does a link exist? */ - static bool linkExists (const std::string& path) + bool linkExists (const std::string& path) { struct stat * buf = NULL; @@ -942,7 +941,7 @@ namespace morph /*! * Stat a directory, return true if the directory exists. */ - static bool dirExists (const std::string& path) + bool dirExists (const std::string& path) { DIR* d; if (!(d = opendir (path.c_str()))) { @@ -976,9 +975,9 @@ namespace morph * \param gid The group id to apply to the directory. This is applied even if * the directory was not created. This is NOT applied if it is set to -1. */ - static void createDir (const std::string& path, - const mode_t mode = 0775, - const int uid = -1, const int gid = -1) + void createDir (const std::string& path, + const mode_t mode = 0775, + const int uid = -1, const int gid = -1) { if (path.empty()) { return; } @@ -1104,7 +1103,7 @@ namespace morph /*! * Attempt to rmdir path. */ - static void removeDir (const std::string& path) + void removeDir (const std::string& path) { int rtn = rmdir (path.c_str()); if (rtn) { @@ -1159,13 +1158,13 @@ namespace morph * * \return true if directory was created, false if directory already existed */ - static bool createDirIf (const std::string& path) + bool createDirIf (const std::string& path) { std::stringstream ee; - if (morph::Tools::dirExists (path) == false) { - morph::Tools::createDir (path); - if (morph::Tools::dirExists (path) == false) { + if (morph::tools::dirExists (path) == false) { + morph::tools::createDir (path); + if (morph::tools::dirExists (path) == false) { ee << "Failed to create the directory " << path; throw std::runtime_error (ee.str()); } @@ -1178,7 +1177,7 @@ namespace morph /*! * Set the permissions for the provided file */ - static void setPermissions (const std::string& filepath, const mode_t mode) + void setPermissions (const std::string& filepath, const mode_t mode) { int rtn = chmod (filepath.c_str(), mode); if (rtn) { @@ -1236,7 +1235,7 @@ namespace morph * \param filepath File to check. \param accessType Indicates which access * type(s) to check. r=read, w=write. */ - static bool checkAccess (const std::string& filepath, const std::string& accessType) + bool checkAccess (const std::string& filepath, const std::string& accessType) { if (accessType.find("r") != std::string::npos) { std::ifstream in; @@ -1260,9 +1259,9 @@ namespace morph /*! * Set the ownership for the provided file */ - static void setOwnership (const std::string& filepath, - const int uid = -1, - const int gid = -1) + void setOwnership (const std::string& filepath, + const int uid = -1, + const int gid = -1) { int rtn = chown (filepath.c_str(), uid, gid); if (rtn) { @@ -1315,7 +1314,7 @@ namespace morph /*! * Touch the file. */ - static void touchFile (const std::string& path) + void touchFile (const std::string& path) { std::ofstream f; f.open (path.c_str(), std::ios::out|std::ios::app); @@ -1344,39 +1343,25 @@ namespace morph #define COPYFILE_BUFFERSIZE 32768 #define COPYFILE_BUFFERSIZE_MM 32767 // MM: Minus Minus #ifndef __WIN__ - static void copyFile (const std::string& from, const std::string& to) - { - std::ofstream out; - - out.open (to.c_str(), std::ios::out|std::ios::trunc); - if (!out.is_open()) { - std::string emsg = "Tools::copyFile(): Couldn't open TO file '" + to + "'"; - throw std::runtime_error (emsg); - } - - Tools::copyFile (from, out); - - out.close(); - } - static void copyFile (const std::string& from, std::ostream& to) + void copyFile (const std::string& from, std::ostream& to) { std::ifstream in; // Test that "from" is a regular file - if (!Tools::regfileExists (from)) { + if (!tools::regfileExists (from)) { std::stringstream ee; - ee << "Tools::copyFile(): FROM file '" + ee << "tools::copyFile(): FROM file '" << from << "' is not a regular file"; throw std::runtime_error (ee.str()); } in.open (from.c_str(), std::ios::in); if (!in.is_open()) { - throw std::runtime_error ("Tools::copyFile(): Couldn't open FROM file"); + throw std::runtime_error ("tools::copyFile(): Couldn't open FROM file"); } if (!to) { - throw std::runtime_error ("Tools::copyFile(): Error occurred in TO stream"); + throw std::runtime_error ("tools::copyFile(): Error occurred in TO stream"); } char buf[64]; @@ -1394,8 +1379,22 @@ namespace morph // Finally, close the input. in.close(); } + void copyFile (const std::string& from, const std::string& to) + { + std::ofstream out; + + out.open (to.c_str(), std::ios::out|std::ios::trunc); + if (!out.is_open()) { + std::string emsg = "tools::copyFile(): Couldn't open TO file '" + to + "'"; + throw std::runtime_error (emsg); + } + + tools::copyFile (from, out); + + out.close(); + } #endif // __WIN__ - static void copyFile (FILE* from, const std::string& to) + void copyFile (FILE* from, const std::string& to) { FILE * ofp = NULL; long pos; @@ -1407,19 +1406,19 @@ namespace morph ofp = fopen (to.c_str(), "w"); if (!ofp) { - throw std::runtime_error ("Tools::copyFile(): Can't open output for writing"); + throw std::runtime_error ("tools::copyFile(): Can't open output for writing"); } while ((bytes = fread (inputBuffer, 1, COPYFILE_BUFFERSIZE_MM, from)) > 0) { output = fwrite (inputBuffer, 1, bytes, ofp); if (output != bytes) { fseek (from, pos, SEEK_SET); /* reset input */ - throw std::runtime_error ("Tools::copyFile(): Error writing data"); + throw std::runtime_error ("tools::copyFile(): Error writing data"); } } fclose (ofp); /* close output */ fseek (from, pos, SEEK_SET); /* reset input */ } - static void copyFile (std::istream& from, const std::string& to) + void copyFile (std::istream& from, const std::string& to) { char buf[64]; std::ofstream f; @@ -1434,20 +1433,12 @@ namespace morph f.write (buf, from.gcount()); } } -#ifndef __WIN__ - static void copyFile (const std::string& from, FILE* to) - { - FILE* ifp = fopen (from.c_str(), "r"); - Tools::copyFile (ifp, to); - fclose (ifp); - } -#endif /*! * Copy from one file pointer to another. Both are expected to be open, neither * is closed after the copy. */ - static void copyFile (FILE* from, FILE* to) + void copyFile (FILE* from, FILE* to) { long pos; int bytes=0, output=0; @@ -1457,22 +1448,31 @@ namespace morph pos = ftell (from); if (!to) { - throw std::runtime_error ("Tools::copyFile(): output is not open for writing"); + throw std::runtime_error ("tools::copyFile(): output is not open for writing"); } while ((bytes = fread (inputBuffer, 1, COPYFILE_BUFFERSIZE_MM, from)) > 0) { output = fwrite (inputBuffer, 1, bytes, to); if (output != bytes) { fseek (from, pos, SEEK_SET); /* reset input */ - throw std::runtime_error ("Tools::copyFile(): Error writing data"); + throw std::runtime_error ("tools::copyFile(): Error writing data"); } } fseek (from, pos, SEEK_SET); /* reset input */ } +#ifndef __WIN__ + void copyFile (const std::string& from, FILE* to) + { + FILE* ifp = fopen (from.c_str(), "r"); + tools::copyFile (ifp, to); + fclose (ifp); + } +#endif + /*! * Copy a file from an input stream into a string. */ - static void copyFileToString (std::istream& from, std::string& to) + void copyFileToString (std::istream& from, std::string& to) { char buf[64]; while (!from.eof()) { @@ -1481,7 +1481,7 @@ namespace morph } } - static void copyStringToFile (const std::string& fromstr, const std::string& to) + void copyStringToFile (const std::string& fromstr, const std::string& to) { std::ofstream out; out.open (to.c_str(), std::ios::out|std::ios::trunc); @@ -1495,7 +1495,7 @@ namespace morph } //! Append the file from to the filestream appendTo - static void appendFile (const std::string& from, std::ostream& appendTo) + void appendFile (const std::string& from, std::ostream& appendTo) { if (!appendTo.good()) { throw std::runtime_error ("Can't append to appendTo, it's not good()"); @@ -1503,7 +1503,7 @@ namespace morph std::ifstream in; in.open (from.c_str(), std::ios::in); if (!in.is_open()) { - throw std::runtime_error ("Tools::appendFile(): Couldn't open FROM file"); + throw std::runtime_error ("tools::appendFile(): Couldn't open FROM file"); } char buf[64]; @@ -1516,7 +1516,7 @@ namespace morph } //! Append the content of the filestream from to the filestream appendTo - static void appendFile (std::istream& from, std::ostream& appendTo) + void appendFile (std::istream& from, std::ostream& appendTo) { if (!appendTo.good()) { throw std::runtime_error ("Can't append to appendTo, it's not good()"); @@ -1531,7 +1531,7 @@ namespace morph } //! Append the content of the filestream from to the file at appendTo - static void appendFile (std::istream& from, const std::string& appendTo) + void appendFile (std::istream& from, const std::string& appendTo) { std::ofstream f; f.open (appendTo.c_str(), std::ios::out|std::ios::app); @@ -1550,7 +1550,7 @@ namespace morph } //! Append the file at path from to the file at path appendTo - static void appendFile (const std::string& from, const std::string& appendTo) + void appendFile (const std::string& from, const std::string& appendTo) { std::ifstream fin; fin.open (from.c_str(), std::ios::in); @@ -1576,40 +1576,94 @@ namespace morph } } + /*! + * Call unlink() on the given file path fpath. If unlinking fails, throw a + * descriptive error based on the errno which was set on unlink's return. + */ + void unlinkFile (const std::string& fpath) + { + int rtn = unlink (fpath.c_str()); + if (rtn) { + int theError = errno; + std::string emsg; + switch (theError) { + case EPERM: + case EACCES: + emsg = "Write access to '" + fpath + "' is not allowed due to permissions"; + break; + case EBUSY: + emsg = "'" + fpath + "' cannot be removed as it is in use by another process"; + break; + case EFAULT: + emsg = "'" + fpath + "' points outside your accessible address space"; + break; + case EIO: + emsg = "I/O error occurred reading '" + fpath + "'"; + break; + case EISDIR: + emsg = "'" + fpath + "' is a directory"; + break; + case ELOOP: + emsg = "Too many symlinks encountered in '" + fpath + "'"; + break; + case ENAMETOOLONG: + emsg = "'" + fpath + "' is too long a name"; + break; + case ENOENT: + emsg = "'" + fpath + "' does not exist or is a dangling symlink"; + break; + case ENOMEM: + emsg = "In sufficient kernel memory to open '" + fpath + "'"; + break; + case ENOTDIR: + emsg = "'" + fpath + "' contains a component that is not a directory"; + break; + case EROFS: + emsg = "'" + fpath + "' is on a read-only filesystem"; + break; + default: + emsg = "Unknown error unlinking file '" + fpath + "'"; + break; + } + + throw std::runtime_error (emsg); + } + } + #ifndef __WIN__ /*! * Make a copy of \param bytes bytes of the file at \param original to the file * \param truncated. */ - static void truncateFile (const std::string& original, - const std::string& truncated, - const unsigned int bytes) + void truncateFile (const std::string& original, + const std::string& truncated, + const unsigned int bytes) { std::ofstream out; out.open (truncated.c_str(), std::ios::out|std::ios::trunc); if (!out.is_open()) { - std::string emsg = "Tools::copyFile(): Couldn't open TRUNCATED file '" + truncated + "'"; + std::string emsg = "tools::copyFile(): Couldn't open TRUNCATED file '" + truncated + "'"; throw std::runtime_error (emsg); } std::ifstream in; // Test that "original" is a regular file - if (!Tools::regfileExists (original)) { + if (!tools::regfileExists (original)) { std::stringstream ee; - ee << "Tools::truncateFile(): ORIGINAL file '" + ee << "tools::truncateFile(): ORIGINAL file '" << original << "' is not a regular file"; throw std::runtime_error (ee.str()); } in.open (original.c_str(), std::ios::in); if (!in.is_open()) { - throw std::runtime_error ("Tools::truncateFile(): Couldn't open ORIGINAL file"); + throw std::runtime_error ("tools::truncateFile(): Couldn't open ORIGINAL file"); } if (!out) { - throw std::runtime_error ("Tools::truncateFile(): Error occurred in TRUNCATED stream"); + throw std::runtime_error ("tools::truncateFile(): Error occurred in TRUNCATED stream"); } unsigned int loops(0); @@ -1647,100 +1701,10 @@ namespace morph /*! * Move a file. Throw exception on failure. */ - static void moveFile (const std::string& from, const std::string& to) - { - Tools::copyFile (from, to); - Tools::unlinkFile (from); - } -#endif - /*! - * Call unlink() on the given file path fpath. If unlinking fails, throw a - * descriptive error based on the errno which was set on unlink's return. - */ - static void unlinkFile (const std::string& fpath) - { - int rtn = unlink (fpath.c_str()); - if (rtn) { - int theError = errno; - std::string emsg; - switch (theError) { - case EPERM: - case EACCES: - emsg = "Write access to '" + fpath + "' is not allowed due to permissions"; - break; - case EBUSY: - emsg = "'" + fpath + "' cannot be removed as it is in use by another process"; - break; - case EFAULT: - emsg = "'" + fpath + "' points outside your accessible address space"; - break; - case EIO: - emsg = "I/O error occurred reading '" + fpath + "'"; - break; - case EISDIR: - emsg = "'" + fpath + "' is a directory"; - break; - case ELOOP: - emsg = "Too many symlinks encountered in '" + fpath + "'"; - break; - case ENAMETOOLONG: - emsg = "'" + fpath + "' is too long a name"; - break; - case ENOENT: - emsg = "'" + fpath + "' does not exist or is a dangling symlink"; - break; - case ENOMEM: - emsg = "In sufficient kernel memory to open '" + fpath + "'"; - break; - case ENOTDIR: - emsg = "'" + fpath + "' contains a component that is not a directory"; - break; - case EROFS: - emsg = "'" + fpath + "' is on a read-only filesystem"; - break; - default: - emsg = "Unknown error unlinking file '" + fpath + "'"; - break; - } - - throw std::runtime_error (emsg); - } - } - -#ifndef __WIN__ - /*! - * Unlink files in dirPath which are older than olerThanSeconds and which - * contain filePart. - */ - static void clearoutDir (const std::string& dirPath, - const unsigned int olderThanSeconds = 0, - const std::string& filePart = "") + void moveFile (const std::string& from, const std::string& to) { - std::vector files; - try { - Tools::readDirectoryTree (files, dirPath, olderThanSeconds); - } catch (const std::exception& e) { - // Failed to read dir tree - return; - } - std::vector::iterator i = files.begin(); - while (i != files.end()) { - std::string fpath = dirPath + "/" + *i; - try { - if (filePart.empty()) { - Tools::unlinkFile (fpath); - } else { - // Must find filePart to unlink - if (i->find (filePart, 0) != std::string::npos) { - Tools::unlinkFile (fpath); - } // else do nothing - } - - } catch (const std::exception& e) { - // Failed to unlink *i - } - ++i; - } + tools::copyFile (from, to); + tools::unlinkFile (from); } /*! @@ -1767,10 +1731,10 @@ namespace morph * If olderThanSeconds is passed in with a non-zero value, then only files older * than olderThanSeconds will be returned. */ - static void readDirectoryTree (std::vector& vec, - const std::string& baseDirPath, - const std::string& subDirPath, - const unsigned int olderThanSeconds = 0) + void readDirectoryTree (std::vector& vec, + const std::string& baseDirPath, + const std::string& subDirPath, + const unsigned int olderThanSeconds = 0) { DIR* d; struct dirent *ep; @@ -1832,8 +1796,7 @@ namespace morph } else { newPath = sd + "/" + ep->d_name; } - Tools::readDirectoryTree (vec, baseDirPath, - newPath.c_str(), olderThanSeconds); + tools::readDirectoryTree (vec, baseDirPath, newPath.c_str(), olderThanSeconds); } else { // Non-directories are simply added to the vector std::string newEntry; @@ -1874,11 +1837,46 @@ namespace morph * If olderThanSeconds is passed in with a non-zero value, then only files older * than olderThanSeconds will be returned. */ - static void readDirectoryTree (std::vector& vec, - const std::string& dirPath, - const unsigned int olderThanSeconds = 0) + void readDirectoryTree (std::vector& vec, + const std::string& dirPath, + const unsigned int olderThanSeconds = 0) { - Tools::readDirectoryTree (vec, dirPath, "", olderThanSeconds); + tools::readDirectoryTree (vec, dirPath, "", olderThanSeconds); + } + + /*! + * Unlink files in dirPath which are older than olerThanSeconds and which + * contain filePart. + */ + void clearoutDir (const std::string& dirPath, + const unsigned int olderThanSeconds = 0, + const std::string& filePart = "") + { + std::vector files; + try { + tools::readDirectoryTree (files, dirPath, olderThanSeconds); + } catch (const std::exception& e) { + // Failed to read dir tree + return; + } + std::vector::iterator i = files.begin(); + while (i != files.end()) { + std::string fpath = dirPath + "/" + *i; + try { + if (filePart.empty()) { + tools::unlinkFile (fpath); + } else { + // Must find filePart to unlink + if (i->find (filePart, 0) != std::string::npos) { + tools::unlinkFile (fpath); + } // else do nothing + } + + } catch (const std::exception& e) { + // Failed to unlink *i + } + ++i; + } } /*! @@ -1895,8 +1893,7 @@ namespace morph * * The set dset would be filled only with dir2, dir1. */ - static void readDirectoryDirs (std::set& dset, - const std::string& dirPath) + void readDirectoryDirs (std::set& dset, const std::string& dirPath) { DIR* d; struct dirent *ep; @@ -1932,9 +1929,9 @@ namespace morph * The base directory path baseDirPath should have NO TRAILING '/'. The * subDirPath should have NO INITIAL '/' character. */ - static void readDirectoryEmptyDirs (std::set& dset, - const std::string& baseDirPath, - const std::string& subDir = "") + void readDirectoryEmptyDirs (std::set& dset, + const std::string& baseDirPath, + const std::string& subDir = "") { DIR* d; struct dirent *ep; @@ -1969,14 +1966,14 @@ namespace morph } else { newSubDir = subDir + "/" + static_cast(ep->d_name); } - Tools::readDirectoryEmptyDirs (dset, baseDirPath, newSubDir); + tools::readDirectoryEmptyDirs (dset, baseDirPath, newSubDir); } } if (levelDirCount == 0) { // No directories found here, check for files std::vector foundfiles; - Tools::readDirectoryTree (foundfiles, dirPath); + tools::readDirectoryTree (foundfiles, dirPath); if (foundfiles.empty()) { dset.insert (subDir); } // else DBG ("NOT adding " << subDir << " as " << dirPath << " contains " << foundfiles.size() << " files"); @@ -1985,21 +1982,6 @@ namespace morph (void) closedir (d); } - /*! - * Attempts to remove all the unused directories in a tree. - * - * May throw exceptions. - */ - static void removeUnusedDirs (std::set& dset, const std::string& dirPath) - { - std::set onepass; - do { - onepass.clear(); - Tools::removeEmptySubDirs (onepass, dirPath); - dset.insert (onepass.begin(), onepass.end()); - } while (!onepass.empty()); - } - /*! * Recursively remove all empty directories in baseDirPath(/subDir) * @@ -2010,9 +1992,9 @@ namespace morph * This does one "pass" - it removes all empty end-of-directories in a tree. If * you want to remove all "unused" directories in a tree, use removeUnusedDirs() */ - static void removeEmptySubDirs (std::set& dset, - const std::string& baseDirPath, - const std::string& subDir = "") + void removeEmptySubDirs (std::set& dset, + const std::string& baseDirPath, + const std::string& subDir = "") { DIR* d; struct dirent *ep; @@ -2047,18 +2029,18 @@ namespace morph } else { newSubDir = subDir + "/" + static_cast(ep->d_name); } - Tools::removeEmptySubDirs (dset, baseDirPath, newSubDir); + tools::removeEmptySubDirs (dset, baseDirPath, newSubDir); } } if (levelDirCount == 0) { // No directories found here, check for files std::vector foundfiles; - Tools::readDirectoryTree (foundfiles, dirPath); + tools::readDirectoryTree (foundfiles, dirPath); if (foundfiles.empty()) { if (!subDir.empty()) { - Tools::removeDir (dirPath); + tools::removeDir (dirPath); dset.insert (subDir); } } // else "NOT Removing " << dirPath << " which contains " << foundfiles.size() << " files"; @@ -2067,10 +2049,25 @@ namespace morph (void) closedir (d); } + /*! + * Attempts to remove all the unused directories in a tree. + * + * May throw exceptions. + */ + void removeUnusedDirs (std::set& dset, const std::string& dirPath) + { + std::set onepass; + do { + onepass.clear(); + tools::removeEmptySubDirs (onepass, dirPath); + dset.insert (onepass.begin(), onepass.end()); + } while (!onepass.empty()); + } + /*! * Return a datestamp - st_mtime; the file modification time for the given file. */ - static std::string fileModDatestamp (const std::string& filename) + std::string fileModDatestamp (const std::string& filename) { struct stat * buf = NULL; std::stringstream datestamp; @@ -2092,9 +2089,9 @@ namespace morph /*! * Check whether the specified files differ. */ - static bool filesDiffer (const std::string& first, const std::string& second) + bool filesDiffer (const std::string& first, const std::string& second) { - if (!(Tools::regfileExists (first) && Tools::regfileExists (second))) { + if (!(tools::regfileExists (first) && tools::regfileExists (second))) { throw std::runtime_error ("Error: expecting two regular files"); } std::string diffcmd = "diff " + first + " " + second + " >/dev/null 2>&1"; @@ -2107,7 +2104,7 @@ namespace morph * Given a path like /path/to/file in str, remove all the preceding /path/to/ * stuff to leave just the filename. */ - static void stripUnixPath (std::string& unixPath) + void stripUnixPath (std::string& unixPath) { std::string::size_type pos (unixPath.find_last_of ('/')); if (pos != std::string::npos) { unixPath = unixPath.substr (++pos); } @@ -2117,7 +2114,7 @@ namespace morph * Given a path like /path/to/file in str, remove the final filename, leaving * just the path, "/path/to". */ - static void stripUnixFile (std::string& unixPath) + void stripUnixFile (std::string& unixPath) { std::string::size_type pos (unixPath.find_last_of ('/')); if (pos != std::string::npos) { unixPath = unixPath.substr (0, pos); } @@ -2128,12 +2125,12 @@ namespace morph * of a pair of strings, returning the filename as the second element. The * unixPath could then be reconstructed as rt.first + string("/") + rtn.second. */ - static std::pair getUnixPathAndFile (const std::string& unixPath) + std::pair getUnixPathAndFile (const std::string& unixPath) { std::string fpath(unixPath); std::string fname(unixPath); - morph::Tools::stripUnixFile (fpath); - morph::Tools::stripUnixPath (fname); + morph::tools::stripUnixFile (fpath); + morph::tools::stripUnixPath (fname); return std::make_pair (fpath, fname); } @@ -2141,7 +2138,7 @@ namespace morph * Given a path like /path/to/file.ext or just file.ext in str, remove the file * suffix. */ - static void stripFileSuffix (std::string& unixPath) + void stripFileSuffix (std::string& unixPath) { std::string::size_type pos (unixPath.rfind('.')); if (pos != std::string::npos) { @@ -2161,7 +2158,7 @@ namespace morph /*! * Return the current year. */ - static unsigned int yearNow() + unsigned int yearNow() { time_t curtime; // Current time struct tm* t; @@ -2174,7 +2171,7 @@ namespace morph /*! * Return the current month (1==Jan, 12==Dec). */ - static unsigned int monthNow() + unsigned int monthNow() { time_t curtime; // Current time struct tm* t; @@ -2187,7 +2184,7 @@ namespace morph /*! * Return the current 'day of month' (the tm_mday field of a struct tm). */ - static unsigned int dateNow() + unsigned int dateNow() { time_t curtime; // Current time struct tm* t; @@ -2202,7 +2199,7 @@ namespace morph * string. If shortFormat is true, return "Jan", "Dec", etc., otherwise * "January", "December" etc. */ - static std::string monthStr (const int month, const bool shortFormat=false) + std::string monthStr (const int month, const bool shortFormat=false) { std::string rtn(""); @@ -2299,7 +2296,7 @@ namespace morph * Give the number n, return the suitable (english) suffix. E.g. "st" for 1, * "nd" for 22 etc. */ - static std::string suffix (const int n) + std::string suffix (const int n) { std::string suf("th"); // Most numbers end in "th" (in English) int leastSig = n%10; // Right most, least significant numeral @@ -2334,7 +2331,7 @@ namespace morph * as the separator. If the fifth character IS a numeral, then the date format * is read in as YYYYMMDD. */ - static time_t dateToNum (const std::string& dateStr) + time_t dateToNum (const std::string& dateStr) { char separator = '\0'; @@ -2420,7 +2417,7 @@ namespace morph * * The 3rd char after the space is read in and used as time separator */ - static time_t dateTimeToNum (const std::string& dateTimeStr) + time_t dateTimeToNum (const std::string& dateTimeStr) { char dateSeparator = '\0'; char timeSeparator = '\0'; @@ -2523,10 +2520,10 @@ namespace morph * Convert a unix epoch number to a date/time of form 2009-02-16 02:03:01, using * dateSeparator to delimit the date and timeSeparator to delimit the time. */ - static std::string numToDateTime (const time_t epochSeconds, - const char dateSeparator = '\0', - const char timeSeparator = '\0', - const char midSeparator = ' ') + std::string numToDateTime (const time_t epochSeconds, + const char dateSeparator = '\0', + const char timeSeparator = '\0', + const char midSeparator = ' ') { if (epochSeconds == 0) { return "unknown"; } @@ -2578,7 +2575,7 @@ namespace morph * Convert a unix epoch number to a date of form 2009-02-16, using separator to * delimit the date. */ - static std::string numToDate (const time_t epochSeconds, const char separator = '\0') + std::string numToDate (const time_t epochSeconds, const char separator = '\0') { time_t es = epochSeconds; struct tm* t = static_cast(malloc (sizeof (struct tm))); @@ -2617,7 +2614,7 @@ namespace morph /*! * Return the current time in neat string format. */ - static std::string timeNow() + std::string timeNow() { time_t curtime; struct tm* loctime; @@ -2631,9 +2628,9 @@ namespace morph * part of a filename. */ #ifndef __WIN__ - static std::string filenameTimestamp() + std::string filenameTimestamp() { - return morph::Tools::numToDateTime (time(NULL), '\0', '\0', '_'); + return morph::tools::numToDateTime (time(NULL), '\0', '\0', '_'); } #endif /*! @@ -2650,144 +2647,132 @@ namespace morph * used to escape the enclosure chars. */ template - static std::vector splitStringWithEncs (const ST& s, - const ST& separatorChars = ST(";, "), - const ST& enclosureChars = ST("\"'"), - const typename ST::value_type& escapeChar = typename ST::value_type(0)); + std::vector splitStringWithEncs (const ST& s, + const ST& separatorChars = ST(";, "), + const ST& enclosureChars = ST("\"'"), + const typename ST::value_type& escapeChar = typename ST::value_type(0)) + { + // Run through the string, searching for separator and + // enclosure chars and finding tokens based on those. + + std::vector theVec; + ST entry(""); + typename ST::size_type a=0, b=0, c=0; + ST sepsAndEncsAndEsc = separatorChars + enclosureChars; + sepsAndEncsAndEsc += escapeChar; + + typename ST::size_type sz = s.size(); + while (a < sz) { + + // If true, then the thing we're searching for is an enclosure + // char, otherwise, it's a separator char. + bool nextIsEnc(false); + typename ST::value_type currentEncChar = 0; + + if (a == 0) { // First field. + if (escapeChar && s[a] == escapeChar) { + // First char is an escape char - skip this and next + ++a; ++a; + continue; + } else if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { + // First char is an enclosure char. + nextIsEnc = true; + currentEncChar = s[a]; + ++a; // Skip the enclosure char + } else if ((separatorChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { + // First char is a ',' This special case means that we insert an entry for the current ',' and step past it. + theVec.push_back (""); + ++a; - }; // class Tools + } // else first char is a normal char or a separator. -} // morph namespace + } else { // Not first field -/*! - * Templated function splitStringWithEncs implementation. - */ -template -std::vector -morph::Tools::splitStringWithEncs (const ST& s, - const ST& separatorChars, - const ST& enclosureChars, - const typename ST::value_type& escapeChar) // or '\0' -{ - // Run through the string, searching for separator and - // enclosure chars and finding tokens based on those. - - std::vector theVec; - ST entry(""); - typename ST::size_type a=0, b=0, c=0; - ST sepsAndEncsAndEsc = separatorChars + enclosureChars; - sepsAndEncsAndEsc += escapeChar; - - typename ST::size_type sz = s.size(); - while (a < sz) { - - // If true, then the thing we're searching for is an enclosure - // char, otherwise, it's a separator char. - bool nextIsEnc(false); - typename ST::value_type currentEncChar = 0; - - if (a == 0) { // First field. - if (escapeChar && s[a] == escapeChar) { - // First char is an escape char - skip this and next - ++a; ++a; - continue; - } else if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { - // First char is an enclosure char. - nextIsEnc = true; - currentEncChar = s[a]; - ++a; // Skip the enclosure char - } else if ((separatorChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { - // First char is a ',' This special case means that we insert an entry for the current ',' and step past it. - theVec.push_back (""); - ++a; - - } // else first char is a normal char or a separator. - - } else { // Not first field - - if ((a = s.find_first_of (sepsAndEncsAndEsc, a)) == ST::npos) { - theVec.push_back (s); - return theVec; - } - - else if (escapeChar && s[a] == escapeChar) { - // it's an escape char - skip this and next - ++a; ++a; - continue; - } else if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { - // it's an enclosure char. - nextIsEnc = true; - currentEncChar = s[a]; - ++a; // Skip the enclosure char - } else if ((separatorChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { - // It's a field separator - ++a; // Skip the separator - if (a >= sz) { - // Special case - a trailing separator character - add an empty - // value to the return vector of tokens. - theVec.push_back (""); - } else { - // a < sz, so now check if we've hit an escape char - if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { - // Enclosure char following sep char + if ((a = s.find_first_of (sepsAndEncsAndEsc, a)) == ST::npos) { + theVec.push_back (s); + return theVec; + } + + else if (escapeChar && s[a] == escapeChar) { + // it's an escape char - skip this and next + ++a; ++a; + continue; + } else if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { + // it's an enclosure char. nextIsEnc = true; currentEncChar = s[a]; ++a; // Skip the enclosure char - } + } else if ((separatorChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { + // It's a field separator + ++a; // Skip the separator + if (a >= sz) { + // Special case - a trailing separator character - add an empty + // value to the return vector of tokens. + theVec.push_back (""); + } else { + // a < sz, so now check if we've hit an escape char + if ((enclosureChars.find_first_of (static_cast(s[a]), 0)) != ST::npos) { + // Enclosure char following sep char + nextIsEnc = true; + currentEncChar = s[a]; + ++a; // Skip the enclosure char + } + } + } // else unexpected case. } - } // else unexpected case. - } - - // Check we didn't over-run - if (a >= sz) { break; } - - // Now get the token - typename ST::size_type range = ST::npos; - if (nextIsEnc) { - c = a; - while ((b = s.find_first_of (currentEncChar, c)) != ST::npos) { - // FIXME: Check we didn't find an escaped enclosureChar. - if (escapeChar) { - c = b; --c; - if (s[c] == escapeChar) { - // Skip b which is an escaped enclosure char - c = b; ++c; - continue; + + // Check we didn't over-run + if (a >= sz) { break; } + + // Now get the token + typename ST::size_type range = ST::npos; + if (nextIsEnc) { + c = a; + while ((b = s.find_first_of (currentEncChar, c)) != ST::npos) { + // FIXME: Check we didn't find an escaped enclosureChar. + if (escapeChar) { + c = b; --c; + if (s[c] == escapeChar) { + // Skip b which is an escaped enclosure char + c = b; ++c; + continue; + } + } + range = b - a; + break; } - } - range = b - a; - break; - } - } else { - if ((b = s.find_first_of (separatorChars, a)) != ST::npos) { - // Check it wasn't an escaped separator: - if (escapeChar) { - c = b; --c; - if (c >= 0 && c != ST::npos && c < sz && s[c] == escapeChar) { - c = b; ++c; - continue; + } else { + if ((b = s.find_first_of (separatorChars, a)) != ST::npos) { + // Check it wasn't an escaped separator: + if (escapeChar) { + c = b; --c; + if (c >= 0 && c != ST::npos && c < sz && s[c] == escapeChar) { + c = b; ++c; + continue; + } + } + range = b - a; } } - range = b - a; - } - } - entry = s.substr (a, range); - Tools::stripChars (entry, escapeChar); - theVec.push_back (entry); + entry = s.substr (a, range); + tools::stripChars (entry, escapeChar); + theVec.push_back (entry); - if (range != ST::npos) { // end of field was not end of string - if (nextIsEnc) { - a += range + 1; // +1 to take us past the closing enclosure. - } else { - // in new scheme, we want to find the separator, so this places us ON the separator. - a += range; + if (range != ST::npos) { // end of field was not end of string + if (nextIsEnc) { + a += range + 1; // +1 to take us past the closing enclosure. + } else { + // in new scheme, we want to find the separator, so this places us ON the separator. + a += range; + } + } else { + a = range; + } } - } else { - a = range; - } - } - return theVec; -} + return theVec; + } + } // namespace tools +} // namespace morph diff --git a/standalone_examples/neuralnet/ff_xor.cpp b/standalone_examples/neuralnet/ff_xor.cpp index e1e637e4..2613c88f 100644 --- a/standalone_examples/neuralnet/ff_xor.cpp +++ b/standalone_examples/neuralnet/ff_xor.cpp @@ -91,8 +91,8 @@ int main (int argc, char** argv) unsigned int framenum = 0; // Create a directory to save PNG images - if (morph::Tools::dirExists ("./logs") == false) { - morph::Tools::createDir ("./logs"); + if (morph::tools::dirExists ("./logs") == false) { + morph::tools::createDir ("./logs"); } for (unsigned int ep = 0; ep < epochs; ++ep) { diff --git a/standalone_examples/schnakenberg/schnakenberg.cpp b/standalone_examples/schnakenberg/schnakenberg.cpp index 15d1ae0a..8f00a318 100644 --- a/standalone_examples/schnakenberg/schnakenberg.cpp +++ b/standalone_examples/schnakenberg/schnakenberg.cpp @@ -106,9 +106,9 @@ int main (int argc, char **argv) // Using json filename as logpath std::string justfile = paramsfile; // Remove trailing .json and leading directories - std::vector pth = morph::Tools::stringToVector (justfile, "/"); + std::vector pth = morph::tools::stringToVector (justfile, "/"); justfile = pth.back(); - morph::Tools::searchReplace (".json", "", justfile); + morph::tools::searchReplace (".json", "", justfile); // Use logbase as the subdirectory into which this should go logbase = conf.getString ("logbase", "logs/"); if (logbase.back() != '/') { @@ -212,9 +212,9 @@ int main (int argc, char **argv) * Now create a log directory if necessary, and exit on any * failures. */ - if (morph::Tools::dirExists (logpath) == false) { - morph::Tools::createDir (logpath); - if (morph::Tools::dirExists (logpath) == false) { + if (morph::tools::dirExists (logpath) == false) { + morph::tools::createDir (logpath); + if (morph::tools::dirExists (logpath) == false) { std::cerr << "Failed to create the logpath directory " << logpath << " which does not exist."<< std::endl; return 1; @@ -223,8 +223,8 @@ int main (int argc, char **argv) // Directory DOES exist. See if it contains a previous run and // exit without overwriting to avoid confusion. if (overwrite_logs == false - && (morph::Tools::fileExists (logpath + "/params.json") == true - || morph::Tools::fileExists (logpath + "/positions.h5") == true)) { + && (morph::tools::fileExists (logpath + "/params.json") == true + || morph::tools::fileExists (logpath + "/positions.h5") == true)) { std::cerr << "Seems like a previous simulation was logged in " << logpath << ".\n" << "Please clean it out manually, choose another directory or set\n" << "overwrite_logs to true in your parameters config JSON file." << std::endl; @@ -330,7 +330,7 @@ int main (int argc, char **argv) // results were computed with single precision, if 8, then double // precision was used. Also save various parameters from the RD system. conf.set ("float_width", (unsigned int)sizeof(FLT)); - std::string tnow = morph::Tools::timeNow(); + std::string tnow = morph::tools::timeNow(); conf.set ("sim_ran_at_time", tnow.substr(0,tnow.size()-1)); conf.set ("hextohex_d", RD.hextohex_d); conf.set ("D_A", RD.D_A); diff --git a/standalone_examples/template/model.cpp b/standalone_examples/template/model.cpp index bbcc64b0..04b612fe 100644 --- a/standalone_examples/template/model.cpp +++ b/standalone_examples/template/model.cpp @@ -47,7 +47,7 @@ int main(int argc, char **argv) // setup the log file std::string logpath = argv[2]; std::ofstream logfile; - morph::Tools::createDir (logpath); + morph::tools::createDir (logpath); { std::stringstream ss; ss << logpath << "/log.txt"; logfile.open(ss.str()); } logfile << "Hello world!" << std::endl; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2ea05c45..a14c80d6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -517,7 +517,7 @@ if(ARMADILLO_FOUND) endif() -# morph::Tools +# morph::tools add_executable(testTools testTools.cpp) add_test(testTools testTools) diff --git a/tests/testDirichlet.cpp b/tests/testDirichlet.cpp index 155a0150..7d6f042b 100644 --- a/tests/testDirichlet.cpp +++ b/tests/testDirichlet.cpp @@ -161,7 +161,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testDirichlet2.cpp b/tests/testDirichlet2.cpp index 56d16c7d..c81a8b27 100644 --- a/tests/testDirichlet2.cpp +++ b/tests/testDirichlet2.cpp @@ -174,7 +174,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testDirichlet4.cpp b/tests/testDirichlet4.cpp index cf30e71f..0ae55650 100644 --- a/tests/testDirichlet4.cpp +++ b/tests/testDirichlet4.cpp @@ -172,7 +172,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testDirichlet5.cpp b/tests/testDirichlet5.cpp index 6c84355c..6110efae 100644 --- a/tests/testDirichlet5.cpp +++ b/tests/testDirichlet5.cpp @@ -170,7 +170,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testTools.cpp b/tests/testTools.cpp index 9a81cf69..5a286a54 100644 --- a/tests/testTools.cpp +++ b/tests/testTools.cpp @@ -1,8 +1,8 @@ -// Test a few morph::Tools functions +// Test a few morph::tools functions #include "morph/tools.h" int main() { - std::cout << "pwd: " << morph::Tools::getPwd() << std::endl; + std::cout << "pwd: " << morph::tools::getPwd() << std::endl; return 0; } diff --git a/tests/test_circleboundary.cpp b/tests/test_circleboundary.cpp index b9fe9ea4..a0fbb7dd 100644 --- a/tests/test_circleboundary.cpp +++ b/tests/test_circleboundary.cpp @@ -58,7 +58,7 @@ int main (int argc, char** argv) } catch (const std::exception& e) { std::cerr << "Caught exception reading svg: " << e.what() << std::endl; - std::cerr << "Current working directory: " << morph::Tools::getPwd() << std::endl; + std::cerr << "Current working directory: " << morph::tools::getPwd() << std::endl; rtn = -1; } diff --git a/tests/test_ellipseboundary.cpp b/tests/test_ellipseboundary.cpp index 450cc763..4b7ee7cb 100644 --- a/tests/test_ellipseboundary.cpp +++ b/tests/test_ellipseboundary.cpp @@ -58,7 +58,7 @@ int main (int argc, char** argv) } catch (const std::exception& e) { std::cerr << "Caught exception reading svg: " << e.what() << std::endl; - std::cerr << "Current working directory: " << morph::Tools::getPwd() << std::endl; + std::cerr << "Current working directory: " << morph::tools::getPwd() << std::endl; rtn = -1; } diff --git a/tests/testbighexgrid.cpp b/tests/testbighexgrid.cpp index 72c0120c..7e957fef 100644 --- a/tests/testbighexgrid.cpp +++ b/tests/testbighexgrid.cpp @@ -57,7 +57,7 @@ int main() } catch (const std::exception& e) { std::cerr << "Caught exception reading trial.svg: " << e.what() << std::endl; - std::cerr << "Current working directory: " << morph::Tools::getPwd() << std::endl; + std::cerr << "Current working directory: " << morph::tools::getPwd() << std::endl; rtn = -1; } diff --git a/tests/testdirs.cpp b/tests/testdirs.cpp index 1afba1b1..fa034dc0 100644 --- a/tests/testdirs.cpp +++ b/tests/testdirs.cpp @@ -8,8 +8,8 @@ int main() int rtn = -2; morph::RandString rs(8); std::string dpath = "testdir" + rs.get(); - morph::Tools::createDir (dpath); - if (morph::Tools::dirExists (dpath)) { + morph::tools::createDir (dpath); + if (morph::tools::dirExists (dpath)) { std::cout << "Created directory " << dpath << " successfully.\n"; rtn = 0; } else { diff --git a/tests/testhexbounddist.cpp b/tests/testhexbounddist.cpp index b9a0e1b0..7b8f2150 100644 --- a/tests/testhexbounddist.cpp +++ b/tests/testhexbounddist.cpp @@ -14,7 +14,7 @@ int main() { int rtn = 0; try { - string pwd = Tools::getPwd(); + string pwd = tools::getPwd(); string curvepath = "../../tests/trial.svg"; ReadCurves r(curvepath); @@ -38,7 +38,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception reading trial.svg: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testhexgrid2.cpp b/tests/testhexgrid2.cpp index f7553b79..f6b92b6b 100644 --- a/tests/testhexgrid2.cpp +++ b/tests/testhexgrid2.cpp @@ -10,7 +10,7 @@ int main() { int rtn = 0; try { - string pwd = Tools::getPwd(); + string pwd = tools::getPwd(); // Assumes were in the build dir and that the build dir is within the // morphologica directory. string curvepath = "../../tests/trial.svg"; @@ -30,7 +30,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception reading trial.svg: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn; diff --git a/tests/testhexgrid3.cpp b/tests/testhexgrid3.cpp index 6bbb8cd4..3f5b8bc8 100644 --- a/tests/testhexgrid3.cpp +++ b/tests/testhexgrid3.cpp @@ -12,7 +12,7 @@ int main() { int rtn = 0; try { - std::string pwd = morph::Tools::getPwd(); + std::string pwd = morph::tools::getPwd(); std::string curvepath = "../../tests/trialmod.svg"; morph::ReadCurves r(curvepath); @@ -74,7 +74,7 @@ int main() } catch (const std::exception& e) { std::cerr << "Caught exception reading svg: " << e.what() << std::endl; - std::cerr << "Current working directory: " << morph::Tools::getPwd() << std::endl; + std::cerr << "Current working directory: " << morph::tools::getPwd() << std::endl; rtn = -1; } diff --git a/tests/testhexgridsave.cpp b/tests/testhexgridsave.cpp index 69dacb0e..a7bbc40b 100644 --- a/tests/testhexgridsave.cpp +++ b/tests/testhexgridsave.cpp @@ -18,10 +18,10 @@ int main() int rtn = 0; unsigned int hexnum = 0; - cout << "Start " << Tools::timeNow() << endl; + cout << "Start " << tools::timeNow() << endl; // Create and then write a HexGrid try { - string pwd = Tools::getPwd(); + string pwd = tools::getPwd(); string curvepath = "../../tests/trial.svg"; ReadCurves r(curvepath); @@ -39,15 +39,15 @@ int main() } catch (const exception& e) { cerr << "Caught exception reading trial.svg: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } - cout << "Generated " << Tools::timeNow() << endl; + cout << "Generated " << tools::timeNow() << endl; // Now read it back try { HexGrid hg("../trialhexgrid.h5"); - cout << "Read " << Tools::timeNow() << endl; + cout << "Read " << tools::timeNow() << endl; // Make sure read-in grid has same number of hexes as the generated one. if (hexnum != hg.num()) { rtn = -1; } @@ -100,7 +100,7 @@ int main() } catch (const exception& e) { cerr << "Caught exception reading trial.svg: " << e.what() << endl; - cerr << "Current working directory: " << Tools::getPwd() << endl; + cerr << "Current working directory: " << tools::getPwd() << endl; rtn = -1; } return rtn;