Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a814122
added ParamFile.cpp and ParamFile.hpp as a faster, type-safe file str…
ozmorph May 23, 2020
d10e19e
replaced many invocations of GetInputParameter() and GetInputParamete…
ozmorph May 23, 2020
859a031
replaced std::not1() macro with lambda for clarity; replaced 'default…
ozmorph May 27, 2020
e9530ae
fixed bug in ParamFile.cpp when a newer key-value overrides a pair fr…
ozmorph May 27, 2020
cd28527
added extract_multiple and extract_multiple_or_exit functions to Para…
ozmorph May 28, 2020
6bc11be
deduplicating code in ParamFile.cpp
ozmorph May 28, 2020
1f78c6e
added class documentation to ParamFile.hpp
ozmorph May 28, 2020
47f3c77
added ParamFile.cpp and ParamFile.hpp to Visual Studio project
ozmorph Jun 1, 2020
be1028e
added extract_multiple_strings_or_exit() and extract_string_matrix_or…
ozmorph Jun 4, 2020
3d11048
added extract_multiple_no_default() function
ozmorph Jun 4, 2020
1447303
added cond_extract_multiple() to ParamFile.(c/h)pp which allows the u…
ozmorph Jun 5, 2020
edbe277
added code that enables ParamReader::parse_param_file to handle multi…
ozmorph Jun 10, 2020
9b1163b
fix for CentOS 7 which uses libstd++ with a non-C++11 ABI
ozmorph Jun 10, 2020
e4fce45
fixed error with std::istringstream's error bits not being cleared be…
ozmorph Jun 10, 2020
6964704
updated cidf parameter reading with params.extract_multiple_no_default()
ozmorph Jun 11, 2020
cd51708
fix for CentOS 7 which doesn't allow auto parameters in lambda expres…
ozmorph Jun 11, 2020
6ad08e0
added missing documentation to ParamFile.hpp functions
ozmorph Jun 16, 2020
7eebd71
converted many of the remaining GetInputParameter2() calls to params.…
ozmorph Jun 22, 2020
9daad3d
renamed ParamFile.hpp to ParamFile.h; updated CMakeLists and vcxproj …
ozmorph Jun 25, 2020
ea744d4
removed inline keyword from string trim functions in ParamFile.cpp
ozmorph Jun 25, 2020
4787c28
converted ParamFile.cpp and ParamFile.h to use tabs instead of spaces
ozmorph Jun 25, 2020
65d5d31
use Allman braces everywhere in ParamFile.cpp and ParamFile.h
ozmorph Jun 25, 2020
945c9fb
refactored parse_*() functions from CLI.h/.cpp into Parsers.h/.cpp to…
ozmorph Jun 25, 2020
9cc1960
large commit; added parse_*_no_default(), parse_*(), and parse_*_or_e…
ozmorph Jul 1, 2020
20d1dea
updates to logging within ParamFile.cpp; replaced ERR_CRITICAL_FMT wi…
ozmorph Jul 1, 2020
382b0c6
centos7 fix: added missing <cstdint> and <stdexcept> includes that br…
ozmorph Jul 6, 2020
6dadc5e
added extract_inverse_cdf() to ParamFile; moved ICDF_START constant f…
ozmorph Jul 6, 2020
8bc6c4f
removed GetInputParameter2all()
ozmorph Jul 6, 2020
edc7c19
updated header guards for ParamFile.h to reflect file name change
ozmorph Jul 6, 2020
4f95992
changed m_param_value_map to param_value_map_ to match naming convent…
ozmorph Jul 6, 2020
2290c63
changed global variable Param P in CovidSim.cpp to be value initializ…
ozmorph Jul 6, 2020
ce920d7
removed unnecessary zero initialization code in ReadParams()
ozmorph Jul 6, 2020
29a0702
added parse_bool* functions to Parsers.cpp to parse boolean values fr…
ozmorph Jul 6, 2020
5505cdd
added extract_bool() function to ParamFile.cpp to explicitly extract …
ozmorph Jul 6, 2020
4cd99a8
converted many occurrences of int variables in the Param structure th…
ozmorph Jul 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions covid-sim.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<ClCompile Include="src\Error.cpp" />
<ClCompile Include="src\Kernels.cpp" />
<ClCompile Include="src\Memory.cpp" />
<ClCompile Include="src\ParamFile.cpp" />
<ClCompile Include="src\Parsers.cpp" />
<ClCompile Include="src\Rand.cpp" />
<ClCompile Include="src\SetupModel.cpp" />
<ClCompile Include="src\CovidSim.cpp" />
Expand All @@ -123,6 +125,8 @@
<ClInclude Include="src\Model.h" />
<ClInclude Include="src\ModelMacros.h" />
<ClInclude Include="src\Param.h" />
<ClInclude Include="src\ParamFile.h" />
<ClInclude Include="src\Parsers.h" />
<ClInclude Include="src\Rand.h" />
<ClInclude Include="src\SetupModel.h" />
<ClInclude Include="src\CovidSim.h" />
Expand Down
85 changes: 7 additions & 78 deletions src/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,7 @@
#include "CLI.h"
#include "Error.h"
#include "Param.h"

void parse_string(std::string const& input, std::string& output)
{
output = input;
}

void parse_read_file(std::string const& input, std::string& output)
{
// check to see if the file exists and error out if it doesn't
if (static_cast<bool>(std::ifstream(input)) == false)
{
ERR_CRITICAL_FMT("%s is not a file\n", input.c_str());
}
output = input;
}

void parse_write_dir(std::string const& input, std::string& output)
{
// check to see if this prefix already exists as a file and error out
if (static_cast<bool>(std::ifstream(input)) == true)
{
ERR_CRITICAL_FMT("Cannot use this prefix, this path already exists"
" as a file: %s\n", input.c_str());
}
// TODO: add a platform-independent check to see if the prefix could
// be added as a directory or file
output = input;
}

void parse_integer(std::string const& input, int& output)
{
try
{
std::size_t pos;
output = std::stoi(input, &pos);
if (pos != input.size())
{
ERR_CRITICAL_FMT("Detected invalid characters after parsed integer: %s\n", input.c_str());
}
}
catch (const std::invalid_argument& e)
{
ERR_CRITICAL_FMT("EINVAL: Expected integer got %s\n", input.c_str());
}
catch (const std::out_of_range& e)
{
ERR_CRITICAL_FMT("ERANGE: Input integer is out of range. Expected %d to %d. Got %s\n",
std::numeric_limits<int>::min(), std::numeric_limits<int>::max(), input.c_str());
}
}

void parse_double(std::string const& input, double& output)
{
try
{
std::size_t pos;
output = std::stod(input, &pos);
if (pos != input.size())
{
ERR_CRITICAL_FMT("Detected invalid characters after parsed double: %s\n", input.c_str());
}
}
catch (const std::invalid_argument& e)
{
ERR_CRITICAL_FMT("EINVAL: Expected double got %s\n", input.c_str());
}
catch (const std::out_of_range& e)
{
ERR_CRITICAL_FMT("ERANGE: Input integer is out of range. Expected %.4e to %.4e. Got %s\n",
std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), input.c_str());
}
}
#include "Parsers.h"

void CmdLineArgs::add_custom_option(std::string const& option, ParserFn func, std::string const& doc)
{
Expand All @@ -94,12 +23,12 @@ void CmdLineArgs::add_custom_option(std::string const& option, ParserFn func, st

void CmdLineArgs::add_double_option(std::string const& option, double& output, std::string const& doc)
{
add_custom_option(option, std::bind(parse_double, std::placeholders::_1, std::ref(output)), doc);
add_custom_option(option, std::bind(parse_double_or_exit, std::placeholders::_1, std::ref(output)), doc);
}

void CmdLineArgs::add_integer_option(std::string const& option, int& output, std::string const& doc)
{
add_custom_option(option, std::bind(parse_integer, std::placeholders::_1, std::ref(output)), doc);
add_custom_option(option, std::bind(parse_integer_or_exit, std::placeholders::_1, std::ref(output)), doc);
}

void CmdLineArgs::add_string_option(std::string const& option, StringParserFn func, std::string& output, std::string const& doc)
Expand Down Expand Up @@ -127,10 +56,10 @@ void CmdLineArgs::parse(int argc, char* argv[], Param& P)

// Get seeds.
int i = argc - 4;
parse_integer(argv[i], P.setupSeed1);
parse_integer(argv[i+1], P.setupSeed2);
parse_integer(argv[i+2], P.runSeed1);
parse_integer(argv[i+3], P.runSeed2);
parse_integer_or_exit(argv[i], P.setupSeed1);
parse_integer_or_exit(argv[i+1], P.setupSeed2);
parse_integer_or_exit(argv[i+2], P.runSeed1);
parse_integer_or_exit(argv[i+3], P.runSeed2);

for (i = 1; i < argc - 4; i++)
{
Expand Down
29 changes: 0 additions & 29 deletions src/CLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,6 @@
// only a forward-declartion, no need to pull in all of Param.h in this header
struct Param;

// The parse_* functions are kept outside of the CmdLineArgs class because they
// can be used to parse any string input and are not specific to CLI arguments.
// e.g. they may eventually be useful for parsing from the (pre)param files

/**
* Parses and checks if the input string is a readable file on-disk.
*/
void parse_read_file(std::string const& input, std::string& output);

/**
* Parses and checks if the input string is a writable directory.
*/
void parse_write_dir(std::string const& input, std::string& output);

/**
* handles general string.
*/
void parse_string(std::string const& input, std::string& output);

/**
* Parses and checks if the input string is an integer.
*/
void parse_integer(std::string const& input, int& output);

/**
* Parses and checks if the input string is an double.
*/
void parse_double(std::string const& input, double& output);

class CmdLineArgs {
public:
// Function prototype for a generic parser function
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Set up the IDE
set(MAIN_SRC_FILES CovidSim.cpp BinIO.cpp Rand.cpp Error.cpp Dist.cpp
Kernels.cpp Bitmap.cpp SetupModel.cpp CalcInfSusc.cpp Sweep.cpp Update.cpp
Param.cpp Direction.cpp InverseCdf.cpp Memory.cpp CLI.cpp)
Param.cpp Direction.cpp InverseCdf.cpp Memory.cpp CLI.cpp ParamFile.cpp
Parsers.cpp)
set(MAIN_HDR_FILES CovidSim.h BinIO.h Rand.h Constants.h Country.h Error.h
Dist.h Kernels.h Bitmap.h Model.h Param.h SetupModel.h ModelMacros.h
InfStat.h CalcInfSusc.h Sweep.h Update.h MicroCellPosition.hpp Direction.hpp
InverseCdf.h Memory.h CLI.h)
InverseCdf.h Memory.h CLI.h ParamFile.h Parsers.h)
source_group(covidsim\\main FILES ${MAIN_SRC_FILES} ${MAIN_HDR_FILES})

# CovidSim target
Expand Down
Loading