| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <string> |
| 12 |
|
| 13 |
namespace PVR |
| 14 |
{ |
| 15 |
class CPVRChannelNumber |
| 16 |
{ |
| 17 |
public: |
| 18 |
CPVRChannelNumber() = default; |
| 19 |
|
| 20 |
constexpr CPVRChannelNumber(unsigned int iChannelNumber, unsigned int iSubChannelNumber) |
| 21 |
: m_iChannelNumber(iChannelNumber), m_iSubChannelNumber(iSubChannelNumber) {} |
| 22 |
|
| 23 |
constexpr bool operator ==(const CPVRChannelNumber& right) const |
| 24 |
{ |
| 25 |
return (m_iChannelNumber == right.m_iChannelNumber && |
| 26 |
m_iSubChannelNumber == right.m_iSubChannelNumber); |
| 27 |
} |
| 28 |
|
| 29 |
constexpr bool operator !=(const CPVRChannelNumber& right) const |
| 30 |
{ |
| 31 |
return !(*this == right); |
| 32 |
} |
| 33 |
|
| 34 |
constexpr bool operator <(const CPVRChannelNumber& right) const |
| 35 |
{ |
| 36 |
return m_iChannelNumber == right.m_iChannelNumber |
| 37 |
? m_iSubChannelNumber < right.m_iSubChannelNumber |
| 38 |
: m_iChannelNumber < right.m_iChannelNumber; |
| 39 |
} |
| 40 |
|
| 41 |
/*! |
| 42 |
* @brief Check whether this channel number is valid (main channel number > 0). |
| 43 |
* @return True if valid, false otherwise.. |
| 44 |
*/ |
| 45 |
constexpr bool IsValid() const { return m_iChannelNumber > 0; } |
| 46 |
|
| 47 |
/*! |
| 48 |
* @brief Set the primary channel number. |
| 49 |
* @return The channel number. |
| 50 |
*/ |
| 51 |
constexpr unsigned int GetChannelNumber() const |
| 52 |
{ |
| 53 |
return m_iChannelNumber; |
| 54 |
} |
| 55 |
|
| 56 |
/*! |
| 57 |
* @brief Set the sub channel number. |
| 58 |
* @return The sub channel number (ATSC). |
| 59 |
*/ |
| 60 |
constexpr unsigned int GetSubChannelNumber() const |
| 61 |
{ |
| 62 |
return m_iSubChannelNumber; |
| 63 |
} |
| 64 |
|
| 65 |
/*! |
| 66 |
* @brief The character used to separate channel and subchannel number. |
| 67 |
*/ |
| 68 |
static const char SEPARATOR; // '.' |
| 69 |
|
| 70 |
/*! |
| 71 |
* @brief Get a string representation for the channel number. |
| 72 |
* @return The formatted string in the form <channel>SEPARATOR<subchannel>. |
| 73 |
*/ |
| 74 |
std::string FormattedChannelNumber() const; |
| 75 |
|
| 76 |
/*! |
| 77 |
* @brief Get a string representation for the channel number that can be used for SortItems. |
| 78 |
* @return The sortable string in the form <channel> <subchannel>. |
| 79 |
*/ |
| 80 |
std::string SortableChannelNumber() const; |
| 81 |
|
| 82 |
private: |
| 83 |
std::string ToString(char separator) const; |
| 84 |
|
| 85 |
unsigned int m_iChannelNumber = 0; |
| 86 |
unsigned int m_iSubChannelNumber = 0; |
| 87 |
}; |
| 88 |
} |