Skip to content

Commit

Permalink
Use C++20 features to simplify the SystemLocation class.
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Feb 10, 2024
1 parent a107664 commit 9e2fdff
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 32 deletions.
1 change: 0 additions & 1 deletion source/midi/midifile.cpp
Expand Up @@ -87,7 +87,6 @@ static SystemLocation moveToNextBar(MidiEventList &event_list, int ticks,
RepeatController &repeat_controller)
{
SystemLocation prev_location = location;
SystemLocation new_location;

// Move to the next barline and follow any directions / repeats / alternate
// endings.
Expand Down
1 change: 0 additions & 1 deletion source/score/precompiled.h
Expand Up @@ -18,5 +18,4 @@
#include <unordered_map>
#include <vector>

#include <boost/operators.hpp>
#include <boost/rational.hpp>
19 changes: 0 additions & 19 deletions source/score/systemlocation.cpp
Expand Up @@ -25,25 +25,6 @@ SystemLocation::SystemLocation(int system, int position)
{
}

SystemLocation::SystemLocation()
: mySystem(0),
myPosition(0)
{
}

bool SystemLocation::operator<(const SystemLocation &location) const
{
if (mySystem == location.mySystem)
return myPosition < location.myPosition;
else
return mySystem < location.mySystem;
}

bool SystemLocation::operator==(const SystemLocation &location) const
{
return mySystem == location.mySystem && myPosition == location.myPosition;
}

void SystemLocation::setPosition(int position)
{
myPosition = position;
Expand Down
16 changes: 5 additions & 11 deletions source/score/systemlocation.h
Expand Up @@ -18,22 +18,16 @@
#ifndef SCORE_SYSTEMLOCATION_H
#define SCORE_SYSTEMLOCATION_H

#include <boost/operators.hpp>
#include <memory>

/// Convenience class to represent a location in a system.
class SystemLocation :
// Generate != from operator==
boost::equality_comparable<SystemLocation>,
// Generate <=, >, >= from operator<
boost::less_than_comparable<SystemLocation>
class SystemLocation
{
public:
SystemLocation();
SystemLocation() = default;
SystemLocation(int system, int position);

bool operator<(const SystemLocation &location) const;
bool operator==(const SystemLocation &location) const;
auto operator<=>(const SystemLocation &location) const = default;

void setSystem(int system);
int getSystem() const;
Expand All @@ -42,8 +36,8 @@ class SystemLocation :
int getPosition() const;

private:
int mySystem;
int myPosition;
int mySystem = 0;
int myPosition = 0;
};

/// Enable the use of SystemLocation as a key for std::unordered_map, etc.
Expand Down

0 comments on commit 9e2fdff

Please sign in to comment.