Add copy constructors to page classes
This commit is contained in:
@@ -34,6 +34,21 @@ LevelOnePage::LevelOnePage()
|
||||
clearPage();
|
||||
}
|
||||
|
||||
LevelOnePage::LevelOnePage(const PageBase &other)
|
||||
{
|
||||
m_paddingX26Triplet.setAddress(41);
|
||||
m_paddingX26Triplet.setMode(0x1e);
|
||||
m_paddingX26Triplet.setData(0);
|
||||
localEnhance.reserve(208);
|
||||
clearPage();
|
||||
|
||||
for (int i=0; i<8; i++)
|
||||
setControlBit(i, other.controlBit(i));
|
||||
for (int i=0; i<90; i++)
|
||||
if (other.packetNeededArrayIndex(i))
|
||||
setPacketArrayIndex(i, other.packetArrayIndex(i));
|
||||
}
|
||||
|
||||
// So far we only call clearPage() once, within the constructor
|
||||
void LevelOnePage::clearPage()
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
enum CycleTypeEnum { CTcycles, CTseconds };
|
||||
|
||||
LevelOnePage();
|
||||
LevelOnePage(const PageBase &);
|
||||
|
||||
QByteArray packet(int, int=0);
|
||||
bool setPacket(int, QByteArray);
|
||||
|
||||
68
pagebase.cpp
68
pagebase.cpp
@@ -32,6 +32,17 @@ PageBase::PageBase()
|
||||
m_controlBits[i] = false;
|
||||
}
|
||||
|
||||
PageBase::PageBase(const PageBase &other)
|
||||
{
|
||||
setPageFunction(other.pageFunction());
|
||||
setPacketCoding(other.packetCoding());
|
||||
for (int i=0; i<8; i++)
|
||||
setControlBit(i, other.controlBit(i));
|
||||
for (int i=0; i<90; i++)
|
||||
if (other.packetNeededArrayIndex(i))
|
||||
setPacketArrayIndex(i, other.packetArrayIndex(i));
|
||||
}
|
||||
|
||||
PageBase::~PageBase()
|
||||
{
|
||||
for (int i=0; i<90; i++)
|
||||
@@ -41,22 +52,32 @@ PageBase::~PageBase()
|
||||
|
||||
QByteArray PageBase::packet(int packetNumber, int designationCode) const
|
||||
{
|
||||
int packetArrayIndex = packetNumber;
|
||||
int arrayIndex = packetNumber;
|
||||
|
||||
if (packetNumber >= 26)
|
||||
packetArrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
if (m_packets[packetArrayIndex] == nullptr)
|
||||
arrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
return packetArrayIndex(arrayIndex);
|
||||
}
|
||||
|
||||
QByteArray PageBase::packetArrayIndex(int arrayIndex) const
|
||||
{
|
||||
if (m_packets[arrayIndex] == nullptr)
|
||||
return QByteArray(); // Blank result
|
||||
return *m_packets[packetArrayIndex];
|
||||
return *m_packets[arrayIndex];
|
||||
}
|
||||
|
||||
bool PageBase::packetNeeded(int packetNumber, int designationCode) const
|
||||
{
|
||||
int packetArrayIndex = packetNumber;
|
||||
int arrayIndex = packetNumber;
|
||||
|
||||
if (packetNumber >= 26)
|
||||
packetArrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
return m_packets[packetArrayIndex] != nullptr;
|
||||
arrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
return packetNeededArrayIndex(arrayIndex);
|
||||
}
|
||||
|
||||
bool PageBase::packetNeededArrayIndex(int arrayIndex) const
|
||||
{
|
||||
return m_packets[arrayIndex] != nullptr;
|
||||
}
|
||||
|
||||
bool PageBase::setPacket(int packetNumber, QByteArray packetContents)
|
||||
@@ -66,26 +87,37 @@ bool PageBase::setPacket(int packetNumber, QByteArray packetContents)
|
||||
|
||||
bool PageBase::setPacket(int packetNumber, int designationCode, QByteArray packetContents)
|
||||
{
|
||||
int packetArrayIndex = packetNumber;
|
||||
int arrayIndex = packetNumber;
|
||||
|
||||
if (packetNumber >= 26)
|
||||
packetArrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
if (m_packets[packetArrayIndex] == nullptr)
|
||||
m_packets[packetArrayIndex] = new QByteArray(40, 0x00);
|
||||
*m_packets[packetArrayIndex] = packetContents;
|
||||
arrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
return setPacketArrayIndex(arrayIndex, packetContents);
|
||||
}
|
||||
|
||||
bool PageBase::setPacketArrayIndex(int arrayIndex, QByteArray packetContents)
|
||||
{
|
||||
if (m_packets[arrayIndex] == nullptr)
|
||||
m_packets[arrayIndex] = new QByteArray(40, 0x00);
|
||||
*m_packets[arrayIndex] = packetContents;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PageBase::deletePacket(int packetNumber, int designationCode)
|
||||
{
|
||||
int packetArrayIndex = packetNumber;
|
||||
int arrayIndex = packetNumber;
|
||||
|
||||
if (packetNumber >= 26)
|
||||
packetArrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
if (m_packets[packetArrayIndex] != nullptr) {
|
||||
delete m_packets[packetArrayIndex];
|
||||
m_packets[packetArrayIndex] = nullptr;
|
||||
arrayIndex += (packetNumber - 26) * 16 + designationCode;
|
||||
|
||||
return deletePacketArrayIndex(arrayIndex);
|
||||
}
|
||||
|
||||
bool PageBase::deletePacketArrayIndex(int arrayIndex)
|
||||
{
|
||||
if (m_packets[arrayIndex] != nullptr) {
|
||||
delete m_packets[arrayIndex];
|
||||
m_packets[arrayIndex] = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -97,7 +129,7 @@ bool PageBase::setControlBit(int bitNumber, bool active)
|
||||
return true;
|
||||
}
|
||||
|
||||
PageBase::PacketCodingEnum PageBase::packetCoding(int packetNumber, int designationCode) const
|
||||
PageBase::PacketCodingEnum PageBase::packetCoding(int packetNumber) const
|
||||
{
|
||||
switch (packetNumber) {
|
||||
case 26:
|
||||
|
||||
@@ -34,19 +34,26 @@ public:
|
||||
enum PacketCodingEnum { PC7bit, PC8bit, PC18bit, PC4bit, PC4bit7bit, PCMixed };
|
||||
|
||||
PageBase();
|
||||
PageBase(const PageBase &);
|
||||
~PageBase();
|
||||
|
||||
QByteArray packet(int, int=0) const;
|
||||
bool packetNeeded(int, int=0) const;
|
||||
bool setPacket(int, QByteArray);
|
||||
bool setPacket(int, int, QByteArray);
|
||||
bool deletePacket(int, int=0);
|
||||
|
||||
QByteArray packetArrayIndex(int) const;
|
||||
bool packetNeededArrayIndex(int) const;
|
||||
bool setPacketArrayIndex(int, QByteArray);
|
||||
bool deletePacketArrayIndex(int);
|
||||
|
||||
bool controlBit(int bitNumber) const { return m_controlBits[bitNumber]; }
|
||||
bool setControlBit(int, bool);
|
||||
|
||||
PageFunctionEnum pageFunction() const { return m_pageFunction; }
|
||||
bool setPageFunction(PageFunctionEnum);
|
||||
PacketCodingEnum packetCoding(int=0, int=0) const;
|
||||
PacketCodingEnum packetCoding(int=0) const;
|
||||
bool setPacketCoding(PacketCodingEnum);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user