8000 Address SonarCloud findings: drop redundant c_str(), use is_same_v · QIICR/dcmqi@145b7b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 145b7b4

Browse files
rflocaclaude
andcommitted
Address SonarCloud findings: drop redundant c_str(), use is_same_v
SonarCloud flagged new-code smells on PR #538. Two are fixed here: - S7121: JSONSegmentationMetaInformationHandler takes its argument as std::string, so passing .c_str() forced a string -> const char* -> string round-trip. Removed at both call sites (the string-overload wrapper and the equivalence test). - S6020: replace std::is_same<...>::value with std::is_same_v in all four occurrences so the string and handler overloads stay consistent. The remaining findings are recorded as won't-fix: the source_location (S6190) and requires/concepts (S6195) suggestions are C++20-only while this project builds as C++17, and the 8-parameter count (S107) is inherited from the existing public string overload that the new handler overload deliberately mirrors. Verified locally (MSVC, C++17, Release): clean compile and 61/61 dcmqi tests pass, including itkimage2segimage_handlerOverloadEquivalence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5074f43 commit 145b7b4

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎apps/seg/Testing/Itk2DicomHandlerOverloadEquivalenceTest.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int main(int argc, char* argv[])
149149
REQUIRE(resultA != nullptr);
150150

151151
// Path B: handler overload (new).
152-
dcmqi::JSONSegmentationMetaInformationHandler handler(metadata.c_str());
152+
dcmqi::JSONSegmentationMetaInformationHandler handler(metadata);
153153
handler.read();
154154
std::unique_ptr<DcmDataset> resultB(
155155
dcmqi::Itk2DicomConverter::itkimage2dcmSegmentation(dcmDatasetsB, segmentations, handler));

‎include/dcmqi/Itk2DicomConverter.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace dcmqi {
9696
* conversion fails (NULL is returned).
9797
* @return A pointer to the resulting DICOM Segmentation object.
9898
*/
99-
template<class ImageSourceType, std::enable_if_t<std::is_same<short, typename ImageSourceType::PixelType>::value, bool> = 0>
99+
template<class ImageSourceType, std::enable_if_t<std::is_same_v<short, typename ImageSourceType::PixelType>, bool> = 0>
100100
static DcmDataset* itkimage2dcmSegmentation(vector<DcmItem*> dcmDatasets,
101101
vector<itk::SmartPointer<const ImageSourceType>> segmentations,
102102
const string &metaData,
@@ -118,7 +118,7 @@ namespace dcmqi {
118118
*
119119
* Parameter semantics are identical to the string overload.
120120
*/
121-
template<class ImageSourceType, std::enable_if_t<std::is_same<short, typename ImageSourceType::PixelType>::value, bool> = 0>
121+
template<class ImageSourceType, std::enable_if_t<std::is_same_v<short, typename ImageSourceType::PixelType>, bool> = 0>
122122
static DcmDataset* itkimage2dcmSegmentation(vector<DcmItem*> dcmDatasets,
123123
vector<itk::SmartPointer<const ImageSourceType>> segmentations,
124124
JSONSegmentationMetaInformationHandler& metaInfo,

‎libsrc/Itk2DicomConverter.cpp‎

Lines changed: 3 additions & 3 deletions
return itkimage2dcmSegmentation(dcmDatasets, segmentations, metaInfo,
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace dcmqi {
2626

2727
// -------------------------------------------------------------------------------------
2828

29-
template<class ImageSourceType, std::enable_if_t<std::is_same<short, typename ImageSourceType::PixelType>::value, bool>>
29+
template<class ImageSourceType, std::enable_if_t<std::is_same_v<short, typename ImageSourceType::PixelType>, bool>>
3030
DcmDataset* Itk2DicomConverter::itkimage2dcmSegmentation(vector<DcmItem*> dcmDatasets,
3131
vector<itk::SmartPointer<const ImageSourceType>> segmentations,
3232
const string &metaData,
@@ -38,7 +38,7 @@ namespace dcmqi {
3838
// Thin wrapper around the handler-based overload: parse the JSON string into a
3939
// handler and delegate. Keeps the legacy file-driven call sites working while
4040
// the handler overload is the load-bearing implementation.
41-
JSONSegmentationMetaInformationHandler metaInfo(metaData.c_str());
41+
JSONSegmentationMetaInformationHandler metaInfo(metaData);
4242
metaInfo.read();
4343
4444
skipEmptySlices, useLabelIDAsSegmentNumber,
@@ -48,7 +48,7 @@ namespace dcmqi {
4848

4949
// -------------------------------------------------------------------------------------
5050

51-
template<class ImageSourceType, std::enable_if_t<std::is_same<short, typename ImageSourceType::PixelType>::value, bool>>
51+
template<class ImageSourceType, std::enable_if_t<std::is_same_v<short, typename ImageSourceType::PixelType>, bool>>
5252
DcmDataset* Itk2DicomConverter::itkimage2dcmSegmentation(vector<DcmItem*> dcmDatasets,
5353
vector<itk::SmartPointer<const ImageSourceType>> segmentations,
5454
JSONSegmentationMetaInformationHandler& metaInfo,

0 commit comments

Comments
 (0)
0