From 7cc9352049591780979a4d88dbbb3bf7c1e800e5 Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Wed, 15 Jan 2025 23:14:30 +1100 Subject: [PATCH] Fix C++ code formatting for #3061 --- cpp/cmd/mrcalc.cpp | 2 +- cpp/core/adapter/reslice.h | 22 ++++++++++++---------- cpp/core/file/mmap.cpp | 13 ++++++------- cpp/core/file/png.cpp | 12 ++++++------ cpp/core/file/png.h | 9 +++++---- cpp/core/formats/pipe.cpp | 4 ++-- cpp/core/header.cpp | 6 +++--- cpp/core/image_io/png.cpp | 26 +++++++++++++++----------- cpp/core/image_io/ram.h | 2 +- cpp/core/image_io/scratch.h | 2 +- cpp/core/image_io/variable_scaling.h | 2 +- 11 files changed, 53 insertions(+), 47 deletions(-) diff --git a/cpp/cmd/mrcalc.cpp b/cpp/cmd/mrcalc.cpp index 3bc55892a4..3513c708f9 100644 --- a/cpp/cmd/mrcalc.cpp +++ b/cpp/cmd/mrcalc.cpp @@ -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" diff --git a/cpp/core/adapter/reslice.h b/cpp/core/adapter/reslice.h index a5ca68c788..7b7a6511a7 100644 --- a/cpp/core/adapter/reslice.h +++ b/cpp/core/adapter/reslice.h @@ -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 std::enable_if::value, value_type>::type inline normalise( - const default_type sum, const default_type norm) { +template // +typename std::enable_if::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 std::enable_if::value && std::is_integral::value, - value_type>::type inline normalise(const default_type sum, const default_type norm) { +template // +typename std::enable_if::value && // + std::is_integral::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 std::enable_if::value && !std::is_integral::value, value_type>::type -inline normalise (const summing_type sum, const default_type norm) { - return value_type (sum * norm); +template // +typename std::enable_if::value && // + !std::is_integral::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; diff --git a/cpp/core/file/mmap.cpp b/cpp/core/file/mmap.cpp index 34597c4e79..bcf173a7b1 100644 --- a/cpp/core/file/mmap.cpp +++ b/cpp/core/file/mmap.cpp @@ -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; } diff --git a/cpp/core/file/png.cpp b/cpp/core/file/png.cpp index 061232f051..dea9ae6ca7 100644 --- a/cpp/core/file/png.cpp +++ b/cpp/core/file/png.cpp @@ -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), @@ -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)"); @@ -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()) { @@ -216,14 +216,14 @@ Writer::Writer(const Header &H, const std::string &filename) break; case DataType::Float32: bit_depth = 8; - multiplier = std::numeric_limits::infinity(); break; + multiplier = std::numeric_limits::infinity(); break; case DataType::UInt16: case DataType::UInt32: case DataType::UInt64: case DataType::Float64: bit_depth = 16; - multiplier = std::numeric_limits::infinity(); break; + multiplier = std::numeric_limits::infinity(); break; } // Detect cases where one axis has a size of 1, and hence represents the image plane diff --git a/cpp/core/file/png.h b/cpp/core/file/png.h index 9766c6a518..72a38ec056 100644 --- a/cpp/core/file/png.h +++ b/cpp/core/file/png.h @@ -86,12 +86,13 @@ class Writer { template 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(data_type); - for (size_t i = 0; i != num_elements; ++i) - Raw::store_BE (std::min (default_type(std::numeric_limits::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(std::min(default_type(std::numeric_limits::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 diff --git a/cpp/core/formats/pipe.cpp b/cpp/core/formats/pipe.cpp index aaade85860..e421dbb440 100644 --- a/cpp/core/formats/pipe.cpp +++ b/cpp/core/formats/pipe.cpp @@ -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"); diff --git a/cpp/core/header.cpp b/cpp/core/header.cpp index 71f4a6b17e..3aa1e0489d 100644 --- a/cpp/core/header.cpp +++ b/cpp/core/header.cpp @@ -726,11 +726,11 @@ concatenate(const std::vector
&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) { diff --git a/cpp/core/image_io/png.cpp b/cpp/core/image_io/png.cpp index ee6ad718b5..70bfeb8890 100644 --- a/cpp/core/image_io/png.cpp +++ b/cpp/core/image_io/png.cpp @@ -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) || @@ -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)); diff --git a/cpp/core/image_io/ram.h b/cpp/core/image_io/ram.h index b6c61ad70a..493251f264 100644 --- a/cpp/core/image_io/ram.h +++ b/cpp/core/image_io/ram.h @@ -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 diff --git a/cpp/core/image_io/scratch.h b/cpp/core/image_io/scratch.h index 2066c883e0..6a359f6f62 100644 --- a/cpp/core/image_io/scratch.h +++ b/cpp/core/image_io/scratch.h @@ -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 diff --git a/cpp/core/image_io/variable_scaling.h b/cpp/core/image_io/variable_scaling.h index a7de9bf1f5..b114b082b7 100644 --- a/cpp/core/image_io/variable_scaling.h +++ b/cpp/core/image_io/variable_scaling.h @@ -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