General: Make operator bool() instances explicit

Prevents error-prone implicit conversions to bool.
This commit is contained in:
Lioncash 2019-09-07 11:20:14 -04:00
parent 0be0ca2911
commit 7600f8ad27
7 changed files with 9 additions and 7 deletions

View File

@ -26,7 +26,7 @@ protected:
public:
SystemString getSampleBasePath(SampleId sfxId) const;
operator bool() const { return m_valid; }
explicit operator bool() const { return m_valid; }
AudioGroup() = default;
explicit AudioGroup(const AudioGroupData& data) { assign(data); }
explicit AudioGroup(SystemStringView groupPath) { assign(groupPath); }

View File

@ -89,7 +89,9 @@ public:
size_t getSdirSize() const { return m_sdirSz; }
size_t getSampSize() const { return m_sampSz; }
operator bool() const { return m_proj != nullptr && m_pool != nullptr && m_sdir != nullptr && m_samp != nullptr; }
explicit operator bool() const {
return m_proj != nullptr && m_pool != nullptr && m_sdir != nullptr && m_samp != nullptr;
}
DataFormat getDataFormat() const { return m_fmt; }
bool getAbsoluteProjOffsets() const { return m_absOffs; }

View File

@ -216,7 +216,7 @@ public:
bool operator!=(const ObjTokenBase& other) const noexcept { return !operator==(other); }
bool operator<(const ObjTokenBase& other) const noexcept { return m_obj < other.m_obj; }
bool operator>(const ObjTokenBase& other) const noexcept { return m_obj > other.m_obj; }
operator bool() const noexcept { return m_obj != nullptr; }
explicit operator bool() const noexcept { return m_obj != nullptr; }
void reset() noexcept {
if (m_obj) {
m_obj->decrement();

View File

@ -48,7 +48,7 @@ public:
DirectoryEnumerator(SystemStringView path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false,
bool reverse = false, bool noHidden = false);
operator bool() const { return m_entries.size() != 0; }
explicit operator bool() const { return m_entries.size() != 0; }
size_t size() const { return m_entries.size(); }
std::vector<Entry>::const_iterator begin() const { return m_entries.cbegin(); }
std::vector<Entry>::const_iterator end() const { return m_entries.cend(); }

View File

@ -51,7 +51,7 @@ class Sequencer : public Entity {
~ChannelState();
ChannelState() = default;
ChannelState(Sequencer& parent, uint8_t chanId);
operator bool() const { return m_parent != nullptr; }
explicit operator bool() const { return m_parent != nullptr; }
/** Voices corresponding to currently-pressed keys in channel */
std::unordered_map<uint8_t, ObjToken<Voice>> m_chanVoxs;

View File

@ -94,7 +94,7 @@ class SongState {
Track() = default;
Track(SongState& parent, uint8_t midiChan, uint32_t loopStart, const TrackRegion* regions, uint32_t tempo);
operator bool() const { return m_parent != nullptr; }
explicit operator bool() const { return m_parent != nullptr; }
void setRegion(const TrackRegion* region);
void advanceRegion();
bool advance(Sequencer& seq, double dt);

View File

@ -78,7 +78,7 @@ struct SoundMacroState {
float evaluate(double time, const Voice& vox, const SoundMacroState& st) const;
/** Determine if able to use */
operator bool() const { return m_comps.size() != 0; }
explicit operator bool() const { return m_comps.size() != 0; }
};
Evaluator m_volumeSel;