Skip to content

Commit

Permalink
cpp: use shared_ptr for internal map management instead of custom del…
Browse files Browse the repository at this point in the history
…eter
  • Loading branch information
justinfx committed Apr 14, 2024
1 parent 0374a82 commit 05d8562
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changes:
2.12.0
----------------

* cpp - use shared_ptr for internal map management instead of custom deleter
* cpp - clang-tidy formatting

2.11.2
Expand Down
33 changes: 4 additions & 29 deletions cpp/fileseq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <dirent.h>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <sstream>
#include <sys/stat.h>
Expand Down Expand Up @@ -245,32 +246,7 @@ struct SeqInfo {
// Key for sequence results map: basename, extension
typedef std::pair< const std::string, const std::string > SeqKey;
// Map type to track sequence results in a directory
typedef std::map< SeqKey, SeqInfo* > SeqsMap;


// Wrapper to make sure a SeqsMap is cleaned up properly
// when it goes out of scope
class SeqsMapCloser {
public:
SeqsMapCloser(SeqsMap* m) : m_map(m) {}

~SeqsMapCloser() {
if (m_map == NULL) {
return;
}

SeqsMap::iterator it;
for (it = m_map->begin(); it != m_map->end(); ++it) {
if (it->second != NULL) {
delete it->second;
it->second = NULL;
}
}
}

private:
SeqsMap* m_map;
};
typedef std::map< SeqKey, std::shared_ptr<SeqInfo> > SeqsMap;


} // internal
Expand Down Expand Up @@ -313,7 +289,6 @@ Status findSequencesOnDisk(FileSequences &seqs,

// Track members of file sequences as we scan
SeqsMap seqsMap;
SeqsMapCloser seqsMapCloser(&seqsMap);

// Track individual files (if option allows)
FileSequences files;
Expand All @@ -332,7 +307,7 @@ Status findSequencesOnDisk(FileSequences &seqs,
size_t frameWidth;
std::string name;
FileSequence fs;
SeqInfo* seqInfo;
std::shared_ptr<SeqInfo> seqInfo;
SeqPatternMatch match;
SeqsMap::iterator seqFound;

Expand Down Expand Up @@ -456,7 +431,7 @@ Status findSequencesOnDisk(FileSequences &seqs,
if (seqFound == seqsMap.end()) {

// Doesn't exist yet. Create new entry
seqInfo = new SeqInfo;
seqInfo = std::make_shared<SeqInfo>();
seqInfo->minWidth = frameWidth;
seqInfo->padding = padder.getPaddingChars(frameWidth);
seqsMap[key] = seqInfo;
Expand Down

0 comments on commit 05d8562

Please sign in to comment.