Move from dynamically allocating arrays to fixed arrays
This should allow the page bass class to be copy constructed.
This commit is contained in:
@@ -23,98 +23,52 @@
|
|||||||
|
|
||||||
PageBase::PageBase()
|
PageBase::PageBase()
|
||||||
{
|
{
|
||||||
// We use nullptrs to keep track of allocated packets, so initialise them this way
|
|
||||||
for (int y=0; y<26; y++)
|
|
||||||
m_displayPackets[y] = nullptr;
|
|
||||||
for (int y=0; y<3; y++)
|
|
||||||
for (int d=0; d<16; d++)
|
|
||||||
m_designationPackets[y][d] = nullptr;
|
|
||||||
|
|
||||||
for (int b=PageBase::C4ErasePage; b<=PageBase::C14NOS; b++)
|
for (int b=PageBase::C4ErasePage; b<=PageBase::C14NOS; b++)
|
||||||
m_controlBits[b] = false;
|
m_controlBits[b] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PageBase::~PageBase()
|
|
||||||
{
|
|
||||||
for (int y=0; y<26; y++)
|
|
||||||
if (m_displayPackets[y] != nullptr)
|
|
||||||
delete m_displayPackets[y];
|
|
||||||
for (int y=0; y<3; y++)
|
|
||||||
for (int d=0; d<16; d++)
|
|
||||||
if (m_designationPackets[y][d] != nullptr)
|
|
||||||
delete m_designationPackets[y][d];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PageBase::isEmpty() const
|
bool PageBase::isEmpty() const
|
||||||
{
|
{
|
||||||
for (int y=0; y<26; y++)
|
for (int y=0; y<26; y++)
|
||||||
if (m_displayPackets[y] != nullptr)
|
if (!m_displayPackets[y].isEmpty())
|
||||||
return false;
|
return false;
|
||||||
for (int y=0; y<3; y++)
|
for (int y=0; y<3; y++)
|
||||||
for (int d=0; d<16; d++)
|
for (int d=0; d<16; d++)
|
||||||
if (m_designationPackets[y][d] != nullptr)
|
if (!m_designationPackets[y][d].isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray PageBase::packet(int y) const
|
|
||||||
{
|
|
||||||
if (m_displayPackets[y] == nullptr)
|
|
||||||
return QByteArray(); // Blank result
|
|
||||||
|
|
||||||
return *m_displayPackets[y];
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray PageBase::packet(int y, int d) const
|
|
||||||
{
|
|
||||||
if (m_designationPackets[y-26][d] == nullptr)
|
|
||||||
return QByteArray(); // Blank result
|
|
||||||
|
|
||||||
return *m_designationPackets[y-26][d];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool PageBase::setPacket(int y, QByteArray pkt)
|
bool PageBase::setPacket(int y, QByteArray pkt)
|
||||||
{
|
{
|
||||||
if (m_displayPackets[y] == nullptr)
|
m_displayPackets[y] = pkt;
|
||||||
m_displayPackets[y] = new QByteArray(40, 0x00);
|
|
||||||
*m_displayPackets[y] = pkt;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageBase::setPacket(int y, int d, QByteArray pkt)
|
bool PageBase::setPacket(int y, int d, QByteArray pkt)
|
||||||
{
|
{
|
||||||
if (m_designationPackets[y-26][d] == nullptr)
|
m_designationPackets[y-26][d] = pkt;
|
||||||
m_designationPackets[y-26][d] = new QByteArray(40, 0x00);
|
|
||||||
*m_designationPackets[y-26][d] = pkt;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool PageBase::clearPacket(int y)
|
bool PageBase::clearPacket(int y)
|
||||||
{
|
{
|
||||||
if (m_displayPackets[y] != nullptr) {
|
m_displayPackets[y] = QByteArray();
|
||||||
delete m_displayPackets[y];
|
|
||||||
m_displayPackets[y] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageBase::clearPacket(int y, int d)
|
bool PageBase::clearPacket(int y, int d)
|
||||||
{
|
{
|
||||||
if (m_designationPackets[y-26][d] != nullptr) {
|
m_designationPackets[y-26][d] = QByteArray();
|
||||||
delete m_designationPackets[y-26][d];
|
|
||||||
m_designationPackets[y-26][d] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubPage::clearAllPackets()
|
void PageBase::clearAllPackets()
|
||||||
{
|
{
|
||||||
for (int y=0; y<26; y++)
|
for (int y=0; y<26; y++)
|
||||||
clearPacket(y);
|
clearPacket(y);
|
||||||
@@ -122,7 +76,6 @@ void SubPage::clearAllPackets()
|
|||||||
for (int d=0; d<16; d++)
|
for (int d=0; d<16; d++)
|
||||||
clearPacket(y, d);
|
clearPacket(y, d);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
bool PageBase::setControlBit(int b, bool active)
|
bool PageBase::setControlBit(int b, bool active)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,26 +31,25 @@ public:
|
|||||||
enum ControlBitsEnum { C4ErasePage, C5Newsflash, C6Subtitle, C7SuppressHeader, C8Update, C9InterruptedSequence, C10InhibitDisplay, C11SerialMagazine, C12NOS, C13NOS, C14NOS };
|
enum ControlBitsEnum { C4ErasePage, C5Newsflash, C6Subtitle, C7SuppressHeader, C8Update, C9InterruptedSequence, C10InhibitDisplay, C11SerialMagazine, C12NOS, C13NOS, C14NOS };
|
||||||
|
|
||||||
PageBase();
|
PageBase();
|
||||||
virtual ~PageBase();
|
|
||||||
|
|
||||||
virtual bool isEmpty() const;
|
virtual bool isEmpty() const;
|
||||||
|
|
||||||
virtual QByteArray packet(int y) const;
|
virtual QByteArray packet(int y) const { return m_displayPackets[y]; }
|
||||||
virtual QByteArray packet(int y, int d) const;
|
virtual QByteArray packet(int y, int d) const { return m_designationPackets[y-26][d]; }
|
||||||
virtual bool packetExists(int y) const { return m_displayPackets[y] != nullptr; }
|
virtual bool setPacket(int y, QByteArray pkt);
|
||||||
virtual bool packetExists(int y, int d) const { return m_designationPackets[y-26][d] != nullptr; }
|
|
||||||
virtual bool setPacket(int y, QByteArray packet);
|
|
||||||
virtual bool setPacket(int y, int d, QByteArray pkt);
|
virtual bool setPacket(int y, int d, QByteArray pkt);
|
||||||
// bool clearPacket(int y);
|
virtual bool packetExists(int y) const { return !m_displayPackets[y].isEmpty(); }
|
||||||
// bool clearPacket(int y, int d);
|
virtual bool packetExists(int y, int d) const { return !m_designationPackets[y-26][d].isEmpty(); }
|
||||||
// void clearAllPackets();
|
bool clearPacket(int y);
|
||||||
|
bool clearPacket(int y, int d);
|
||||||
|
void clearAllPackets();
|
||||||
|
|
||||||
virtual bool controlBit(int b) const { return m_controlBits[b]; }
|
virtual bool controlBit(int b) const { return m_controlBits[b]; }
|
||||||
virtual bool setControlBit(int b, bool active);
|
virtual bool setControlBit(int b, bool active);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_controlBits[11];
|
bool m_controlBits[11];
|
||||||
QByteArray *m_displayPackets[26], *m_designationPackets[3][16];
|
QByteArray m_displayPackets[26], m_designationPackets[3][16];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user