Skip to content

Commit

Permalink
cpp: clang-tidy formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Apr 14, 2024
1 parent c195a8b commit 0374a82
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changes:

2.12.0
----------------

* cpp - clang-tidy formatting

2.11.2
----------------
* go/cpp: fix regex to handle parsing complex extensions with single character component ("file.1.a.ext")
Expand Down
2 changes: 1 addition & 1 deletion cpp/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void handleErrorStatus(const std::string &msg, Status* stat) {


void setError(const std::string &msg, Status* stat) {
if (stat != NULL) {
if (stat != nullptr) {
stat->setError(msg);
}
}
Expand Down
7 changes: 6 additions & 1 deletion cpp/error.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "google-explicit-constructor"
#pragma ide diagnostic ignored "modernize-use-equals-default"
#ifndef FILESEQ_ERROR_H_
#define FILESEQ_ERROR_H_

Expand Down Expand Up @@ -28,7 +31,7 @@ std::string to receive the error message.
class Status {

public:
Status() {}
Status() = default;

//! If Status evaluates to false, it indicates an error state
operator bool() const { return m_error.empty(); }
Expand Down Expand Up @@ -71,3 +74,5 @@ void setError(const std::string &msg, Status* stat);

#endif // FILESEQ_ERROR_H_


#pragma clang diagnostic pop
39 changes: 20 additions & 19 deletions cpp/fileseq.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions"
#include "fileseq.h"
#include "pad.h"
#include "private/frameset_p.h"
Expand All @@ -13,8 +15,6 @@
#include <string>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utility>

namespace fileseq {
Expand Down Expand Up @@ -47,9 +47,9 @@ std::string framesToFrameRange(const Frames &frames,
framesEnd = sortedFrames.end();
}

long step = 0;
long step;
bool hasWritten = false;
Frames::size_type i = 0;
Frames::size_type i;

std::string start, end;
std::stringstream buf;
Expand Down Expand Up @@ -92,7 +92,6 @@ std::string framesToFrameRange(const Frames &frames,
// Subsequent groups are comma-separated
if (hasWritten) {
buf << ",";
hasWritten = true;
}

// We only have a single frame to write for this group
Expand Down Expand Up @@ -155,26 +154,26 @@ FileSequence findSequenceOnDisk(const std::string &pattern, Status* ok) {
}

FileSequence findSequenceOnDisk(const std::string &pattern, PadStyle style, Status* ok) {
if (ok != NULL) ok->clearError();
if (ok != nullptr) ok->clearError();

Status localOk;
FileSequence fs(pattern, style, &localOk);
FileSequence fs {pattern, style, &localOk};

if (!localOk) {
// Treat a bad pattern as a non-match
std::cerr << "fileseq: " << localOk << std::endl;
return FileSequence();
return {};
}

FileSequences seqs;
localOk = findSequencesOnDisk(seqs, fs.dirname(), fs);
if (!localOk) {
if (ok != NULL) {
if (ok != nullptr) {
std::ostringstream err;
err << "Failed to find " << pattern << ": " << localOk;
ok->setError(err.str());
}
return FileSequence();
return {};
}

const std::string &base = fs.basename();
Expand All @@ -185,12 +184,12 @@ FileSequence findSequenceOnDisk(const std::string &pattern, PadStyle style, Stat
// Find the first match and return it
if (it->basename() == base && it->ext() == ext) {
it->setPaddingStyle(style);
return (*it);
return *it;
}
}

// If we get this far, we didn't find a match
return FileSequence();
return {};
}

// deprecated
Expand Down Expand Up @@ -220,10 +219,10 @@ namespace internal {
// when it goes out of scope
class DirCloser {
public:
DirCloser(DIR* d) : m_dir(d) {}
explicit DirCloser(DIR* d) : m_dir(d) {}

~DirCloser() {
if (m_dir != NULL) {
if (m_dir != nullptr) {
closedir(m_dir);
}
}
Expand Down Expand Up @@ -303,7 +302,7 @@ Status findSequencesOnDisk(FileSequences &seqs,

// Open the directory
DIR* dir;
if ( (dir = opendir(path.c_str())) == NULL ) {
if ( (dir = opendir(path.c_str())) == nullptr ) {
status.setError(std::strerror(errno));
return status;
}
Expand All @@ -330,7 +329,7 @@ Status findSequencesOnDisk(FileSequences &seqs,
std::ostringstream buf(root, std::ios_base::out | std::ios_base::ate);

Frame frame;
size_t frameWidth = 0;
size_t frameWidth;
std::string name;
FileSequence fs;
SeqInfo* seqInfo;
Expand All @@ -349,7 +348,7 @@ Status findSequencesOnDisk(FileSequences &seqs,
errno = 0;

// Read dir and sort files into groups
while ( (d_ent = readdir(dir)) != NULL ) {
while ( (d_ent = readdir(dir)) != nullptr ) {

// Is it a directory?
if (d_ent->d_type == DT_DIR) {
Expand Down Expand Up @@ -495,7 +494,7 @@ Status findSequencesOnDisk(FileSequences &seqs,

seqs.reserve(seqsMap.size());

size_t pos = 0;
size_t pos;
char digit;
std::string ext, pad, frange;

Expand All @@ -519,7 +518,7 @@ Status findSequencesOnDisk(FileSequences &seqs,
// get reparsed as a range.
pos = 1;
// Check if the parsed number was preceded by a "-",
// if so, check before that char to see if its a number
// if so, check before that char to see if it's a number
if (name[name.size()-1] == '-' && name.size() >= 2) {
pos = 2;
}
Expand Down Expand Up @@ -569,3 +568,5 @@ Status findSequencesOnDisk(FileSequences &seqs,


} // fileseq

#pragma clang diagnostic pop
4 changes: 2 additions & 2 deletions cpp/fileseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If an error occurs while reading the filesystem, it can be
captured by passing a fileseq::Status pointer.
*/
FileSequence findSequenceOnDisk(const std::string &pattern,
Status* ok=NULL);
Status* ok=nullptr);

/*!
FindSequenceOnDisk takes a string that is a compatible/parsible
Expand All @@ -50,7 +50,7 @@ captured by passing a fileseq::Status pointer.
*/
FileSequence findSequenceOnDisk(const std::string &pattern,
PadStyle style,
Status* ok=NULL);
Status* ok=nullptr);

/*!
FindSequenceOpts enums define behavior of finding
Expand Down
26 changes: 13 additions & 13 deletions cpp/frameset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void FrameSet::handleMatch(const internal::RangePatternMatch* match, Status* ok)
ok->clearError();

Frame start, end;
long step = 1;
long step;

switch (num) {

Expand Down Expand Up @@ -181,19 +181,19 @@ std::string FrameSet::string() const {

size_t FrameSet::length() const {
return isValid() ? m_frameData->ranges.length() : 0;
};
}

size_t FrameSet::index(Frame frame) const {
return isValid() ? (size_t)m_frameData->ranges.index(frame) : 0;
};
}

Frame FrameSet::frame(size_t index, Status* ok) const {
if (!isValid()) {
return 0;
}

return m_frameData->ranges.value(index, ok);
};
}

void FrameSet::frames(Frames &frames) const {
frames.clear();
Expand All @@ -213,7 +213,7 @@ void FrameSet::frames(Frames &frames) const {
while (it.next()) {
frames.push_back(*it);
}
};
}

RangesIterator FrameSet::iterFrames() const {
if (!isValid()) {
Expand All @@ -224,16 +224,16 @@ RangesIterator FrameSet::iterFrames() const {
}

bool FrameSet::hasFrame(Frame frame) const {
return isValid() ? m_frameData->ranges.contains(frame) : false;
};
return isValid() && m_frameData->ranges.contains(frame);
}

Frame FrameSet::start() const {
return isValid() ? m_frameData->ranges.start() : 0;
};
}

Frame FrameSet::end() const {
return isValid() ? m_frameData->ranges.end() : 0;
};
}

std::string FrameSet::frameRange(int pad) const {
if (!isValid()) {
Expand All @@ -245,7 +245,7 @@ std::string FrameSet::frameRange(int pad) const {
}

return padFrameRange(m_frameData->frameRange, (size_t)pad);
};
}

FrameSet FrameSet::inverted() const {
FrameSet newFrameSet;
Expand All @@ -263,7 +263,7 @@ FrameSet FrameSet::inverted() const {
std::swap(newFrameSet.m_frameData->ranges, ranges);

return newFrameSet;
};
}

std::string FrameSet::invertedFrameRange(int pad) const {
if (!isValid()) {
Expand All @@ -280,7 +280,7 @@ std::string FrameSet::invertedFrameRange(int pad) const {
}

return frange;
};
}

FrameSet FrameSet::normalized() const {
FrameSet newFrameSet;
Expand All @@ -298,6 +298,6 @@ FrameSet FrameSet::normalized() const {
std::swap(newFrameSet.m_frameData->ranges, ranges);

return newFrameSet;
};
}

} // fileseq
4 changes: 2 additions & 2 deletions cpp/pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const PaddingMapper& getPadMapperForStyle(PadStyle style) {

}

// Should not get here. But sanity-check default..
// Should not get here. But sanity-check default.
return s_multiHash;
}

Expand All @@ -130,7 +130,7 @@ size_t PaddingMapper::getPaddingCharsSize(const std::string &chars) const {
return 0;
}

size_t size = 0;
size_t size;

// check for alternate padding syntax
if ((size = internal::getPadSize(chars, internal::PadSyntaxPrintf)) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const PaddingMapper& getPadMapperForStyle(PadStyle style);
class PaddingMapper {

public:
virtual ~PaddingMapper() {}
virtual ~PaddingMapper() = default;

// Return all supported padding characters
std::string getAllChars() const;
Expand Down

0 comments on commit 0374a82

Please sign in to comment.