Skip to content

Commit

Permalink
Use std::string in rest of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
daljit46 committed Jun 6, 2024
1 parent f42abd5 commit d76e8ad
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 156 deletions.
2 changes: 1 addition & 1 deletion cmd/connectome2tck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace MR::DWI;
using namespace MR::DWI::Tractography;
using namespace MR::DWI::Tractography::Connectome;

const char *file_outputs[] = {"per_edge", "per_node", "single", NULL};
const std::vector<std::string> file_outputs = {"per_edge", "per_node", "single"};

// clang-format off
const OptionGroup TrackOutputOptions = OptionGroup ("Options for determining the content / format of output files")
Expand Down
5 changes: 3 additions & 2 deletions cmd/connectomeedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ using namespace MR::Connectome;
using namespace MR::Math;
using namespace App;

const char *operations[] = {"to_symmetric", "upper_triangular", "lower_triangular", "transpose", "zero_diagonal", NULL};
const std::vector<std::string> operations = {
"to_symmetric", "upper_triangular", "lower_triangular", "transpose", "zero_diagonal"};

// clang-format off
void usage() {
Expand Down Expand Up @@ -73,4 +74,4 @@ void run() {
}

File::Matrix::save_matrix(connectome, output_path);
}
}
2 changes: 1 addition & 1 deletion cmd/connectomestats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using Math::Stats::matrix_type;
using Math::Stats::vector_type;
using Stats::PermTest::count_matrix_type;

const char *algorithms[] = {"nbs", "tfnbs", "none", nullptr};
const std::vector<std::string> algorithms = {"nbs", "tfnbs", "none"};

// TODO Eventually these will move to some kind of TFCE header
#define TFCE_DH_DEFAULT 0.1
Expand Down
2 changes: 1 addition & 1 deletion cmd/dwi2fod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using namespace MR;
using namespace App;

const char *const algorithms[] = {"csd", "msmt_csd", NULL};
const std::vector<std::string> algorithms = {"csd", "msmt_csd"};

// clang-format off
const OptionGroup CommonOptions = OptionGroup ("Options common to more than one algorithm")
Expand Down
5 changes: 2 additions & 3 deletions cmd/dwidenoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
using namespace MR;
using namespace App;

const char *const dtypes[] = {"float32", "float64", NULL};

const char *const estimators[] = {"exp1", "exp2", NULL};
const std::vector<std::string> dtypes = {"float32", "float64"};
const std::vector<std::string> estimators = {"Exp1", "Exp2"};

// clang-format off
void usage() {
Expand Down
27 changes: 13 additions & 14 deletions cmd/fixel2voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ using namespace App;

using Fixel::index_type;

const char *operations[] = {"mean",
"sum",
"product",
"min",
"max",
"absmax",
"magmax",
"count",
"complexity",
"sf",
"dec_unit",
"dec_scaled",
"none",
nullptr};
const std::vector<std::string> operations = {"mean",
"sum",
"product",
"min",
"max",
"absmax",
"magmax",
"count",
"complexity",
"sf",
"dec_unit",
"dec_scaled",
"none"};

// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion cmd/fixelfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace MR;
using namespace App;
using namespace MR::Fixel;

const char *const filters[] = {"connect", "smooth", nullptr};
const std::vector<std::string> filters = {"connect", "smooth"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/labelstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using namespace MR;
using namespace App;

const char *field_choices[] = {"mass", "centre", nullptr};
const std::vector<std::string> field_choices = {"mass", "centre"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/maskfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace App;

#define DEFAULT_CLEAN_SCALE 2

const char *filters[] = {"clean", "connect", "dilate", "erode", "fill", "median", nullptr};
const std::vector<std::string> filters = {"clean", "connect", "dilate", "erode", "fill", "median"};

// clang-format off
const OptionGroup CleanOption =
Expand Down
2 changes: 1 addition & 1 deletion cmd/meshconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace MR;
using namespace App;
using namespace MR::Surface;

const char *transform_choices[] = {"first2real", "real2first", "voxel2real", "real2voxel", "fs2real", nullptr};
const std::vector<std::string> transform_choices = {"first2real", "real2first", "voxel2real", "real2voxel", "fs2real"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/meshfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace MR;
using namespace App;
using namespace MR::Surface;

const char *filters[] = {"smooth", NULL};
const std::vector<std::string> filters = {"smooth"};

// clang-format off
const OptionGroup smooth_option = OptionGroup ("Options for mesh smoothing filter")
Expand Down
20 changes: 9 additions & 11 deletions cmd/mrcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ class LoadedImage {

class StackEntry {
public:
StackEntry(const char *entry) : arg(entry), rng_gaussian(false), image_is_complex(false) {}
StackEntry(std::string entry) : arg(std::move(entry)), rng_gaussian(false), image_is_complex(false) {}

StackEntry(Evaluator *evaluator_p)
: arg(nullptr), evaluator(evaluator_p), rng_gaussian(false), image_is_complex(false) {}

void load() {
if (!arg)
if (arg.empty())
return;
auto search = image_list.find(arg);
if (search != image_list.end()) {
Expand Down Expand Up @@ -530,10 +530,9 @@ class StackEntry {
}
}
}
arg = nullptr;
}

const char *arg;
std::string arg;
std::shared_ptr<Evaluator> evaluator;
std::shared_ptr<Image<complex_type>> image;
copy_ptr<Math::RNG> rng;
Expand Down Expand Up @@ -898,7 +897,7 @@ void run_operations(const std::vector<StackEntry> &stack) {
if (stack.size() > 2)
throw Exception("too many operands left on stack!");

if (!stack[1].arg)
if (stack[1].arg.empty())
throw Exception("output image not specified");

if (stack[0].is_complex()) {
Expand Down Expand Up @@ -984,15 +983,14 @@ class OpTernary : public OpBase {
void run() {
std::vector<StackEntry> stack;

for (int n = 1; n < App::argc; ++n) {

const Option *opt = match_option(App::argv[n]);
for (const auto &argument : App::raw_arguments_list) {
const Option *opt = match_option(argument);
if (opt) {

if (opt->is("datatype"))
++n;
continue;
else if (opt->is("nthreads"))
++n;
continue;
else if (opt->is("force") || opt->is("info") || opt->is("debug") || opt->is("quiet"))
continue;

Expand All @@ -1003,7 +1001,7 @@ void run() {
throw Exception(std::string("operation \"") + opt->id + "\" not yet implemented!");

} else {
stack.push_back(App::argv[n]);
stack.push_back(argument);
}
}

Expand Down
19 changes: 7 additions & 12 deletions cmd/mrcolour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ using namespace MR;
using namespace App;

std::vector<std::string> colourmap_choices_std;
std::vector<const char *> colourmap_choices_cstr;

// clang-format off
void usage() {

const ColourMap::Entry *entry = ColourMap::maps;
do {
if (strcmp(entry->name, "Complex"))
colourmap_choices_std.push_back(lowercase(entry->name));
++entry;
} while(entry->name != nullptr);
colourmap_choices_cstr.reserve(colourmap_choices_std.size() + 1);
for (const auto& s : colourmap_choices_std)
colourmap_choices_cstr.push_back(s.c_str());
colourmap_choices_cstr.push_back(nullptr);
for(const auto& entry : ColourMap::maps) {
const bool is_complex = strcmp(entry.name, "Complex") == 0;
if(is_complex) {
colourmap_choices_std.push_back(entry.name);
}
}

AUTHOR = "Robert E. Smith ([email protected])";

Expand All @@ -67,7 +62,7 @@ void usage() {
ARGUMENTS
+ Argument ("input", "the input image").type_image_in()
+ Argument ("map", "the colourmap to apply;"
" choices are: " + join(colourmap_choices_std, ",")).type_choice (colourmap_choices_cstr.data())
" choices are: " + join(colourmap_choices_std, ",")).type_choice (colourmap_choices_std)
+ Argument ("output", "the output image").type_image_out();

OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrdegibbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using namespace MR;
using namespace App;

const char *modes[] = {"2d", "3d", nullptr};
const std::vector<std::string> modes = {"2d", "3d"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using namespace MR;
using namespace App;

const char *filters[] = {"fft", "gradient", "median", "smooth", "normalise", "zclean", NULL};
const std::vector<std::string> filters = {"fft", "gradient", "median", "smooth", "normalise", "zclean"};

// clang-format off
const OptionGroup FFTOption = OptionGroup ("Options for FFT filter")
Expand Down
5 changes: 3 additions & 2 deletions cmd/mrgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
using namespace MR;
using namespace App;

const char *interp_choices[] = {"nearest", "linear", "cubic", "sinc", NULL};

#define DEFAULT_INTERP 2 // cubic
const char *operation_choices[] = {"regrid", "crop", "pad", NULL};
const std::vector<std::string> interp_choices = {"nearest", "linear", "cubic", "sinc"};
const std::vector<std::string> operation_choices = {"regrid", "crop", "pad"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrhistmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using namespace MR;
using namespace App;

const char *choices[] = {"scale", "linear", "nonlinear", nullptr};
const std::vector<std::string> choices = {"scale", "linear", "nonlinear"};

// clang-format off
void usage() {
Expand Down
27 changes: 14 additions & 13 deletions cmd/mrmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@
using namespace MR;
using namespace App;

const char *operations[] = {"mean",
"median",
"sum",
"product",
"rms",
"norm",
"var",
"std",
"min",
"max",
"absmax", // Maximum of absolute values
"magmax", // Value for which the magnitude is the maximum (i.e. preserves signed-ness)
NULL};
const std::vector<std::string> operations = {
"mean",
"median",
"sum",
"product",
"rms",
"norm",
"var",
"std",
"min",
"max",
"absmax", // Maximum of absolute values
"magmax" // Value for which the magnitude is the maximum (i.e. preserves signed-ness)
};

// clang-format off
void usage() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/mrmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
using namespace MR;
using namespace App;

const char *interp_choices[] = {"nearest", "linear", "cubic", "sinc", NULL};
#define DEFAULT_INTERP 1 // linear
const char *space_choices[] = {"voxel", "image1", "image2", "average", NULL};
#define DEFAULT_SPACE 0 // voxel
const std::vector<std::string> interp_choices = {"nearest", "linear", "cubic", "sinc"};
const std::vector<std::string> space_choices = {"voxel", "image1", "image2", "average"};


template <class ValueType>
inline void
Expand Down Expand Up @@ -169,7 +170,7 @@ void evaluate_voxelwise_msq(InType1 &in1,
}

enum MetricType { MeanSquared, CrossCorrelation };
const char *metric_choices[] = {"diff", "cc", NULL};
const std::vector<std::string> metric_choices = {"diff", "cc"};

// clang-format off
void usage() {
Expand Down
10 changes: 2 additions & 8 deletions cmd/mrregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@
using namespace MR;
using namespace App;

const char *transformation_choices[] = {"rigid",
"affine",
"nonlinear",
"rigid_affine",
"rigid_nonlinear",
"affine_nonlinear",
"rigid_affine_nonlinear",
nullptr};
#define DEFAULT_TRANSFORMATION_TYPE 5 // affine_nonlinear
const std::vector<std::string> transformation_choices = {
"rigid", "affine", "nonlinear", "rigid_affine", "rigid_nonlinear", "affine_nonlinear", "rigid_affine_nonlinear"};

// clang-format off
const OptionGroup multiContrastOptions =
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrthreshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace MR;
using namespace App;

enum class operator_type { LT, LE, GE, GT, UNDEFINED };
const char *const operator_list[] = {"lt", "le", "ge", "gt", nullptr};
const std::vector<std::string> operator_list = {"lt", "le", "ge", "gt"};

// clang-format off
void usage() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/mrtransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
using namespace MR;
using namespace App;

const char *interp_choices[] = {"nearest", "linear", "cubic", "sinc", nullptr};
#define DEFAULT_INTERP 2 // cubic
const char *modulation_choices[] = {"fod", "jac", nullptr};
const std::vector<std::string> interp_choices = {"nearest", "linear", "cubic", "sinc"};
const std::vector<std::string> modulation_choices = {"fod", "jac"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mtnormalise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace App;
#define DEFAULT_BALANCE_MAXITER_VALUE 7
#define DEFAULT_POLY_ORDER 3

const char *poly_order_choices[] = {"0", "1", "2", "3", nullptr};
const std::vector<std::string> poly_order_choices = {"0", "1", "2", "3"};

// clang-format off
void usage() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/shbasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
using namespace MR;
using namespace App;

const char *conversions[] = {"old", "new", "force_oldtonew", "force_newtoold", nullptr};
const std::vector<std::string> conversions = {"old", "new", "force_oldtonew", "force_newtoold"};
enum conv_t { NONE, OLD, NEW, FORCE_OLDTONEW, FORCE_NEWTOOLD };

// clang-format off
Expand Down
Loading

0 comments on commit d76e8ad

Please sign in to comment.