everything's a smart pointer

pull/1/head
Tom Early 5 years ago
parent 62e0b18c82
commit acfb479770

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2030 Thomas A. Early N7TAE
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,34 +36,12 @@ const unsigned int NUM_OF_STATES = 16U;
const uint32_t M = 2U; const uint32_t M = 2U;
const unsigned int K = 5U; const unsigned int K = 5U;
CYSFConvolution::CYSFConvolution() : CYSFConvolution::CYSFConvolution() : m_oldMetrics(m_metrics1), m_newMetrics(m_metrics2), m_dp(m_decisions) {}
m_metrics1(nullptr),
m_metrics2(nullptr),
m_oldMetrics(nullptr),
m_newMetrics(nullptr),
m_decisions(nullptr),
m_dp(nullptr)
{
m_metrics1 = new uint16_t[16U];
m_metrics2 = new uint16_t[16U];
m_decisions = new uint64_t[180U];
}
CYSFConvolution::~CYSFConvolution()
{
delete[] m_metrics1;
delete[] m_metrics2;
delete[] m_decisions;
}
void CYSFConvolution::start() void CYSFConvolution::start()
{ {
::memset(m_metrics1, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); for (int i=0; i<16; i++)
::memset(m_metrics2, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); m_metrics1[i] = m_metrics2[i] = 0U;
m_oldMetrics = m_metrics1;
m_newMetrics = m_metrics2;
m_dp = m_decisions;
} }
void CYSFConvolution::decode(uint8_t s0, uint8_t s1) void CYSFConvolution::decode(uint8_t s0, uint8_t s1)

@ -27,7 +27,6 @@ class CYSFConvolution
{ {
public: public:
CYSFConvolution(); CYSFConvolution();
~CYSFConvolution();
void start(); void start();
void decode(uint8_t s0, uint8_t s1); void decode(uint8_t s0, uint8_t s1);
@ -36,13 +35,12 @@ public:
void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const; void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const;
private: private:
uint16_t* m_metrics1; uint16_t m_metrics1[16];
uint16_t* m_metrics2; uint16_t m_metrics2[16];
uint16_t* m_oldMetrics; uint16_t* m_oldMetrics;
uint16_t* m_newMetrics; uint16_t* m_newMetrics;
uint64_t* m_decisions; uint64_t m_decisions[180];
uint64_t* m_dp; uint64_t* m_dp;
}; };
#endif #endif

@ -35,11 +35,11 @@ const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U
const unsigned int INTERLEAVE_TABLE[] = const unsigned int INTERLEAVE_TABLE[] =
{ {
0U, 40U, 80U, 120U, 160U, 0U, 40U, 80U, 120U, 160U,
2U, 42U, 82U, 122U, 162U, 2U, 42U, 82U, 122U, 162U,
4U, 44U, 84U, 124U, 164U, 4U, 44U, 84U, 124U, 164U,
6U, 46U, 86U, 126U, 166U, 6U, 46U, 86U, 126U, 166U,
8U, 48U, 88U, 128U, 168U, 8U, 48U, 88U, 128U, 168U,
10U, 50U, 90U, 130U, 170U, 10U, 50U, 90U, 130U, 170U,
12U, 52U, 92U, 132U, 172U, 12U, 52U, 92U, 132U, 172U,
14U, 54U, 94U, 134U, 174U, 14U, 54U, 94U, 134U, 174U,
@ -57,18 +57,11 @@ const unsigned int INTERLEAVE_TABLE[] =
38U, 78U, 118U, 158U, 198U 38U, 78U, 118U, 158U, 198U
}; };
CYSFFICH::CYSFFICH() : CYSFFICH::CYSFFICH()
m_fich(nullptr)
{ {
m_fich = new unsigned char[6U];
::memset(m_fich, 0U, 6U); ::memset(m_fich, 0U, 6U);
} }
CYSFFICH::~CYSFFICH()
{
delete[] m_fich;
}
bool CYSFFICH::decode(const unsigned char* bytes) bool CYSFFICH::decode(const unsigned char* bytes)
{ {
assert(bytes != nullptr); assert(bytes != nullptr);

@ -24,7 +24,6 @@ class CYSFFICH
{ {
public: public:
CYSFFICH(); CYSFFICH();
~CYSFFICH();
bool decode(const unsigned char* bytes); bool decode(const unsigned char* bytes);
@ -60,7 +59,7 @@ public:
void load(const unsigned char* fich); void load(const unsigned char* fich);
private: private:
unsigned char* m_fich; unsigned char m_fich[6];
}; };
#endif #endif

@ -26,11 +26,11 @@
const unsigned int INTERLEAVE_TABLE_9_20[] = const unsigned int INTERLEAVE_TABLE_9_20[] =
{ {
0U, 40U, 80U, 120U, 160U, 200U, 240U, 280U, 320U, 0U, 40U, 80U, 120U, 160U, 200U, 240U, 280U, 320U,
2U, 42U, 82U, 122U, 162U, 202U, 242U, 282U, 322U, 2U, 42U, 82U, 122U, 162U, 202U, 242U, 282U, 322U,
4U, 44U, 84U, 124U, 164U, 204U, 244U, 284U, 324U, 4U, 44U, 84U, 124U, 164U, 204U, 244U, 284U, 324U,
6U, 46U, 86U, 126U, 166U, 206U, 246U, 286U, 326U, 6U, 46U, 86U, 126U, 166U, 206U, 246U, 286U, 326U,
8U, 48U, 88U, 128U, 168U, 208U, 248U, 288U, 328U, 8U, 48U, 88U, 128U, 168U, 208U, 248U, 288U, 328U,
10U, 50U, 90U, 130U, 170U, 210U, 250U, 290U, 330U, 10U, 50U, 90U, 130U, 170U, 210U, 250U, 290U, 330U,
12U, 52U, 92U, 132U, 172U, 212U, 252U, 292U, 332U, 12U, 52U, 92U, 132U, 172U, 212U, 252U, 292U, 332U,
14U, 54U, 94U, 134U, 174U, 214U, 254U, 294U, 334U, 14U, 54U, 94U, 134U, 174U, 214U, 254U, 294U, 334U,
@ -50,11 +50,11 @@ const unsigned int INTERLEAVE_TABLE_9_20[] =
const unsigned int INTERLEAVE_TABLE_5_20[] = const unsigned int INTERLEAVE_TABLE_5_20[] =
{ {
0U, 40U, 80U, 120U, 160U, 0U, 40U, 80U, 120U, 160U,
2U, 42U, 82U, 122U, 162U, 2U, 42U, 82U, 122U, 162U,
4U, 44U, 84U, 124U, 164U, 4U, 44U, 84U, 124U, 164U,
6U, 46U, 86U, 126U, 166U, 6U, 46U, 86U, 126U, 166U,
8U, 48U, 88U, 128U, 168U, 8U, 48U, 88U, 128U, 168U,
10U, 50U, 90U, 130U, 170U, 10U, 50U, 90U, 130U, 170U,
12U, 52U, 92U, 132U, 172U, 12U, 52U, 92U, 132U, 172U,
14U, 54U, 94U, 134U, 174U, 14U, 54U, 94U, 134U, 174U,
@ -73,31 +73,15 @@ const unsigned int INTERLEAVE_TABLE_5_20[] =
}; };
// This one differs from the others in that it interleaves bits and not dibits // This one differs from the others in that it interleaves bits and not dibits
const unsigned char WHITENING_DATA[] = {0x93U, 0xD7U, 0x51U, 0x21U, 0x9CU, 0x2FU, 0x6CU, 0xD0U, 0xEFU, 0x0FU, const unsigned char WHITENING_DATA[] = {
0xF8U, 0x3DU, 0xF1U, 0x73U, 0x20U, 0x94U, 0xEDU, 0x1EU, 0x7CU, 0xD8U 0x93U, 0xD7U, 0x51U, 0x21U, 0x9CU, 0x2FU, 0x6CU, 0xD0U, 0xEFU, 0x0FU, 0xF8U, 0x3DU, 0xF1U, 0x73U, 0x20U, 0x94U, 0xEDU, 0x1EU, 0x7CU, 0xD8U
}; };
const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U };
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
CYSFPayload::CYSFPayload() :
m_uplink(nullptr),
m_downlink(nullptr),
m_source(nullptr),
m_dest(nullptr)
{
}
CYSFPayload::~CYSFPayload()
{
delete[] m_uplink;
delete[] m_downlink;
delete[] m_source;
delete[] m_dest;
}
bool CYSFPayload::processHeaderData(unsigned char* data) bool CYSFPayload::processHeaderData(unsigned char* data)
{ {
assert(data != nullptr); assert(data != nullptr);
@ -140,14 +124,14 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
if (m_dest == nullptr) if (m_dest == nullptr)
{ {
m_dest = new unsigned char[YSF_CALLSIGN_LENGTH]; m_dest = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
::memcpy(m_dest, output + 0U, YSF_CALLSIGN_LENGTH); ::memcpy(m_dest.get(), output, YSF_CALLSIGN_LENGTH);
} }
if (m_source == nullptr) if (m_source == nullptr)
{ {
m_source = new unsigned char[YSF_CALLSIGN_LENGTH]; m_source = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
::memcpy(m_source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH); ::memcpy(m_source.get(), output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH);
} }
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
@ -217,11 +201,11 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
if (m_downlink != nullptr) if (m_downlink)
::memcpy(output + 0U, m_downlink, YSF_CALLSIGN_LENGTH); ::memcpy(output + 0U, m_downlink.get(), YSF_CALLSIGN_LENGTH);
if (m_uplink != nullptr) if (m_uplink)
::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink, YSF_CALLSIGN_LENGTH); ::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink.get(), YSF_CALLSIGN_LENGTH);
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
@ -618,7 +602,7 @@ void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* d
void CYSFPayload::setUplink(const std::string& callsign) void CYSFPayload::setUplink(const std::string& callsign)
{ {
m_uplink = new unsigned char[YSF_CALLSIGN_LENGTH]; m_uplink = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
std::string uplink = callsign; std::string uplink = callsign;
uplink.resize(YSF_CALLSIGN_LENGTH, ' '); uplink.resize(YSF_CALLSIGN_LENGTH, ' ');
@ -629,7 +613,7 @@ void CYSFPayload::setUplink(const std::string& callsign)
void CYSFPayload::setDownlink(const std::string& callsign) void CYSFPayload::setDownlink(const std::string& callsign)
{ {
m_downlink = new unsigned char[YSF_CALLSIGN_LENGTH]; m_downlink = std::unique_ptr<unsigned char[]>(new unsigned char[YSF_CALLSIGN_LENGTH]);
std::string downlink = callsign; std::string downlink = callsign;
downlink.resize(YSF_CALLSIGN_LENGTH, ' '); downlink.resize(YSF_CALLSIGN_LENGTH, ' ');
@ -643,7 +627,7 @@ std::string CYSFPayload::getSource()
std::string tmp; std::string tmp;
if (m_dest) if (m_dest)
tmp.assign((const char *)m_source, YSF_CALLSIGN_LENGTH); tmp.assign((const char *)m_source.get(), YSF_CALLSIGN_LENGTH);
else else
tmp = ""; tmp = "";
@ -655,7 +639,7 @@ std::string CYSFPayload::getDest()
std::string tmp; std::string tmp;
if (m_dest) if (m_dest)
tmp.assign((const char *)m_dest, YSF_CALLSIGN_LENGTH); tmp.assign((const char *)m_dest.get(), YSF_CALLSIGN_LENGTH);
else else
tmp = ""; tmp = "";
@ -664,9 +648,6 @@ std::string CYSFPayload::getDest()
void CYSFPayload::reset() void CYSFPayload::reset()
{ {
delete[] m_source; m_source.reset();
delete[] m_dest; m_dest.reset();
m_source = nullptr;
m_dest = nullptr;
} }

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2020 Thomas A. Early
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,13 +21,11 @@
#define YSFPayload_H #define YSFPayload_H
#include <string> #include <string>
#include <memory>
class CYSFPayload class CYSFPayload
{ {
public: public:
CYSFPayload();
~CYSFPayload();
bool processHeaderData(unsigned char* bytes); bool processHeaderData(unsigned char* bytes);
void writeVDMode2Data(unsigned char* data, const unsigned char* dt); void writeVDMode2Data(unsigned char* data, const unsigned char* dt);
@ -49,10 +48,10 @@ public:
void reset(); void reset();
private: private:
unsigned char* m_uplink; std::unique_ptr<unsigned char[]> m_uplink;
unsigned char* m_downlink; std::unique_ptr<unsigned char[]> m_downlink;
unsigned char* m_source; std::unique_ptr<unsigned char[]> m_source;
unsigned char* m_dest; std::unique_ptr<unsigned char[]> m_dest;
}; };
#endif #endif

Loading…
Cancel
Save

Powered by TurnKey Linux.