Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix qHash definitions #2762

Merged
merged 7 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/effects/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ enum class SignalProcessingStage {
Postfader
};

inline uint qHash(SignalProcessingStage stage) {
return static_cast<uint>(stage);
inline uint qHash(
SignalProcessingStage stage,
uint seed = 0) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
return qHash(static_cast<uint>(stage), seed);
};

enum class EffectChainMixMode {
Expand Down
12 changes: 8 additions & 4 deletions src/engine/channelhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandle& h) {
return stream;
}

inline uint qHash(const ChannelHandle& handle) {
return qHash(handle.handle());
inline uint qHash(
const ChannelHandle& handle,
uint seed = 0) {
return qHash(handle.handle(), seed);
}

// Convenience class that mimics QPair<ChannelHandle, QString> except with
Expand Down Expand Up @@ -104,8 +106,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandleAndGroup& g) {
return stream;
}

inline uint qHash(const ChannelHandleAndGroup& handle_group) {
return qHash(handle_group.handle());
inline uint qHash(
const ChannelHandleAndGroup& handle_group,
uint seed = 0) {
return qHash(handle_group.handle(), seed);
}

// A helper class used by EngineMaster to assign ChannelHandles to channel group
Expand Down
13 changes: 9 additions & 4 deletions src/preferences/configobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ inline QDebug operator<<(QDebug stream, const ConfigKey& configKey) {
}

// QHash hash function for ConfigKey objects.
inline uint qHash(const ConfigKey& key) {
return qHash(key.group) ^ qHash(key.item);
inline uint qHash(
const ConfigKey& key,
uint seed = 0) {
return qHash(key.group, seed) ^
qHash(key.item, seed);
}

// The value corresponding to a key. The basic value is a string, but can be
Expand Down Expand Up @@ -97,8 +100,10 @@ inline bool operator!=(const ConfigValue& lhs, const ConfigValue& rhs) {
return !(lhs == rhs);
}

inline uint qHash(const ConfigValue& key) {
return qHash(key.value.toUpper());
inline uint qHash(
const ConfigValue& key,
uint seed = 0) {
return qHash(key.value.toUpper(), seed);
}

class ConfigValueKbd : public ConfigValue {
Expand Down
47 changes: 0 additions & 47 deletions src/soundio/soundmanagerutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ unsigned char ChannelGroup::getChannelCount() const {
return m_channels;
}

/**
* Defines equality between two ChannelGroups.
* @return true if the two ChannelGroups share a common base channel
* and channel count, otherwise false.
*/
bool ChannelGroup::operator==(const ChannelGroup &other) const {
return m_channelBase == other.m_channelBase
&& m_channels == other.m_channels;
}

/**
* Checks if another ChannelGroup shares channels with this one.
* @param other the other ChannelGroup to check for a clash with.
Expand All @@ -69,14 +59,6 @@ bool ChannelGroup::clashesWith(const ChannelGroup &other) const {
|| m_channelBase == other.m_channelBase;
}

/**
* Generates a hash of this ChannelGroup, so it can act as a key in a QHash.
* @return a hash for this ChannelGroup
*/
unsigned int ChannelGroup::getHash() const {
return 0 | (m_channels << 8) | m_channelBase;
}

/**
* Constructs an AudioPath object (must be called by a child class's
* constructor, AudioPath is abstract).
Expand Down Expand Up @@ -119,14 +101,6 @@ bool AudioPath::operator==(const AudioPath &other) const {
&& m_index == other.m_index;
}

/**
* Generates a hash of this AudioPath, so it can act as a key in a QHash.
* @return a hash for this AudioPath
*/
unsigned int AudioPath::getHash() const {
return 0 | (m_type << 8) | m_index;
}

/**
* Checks if this AudioPath's channels clash with another's
* (see ChannelGroup::clashesWith).
Expand Down Expand Up @@ -469,24 +443,3 @@ QString SoundDeviceId::debugName() const {
return name + QStringLiteral(", ") + alsaHwDevice + QStringLiteral(", ") + QString::number(portAudioIndex);
}
}

/**
* Defined for QHash, so ChannelGroup can be used as a QHash key.
*/
unsigned int qHash(const ChannelGroup &group) {
return group.getHash();
}

/**
* Defined for QHash, so AudioOutput can be used as a QHash key.
*/
unsigned int qHash(const AudioOutput &output) {
return output.getHash();
}

/**
* Defined for QHash, so AudioInput can be used as a QHash key.
*/
unsigned int qHash(const AudioInput &input) {
return input.getHash();
}
Loading