mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Created c++11 move constructors and operator= methods for a bunch of classes (only enabled for c++11 compilers, of course)
This commit is contained in:
parent
2c328dfedc
commit
ffc2f5d40e
46 changed files with 629 additions and 39 deletions
|
|
@ -79,14 +79,31 @@ int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) noexcept
|
|||
return messageLengths [firstByte & 0x7f];
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
inline void MidiMessage::setToUseInternalData() noexcept
|
||||
{
|
||||
data = static_cast <uint8*> (preallocatedData.asBytes);
|
||||
}
|
||||
|
||||
inline bool MidiMessage::usesAllocatedData() const noexcept
|
||||
{
|
||||
return data != static_cast <const uint8*> (preallocatedData.asBytes);
|
||||
}
|
||||
|
||||
inline void MidiMessage::freeData() noexcept
|
||||
{
|
||||
if (usesAllocatedData())
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
MidiMessage::MidiMessage() noexcept
|
||||
: timeStamp (0),
|
||||
data (static_cast<uint8*> (preallocatedData.asBytes)),
|
||||
size (2)
|
||||
{
|
||||
data[0] = 0xf0;
|
||||
data[1] = 0xf7;
|
||||
preallocatedData.asBytes[0] = 0xf0;
|
||||
preallocatedData.asBytes[1] = 0xf7;
|
||||
}
|
||||
|
||||
MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
|
||||
|
|
@ -96,7 +113,7 @@ MidiMessage::MidiMessage (const void* const d, const int dataSize, const double
|
|||
jassert (dataSize > 0);
|
||||
|
||||
if (dataSize <= 4)
|
||||
data = static_cast<uint8*> (preallocatedData.asBytes);
|
||||
setToUseInternalData();
|
||||
else
|
||||
data = new uint8 [dataSize];
|
||||
|
||||
|
|
@ -111,7 +128,7 @@ MidiMessage::MidiMessage (const int byte1, const double t) noexcept
|
|||
data (static_cast<uint8*> (preallocatedData.asBytes)),
|
||||
size (1)
|
||||
{
|
||||
data[0] = (uint8) byte1;
|
||||
preallocatedData.asBytes[0] = (uint8) byte1;
|
||||
|
||||
// check that the length matches the data..
|
||||
jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
|
||||
|
|
@ -122,8 +139,8 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) noex
|
|||
data (static_cast<uint8*> (preallocatedData.asBytes)),
|
||||
size (2)
|
||||
{
|
||||
data[0] = (uint8) byte1;
|
||||
data[1] = (uint8) byte2;
|
||||
preallocatedData.asBytes[0] = (uint8) byte1;
|
||||
preallocatedData.asBytes[1] = (uint8) byte2;
|
||||
|
||||
// check that the length matches the data..
|
||||
jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
|
||||
|
|
@ -134,9 +151,9 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, con
|
|||
data (static_cast<uint8*> (preallocatedData.asBytes)),
|
||||
size (3)
|
||||
{
|
||||
data[0] = (uint8) byte1;
|
||||
data[1] = (uint8) byte2;
|
||||
data[2] = (uint8) byte3;
|
||||
preallocatedData.asBytes[0] = (uint8) byte1;
|
||||
preallocatedData.asBytes[1] = (uint8) byte2;
|
||||
preallocatedData.asBytes[2] = (uint8) byte3;
|
||||
|
||||
// check that the length matches the data..
|
||||
jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
|
||||
|
|
@ -146,14 +163,14 @@ MidiMessage::MidiMessage (const MidiMessage& other)
|
|||
: timeStamp (other.timeStamp),
|
||||
size (other.size)
|
||||
{
|
||||
if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
|
||||
if (other.usesAllocatedData())
|
||||
{
|
||||
data = new uint8 [size];
|
||||
memcpy (data, other.data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = static_cast<uint8*> (preallocatedData.asBytes);
|
||||
setToUseInternalData();
|
||||
preallocatedData.asInt32 = other.preallocatedData.asInt32;
|
||||
}
|
||||
}
|
||||
|
|
@ -162,14 +179,14 @@ MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
|
|||
: timeStamp (newTimeStamp),
|
||||
size (other.size)
|
||||
{
|
||||
if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
|
||||
if (other.usesAllocatedData())
|
||||
{
|
||||
data = new uint8 [size];
|
||||
memcpy (data, other.data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = static_cast<uint8*> (preallocatedData.asBytes);
|
||||
setToUseInternalData();
|
||||
preallocatedData.asInt32 = other.preallocatedData.asInt32;
|
||||
}
|
||||
}
|
||||
|
|
@ -268,17 +285,16 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other)
|
|||
timeStamp = other.timeStamp;
|
||||
size = other.size;
|
||||
|
||||
if (data != static_cast <const uint8*> (preallocatedData.asBytes))
|
||||
delete[] data;
|
||||
freeData();
|
||||
|
||||
if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
|
||||
if (other.usesAllocatedData())
|
||||
{
|
||||
data = new uint8 [size];
|
||||
memcpy (data, other.data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = static_cast<uint8*> (preallocatedData.asBytes);
|
||||
setToUseInternalData();
|
||||
preallocatedData.asInt32 = other.preallocatedData.asInt32;
|
||||
}
|
||||
}
|
||||
|
|
@ -286,10 +302,51 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
MidiMessage::MidiMessage (MidiMessage&& other) noexcept
|
||||
: timeStamp (other.timeStamp),
|
||||
size (other.size)
|
||||
{
|
||||
if (other.usesAllocatedData())
|
||||
{
|
||||
data = other.data;
|
||||
other.setToUseInternalData();
|
||||
}
|
||||
else
|
||||
{
|
||||
setToUseInternalData();
|
||||
preallocatedData.asInt32 = other.preallocatedData.asInt32;
|
||||
}
|
||||
}
|
||||
|
||||
MidiMessage& MidiMessage::operator= (MidiMessage&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
timeStamp = other.timeStamp;
|
||||
size = other.size;
|
||||
|
||||
freeData();
|
||||
|
||||
if (other.usesAllocatedData())
|
||||
{
|
||||
data = other.data;
|
||||
other.setToUseInternalData();
|
||||
}
|
||||
else
|
||||
{
|
||||
setToUseInternalData();
|
||||
preallocatedData.asInt32 = other.preallocatedData.asInt32;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
MidiMessage::~MidiMessage()
|
||||
{
|
||||
if (data != static_cast <const uint8*> (preallocatedData.asBytes))
|
||||
delete[] data;
|
||||
freeData();
|
||||
}
|
||||
|
||||
int MidiMessage::getChannel() const noexcept
|
||||
|
|
|
|||
|
|
@ -106,6 +106,11 @@ public:
|
|||
/** Copies this message from another one. */
|
||||
MidiMessage& operator= (const MidiMessage& other);
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
MidiMessage (MidiMessage&& other) noexcept;
|
||||
MidiMessage& operator= (MidiMessage&& other) noexcept;
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
/** Returns a pointer to the raw midi data.
|
||||
|
||||
|
|
@ -926,6 +931,10 @@ private:
|
|||
uint32 asInt32;
|
||||
} preallocatedData;
|
||||
#endif
|
||||
|
||||
void freeData() noexcept;
|
||||
void setToUseInternalData() noexcept;
|
||||
bool usesAllocatedData() const noexcept;
|
||||
};
|
||||
|
||||
#endif // __JUCE_MIDIMESSAGE_JUCEHEADER__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue