Skip to content

Commit

Permalink
Merge pull request #291 from ABRG-Models/dev/tools_class_to_namespace
Browse files Browse the repository at this point in the history
morph::Tools refactor
  • Loading branch information
sebjameswml authored Nov 26, 2024
2 parents f05dfa7 + 7b4a515 commit 4855bdf
Show file tree
Hide file tree
Showing 37 changed files with 490 additions and 507 deletions.
6 changes: 3 additions & 3 deletions buildtools/process_colourmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string> tokens = morph::Tools::stringToVector (line, (commas ? "," : " "));
std::vector<std::string> 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;
Expand Down
14 changes: 7 additions & 7 deletions buildtools/process_colourtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -35,7 +35,7 @@ int main ()
std::vector<std::string> 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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<std::string> tokens = morph::Tools::stringToVector (line, (commas ? "," : " "));
std::vector<std::string> 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;
Expand Down
12 changes: 6 additions & 6 deletions examples/Ermentrout2009/erm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions examples/LotkaVolterra/lv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> pth = morph::Tools::stringToVector (justfile, "/");
std::vector<std::string> 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 += '/'; }
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SimpsonGoodhill/sg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 8 additions & 9 deletions examples/schnakenberg/schnak_whisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> pth = Tools::stringToVector (justfile, "/");
vector<string> 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() != '/') {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 8 additions & 9 deletions examples/schnakenberg/schnakenberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> pth = Tools::stringToVector (justfile, "/");
vector<string> 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() != '/') {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion morph/ColourMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion morph/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> co = morph::Tools::stringToVector (arg_ss, std::string("="));
std::vector<std::string> 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
Expand Down
2 changes: 1 addition & 1 deletion morph/HdfData.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ namespace morph {
*/
void process_groups (const char* path)
{
std::vector<std::string> pbits = morph::Tools::stringToVector (path, "/");
std::vector<std::string> 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("");
Expand Down
2 changes: 1 addition & 1 deletion morph/RD_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion morph/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <morph/Random.h>
Expand Down
20 changes: 10 additions & 10 deletions morph/ReadCurves.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<float> v = this->splitSvgCmdString (lCmd, cmd, 10000, p3);
Expand All @@ -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<float> v = this->splitSvgCmdString (lCmd, cmd, 10000, p3);
Expand All @@ -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<float> v = this->splitSvgCmdString (lCmd, cmd, 10000, p3);
Expand Down Expand Up @@ -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<float> v = this->splitSvgCmdString (mCmd, cmd, 10000, p3);
Expand Down Expand Up @@ -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<float> v = this->splitSvgCmdString (cCmd, cmd, 6, p3);
Expand Down Expand Up @@ -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<float> v = this->splitSvgCmdString (sCmd, cmd, 4, p3);
Expand Down
2 changes: 1 addition & 1 deletion morph/RecurrentNetworkModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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."<<std::endl;

Expand Down
Loading

0 comments on commit 4855bdf

Please sign in to comment.