diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-05-25 19:04:57 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-05-25 19:04:57 +0200 |
commit | 0b647385bb6e379c253099b32692f867fe1bd428 (patch) | |
tree | a5355f61bf8a91c7e52f2a1fcb0e50e70bf522df /src/MuxElements.cpp | |
parent | f470de09c4215c39387fbe6d85330c90fecea10d (diff) | |
download | dabmux-0b647385bb6e379c253099b32692f867fe1bd428.tar.gz dabmux-0b647385bb6e379c253099b32692f867fe1bd428.tar.bz2 dabmux-0b647385bb6e379c253099b32692f867fe1bd428.zip |
Simplify DAB label handling
The DabLabel object only save the label in the unpadded form,
and handle padding with spaces at the time of usage.
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r-- | src/MuxElements.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 65045db..a452220 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -24,6 +24,7 @@ */ #include <vector> +#include <algorithm> #include "MuxElements.h" #include <boost/algorithm/string.hpp> @@ -46,12 +47,9 @@ using namespace std; int DabLabel::setLabel(const std::string& label) { size_t len = label.length(); - if (len > sizeof(m_text)) + if (len > DABLABEL_LENGTH) return -3; - memcpy(m_text, label.c_str(), len); - memset(m_text + len, 0x20, sizeof(m_text) - len); - m_flag = 0xFF00; // truncate the label to the eight first characters m_label = label; @@ -73,7 +71,6 @@ int DabLabel::setLabel(const std::string& label, const std::string& short_label) return flag; // short label is valid. - memcpy(m_text, newlabel.m_text, sizeof(m_text)); m_flag = flag & 0xFFFF; m_label = newlabel.m_label; @@ -105,8 +102,8 @@ int DabLabel::setShortLabel(const std::string& slabel) /* Iterate over the label and set the bits in the flag * according to the characters in the slabel */ - for (int i = 0; i < 32; ++i) { - if (*slab == m_text[i]) { + for (size_t i = 0; i < m_label.size(); ++i) { + if (*slab == m_label[i]) { flag |= 0x8000 >> i; if (*(++slab) == 0) { break; @@ -118,7 +115,7 @@ int DabLabel::setShortLabel(const std::string& slabel) * we went through the whole label, the short label * cannot be represented */ - if (*slab != 0) { + if (*slab != '\0') { return -1; } @@ -139,15 +136,22 @@ int DabLabel::setShortLabel(const std::string& slabel) const string DabLabel::short_label() const { stringstream shortlabel; - for (int i = 0; i < 32; ++i) { + for (size_t i = 0; i < m_label.size(); ++i) { if (m_flag & 0x8000 >> i) { - shortlabel << m_text[i]; + shortlabel << m_label[i]; } } return shortlabel.str(); } +void DabLabel::writeLabel(uint8_t* buf) const +{ + memset(buf, ' ', DABLABEL_LENGTH); + if (m_label.size() <= DABLABEL_LENGTH) { + std::copy(m_label.begin(), m_label.end(), (char*)buf); + } +} vector<dabSubchannel*>::iterator getSubchannel( vector<dabSubchannel*>& subchannels, int id) |