Skip to content

Commit

Permalink
Fix C++ code formatting for #3061
Browse files Browse the repository at this point in the history
  • Loading branch information
Lestropie committed Jan 15, 2025
1 parent ee6f060 commit 7cc9352
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cpp/cmd/mrcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void run() {
else if (opt->is("force") || opt->is("info") || opt->is("debug") || opt->is("quiet"))
continue;
else if (opt->is("config"))
n+=2;
n += 2;

#define SECTION 3
#include "mrcalc.cpp"
Expand Down
22 changes: 12 additions & 10 deletions cpp/core/adapter/reslice.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ namespace MR::Adapter {
namespace {
// Partial specialisation for boolean value_type in order to avoid compiler
// warning regarding use of multiplication when assigning to a boolean
template <typename value_type>
typename std::enable_if<std::is_same<value_type, bool>::value, value_type>::type inline normalise(
const default_type sum, const default_type norm) {
template <typename value_type> //
typename std::enable_if<std::is_same<value_type, bool>::value, value_type>::type inline //
normalise(const default_type sum, const default_type norm) { //
return ((sum * norm) >= 0.5) ? true : false;
}

// Partial specialisation to invoke round-to-nearest when taking an average of integers
template <typename value_type>
typename std::enable_if<!std::is_same<value_type, bool>::value && std::is_integral<value_type>::value,
value_type>::type inline normalise(const default_type sum, const default_type norm) {
template <typename value_type> //
typename std::enable_if<!std::is_same<value_type, bool>::value && //
std::is_integral<value_type>::value, value_type>::type inline //
normalise(const default_type sum, const default_type norm) { //
return value_type(std::round(sum * norm));
}

// Standard implementation for floating point (either real or complex)
template <typename value_type, typename summing_type>
typename std::enable_if<!std::is_same<value_type, bool>::value && !std::is_integral<value_type>::value, value_type>::type
inline normalise (const summing_type sum, const default_type norm) {
return value_type (sum * norm);
template <typename value_type, typename summing_type> //
typename std::enable_if<!std::is_same<value_type, bool>::value && //
!std::is_integral<value_type>::value, value_type>::type inline //
normalise(const summing_type sum, const default_type norm) { //
return value_type(sum * norm);
}

// If summing complex numbers, use double precision complex;
Expand Down
13 changes: 6 additions & 7 deletions cpp/core/file/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ MMap::MMap(const Entry &entry, bool readwrite, bool preload, int64_t mapped_size
delayed_writeback = true;
}

if (fsbuf.f_type == 0xff534d42 /* CIFS */ || fsbuf.f_type == 0x6969 /* NFS */ ||
fsbuf.f_type == 0x65735546 /* FUSE */ || fsbuf.f_type == 0x517b /* SMB */ ||
fsbuf.f_type == 0x47504653 /* GPFS */ || fsbuf.f_type == 0xbd00bd0 /* LUSTRE */ ||
fsbuf.f_type == 0x1021997 /* 9P (WSL) */

if (fsbuf.f_type == 0xff534d42 /* CIFS */ || fsbuf.f_type == 0x6969 /* NFS */ || //
fsbuf.f_type == 0x65735546 /* FUSE */ || fsbuf.f_type == 0x517b /* SMB */ || //
fsbuf.f_type == 0x47504653 /* GPFS */ || fsbuf.f_type == 0xbd00bd0 /* LUSTRE */ || //
fsbuf.f_type == 0x1021997 /* 9P (WSL) */ //
#ifdef MRTRIX_MACOSX
|| fsbuf.f_type == 0x0017 /* OSXFUSE */
|| fsbuf.f_type == 0x0017 /* OSXFUSE */ //
#endif
) {
) { //
DEBUG("\"" + Entry::name + "\" appears to reside on a networked filesystem - using delayed write-back");
delayed_writeback = true;
}
Expand Down
12 changes: 6 additions & 6 deletions cpp/core/file/png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace MR::File::PNG {

Reader::Reader(const std::string &filename)
: infile (fopen(filename.c_str(), "rb")),
: infile(fopen(filename.c_str(), "rb")),
png_ptr(NULL),
info_ptr(NULL),
width(0),
Expand Down Expand Up @@ -148,7 +148,7 @@ Writer::Writer(const Header &H, const std::string &filename)
bit_depth(0),
filename(filename),
data_type(H.datatype()),
multiplier (1.0),
multiplier(1.0),
outfile(NULL) {
if (Path::exists(filename) && !App::overwrite_files)
throw Exception("output file \"" + filename + "\" already exists (use -force option to force overwrite)");
Expand All @@ -162,8 +162,8 @@ Writer::Writer(const Header &H, const std::string &filename)
}
outfile = fopen(filename.c_str(), "wb");
if (!outfile)
throw Exception ("Unable to open PNG file for writing for image \"" + filename + "\": " //
+ strerror (errno)); //
throw Exception("Unable to open PNG file for writing for image \"" + filename + "\": " //
+ strerror (errno)); //
png_init_io(png_ptr, outfile);
png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
switch (H.ndim()) {
Expand Down Expand Up @@ -216,14 +216,14 @@ Writer::Writer(const Header &H, const std::string &filename)
break;
case DataType::Float32:
bit_depth = 8;
multiplier = std::numeric_limits<uint8_t>::infinity(); break;
multiplier = std::numeric_limits<uint8_t>::infinity();
break;
case DataType::UInt16:
case DataType::UInt32:
case DataType::UInt64:
case DataType::Float64:
bit_depth = 16;
multiplier = std::numeric_limits<uint16_t>::infinity(); break;
multiplier = std::numeric_limits<uint16_t>::infinity();
break;
}
// Detect cases where one axis has a size of 1, and hence represents the image plane
Expand Down
9 changes: 5 additions & 4 deletions cpp/core/file/png.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ class Writer {
template <typename T>
void Writer::fill(uint8_t *in_ptr, uint8_t *out_ptr, const DataType data_type, const size_t num_elements) {
auto fetch_func = __set_fetch_function<default_type>(data_type);
for (size_t i = 0; i != num_elements; ++i)
Raw::store_BE<T> (std::min (default_type(std::numeric_limits<T>::max()), //
std::max (0.0, std::round(multiplier * fetch_func (in_ptr, 0)))), //
out_ptr, i); //
for (size_t i = 0; i != num_elements; ++i) {
Raw::store_BE<T>(std::min(default_type(std::numeric_limits<T>::max()), //
std::max(0.0, std::round(multiplier * fetch_func (in_ptr, 0)))), //
out_ptr, i); //
in_ptr += data_type.bytes();
out_ptr += sizeof(T);
}
};

} // namespace MR::File::PNG
Expand Down
4 changes: 2 additions & 2 deletions cpp/core/formats/pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ bool Pipe::check(Header &H, size_t num_axes) const {
return false;

if (isatty(STDOUT_FILENO))
throw Exception ("cannot create output piped image: " //
"no command connected at other end of pipe to receive that image"); //
throw Exception("cannot create output piped image: " //
"no command connected at other end of pipe to receive that image"); //

H.name() = File::create_tempfile(0, "mif");

Expand Down
6 changes: 3 additions & 3 deletions cpp/core/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,11 @@ concatenate(const std::vector<Header> &headers, const size_t axis_to_concat, con
Header result(headers[0]);

if (axis_to_concat >= result.ndim()) {
Stride::symbolise (result);
Stride::symbolise(result);
result.ndim() = axis_to_concat + 1;
result.size(axis_to_concat) = 1;
result.stride(axis_to_concat) = axis_to_concat+1;
Stride::actualise (result);
result.stride(axis_to_concat) = axis_to_concat + 1;
Stride::actualise(result);
}

for (size_t axis = 0; axis != result.ndim(); ++axis) {
Expand Down
26 changes: 15 additions & 11 deletions cpp/core/image_io/png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
namespace MR::ImageIO {

void PNG::load(const Header &header, size_t) {
DEBUG (std::string("loading PNG image") + (files.size() > 1 ? "s" : "") + " \"" + header.name() + "\"");
segsize = header.datatype().bytes() * voxel_count(header) * files.size();
addresses.resize(1);
segsize = (header.datatype().bits() * voxel_count (header) + 7) / 8;
DEBUG(std::string("loading PNG image") + (files.size() > 1 ? "s" : "") + " \"" + header.name() + "\"");
segsize = (header.datatype().bits() * voxel_count(header) + 7) / 8;
addresses[0].reset (new uint8_t[segsize]);
if (is_new) {
memset(addresses[0].get(), 0x00, segsize);
} else {
const size_t slice_bytes = (header.datatype().bits() * //
header.size(0) * //
header.size(1) * //
(header.ndim() == 4 ? header.size(3) : 1) + 7) //
/ 8; //
const size_t slice_bytes = (header.datatype().bits() * //
header.size(0) * //
header.size(1) * //
(header.ndim() == 4 ? header.size(3) : 1) //
+ 7) //
/ 8; //
for (size_t i = 0; i != files.size(); ++i) {
File::PNG::Reader png(files[i].name);
if (png.get_width() != header.size(0) || png.get_height() != header.size(1) ||
Expand All @@ -59,9 +58,14 @@ void PNG::load(const Header &header, size_t) {
}

void PNG::unload(const Header &header) {
assert (addresses.size() == 1);
assert(addresses.size() == 1);
if (writable) {
const size_t slice_bytes = (header.datatype().bits() * header.size(0) * header.size(1) * (header.ndim() == 4 ? header.size(3) : 1) + 7) / 8;
const size_t slice_bytes = (header.datatype().bits() * //
header.size(0) * //
header.size(1) * //
(header.ndim() == 4 ? header.size(3) : 1) //
+ 7) //
/ 8; //
for (size_t i = 0; i != files.size(); i++) {
File::PNG::Writer png (header, files[i].name);
png.save (addresses[0].get() + (i * slice_bytes));
Expand Down
2 changes: 1 addition & 1 deletion cpp/core/image_io/ram.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RAM : public Base {

protected:
virtual void load(const Header &, size_t);
virtual void unload(const Header &) { }
virtual void unload(const Header &) {}
};

} // namespace MR::ImageIO
2 changes: 1 addition & 1 deletion cpp/core/image_io/scratch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Scratch : public Base {

protected:
virtual void load(const Header &, size_t);
virtual void unload(const Header &) { }
virtual void unload(const Header &) {}
};

} // namespace MR::ImageIO
2 changes: 1 addition & 1 deletion cpp/core/image_io/variable_scaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class VariableScaling : public Base {

protected:
virtual void load(const Header &, size_t);
virtual void unload(const Header &) { }
virtual void unload(const Header &) {}
};

} // namespace MR::ImageIO

0 comments on commit 7cc9352

Please sign in to comment.