mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 16:01:20 +02:00
CListHelpers: allow UpDownKey with int type, too
This commit is contained in:
@@ -24,10 +24,10 @@
|
|||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <gui/bouquetlist.h>
|
#include <gui/bouquetlist.h>
|
||||||
|
|
||||||
template <class T> int CListHelpers::UpDownKey(T list, neutrino_msg_t msg, int lines, int sel)
|
static int upDownKey(int size, neutrino_msg_t msg, int lines, int sel)
|
||||||
{
|
{
|
||||||
int step;
|
int step;
|
||||||
if (list.empty())
|
if (size <= 0) /* list.empty() or similar... */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (msg >= CRCInput::RC_MaxRC) {
|
if (msg >= CRCInput::RC_MaxRC) {
|
||||||
@@ -47,7 +47,6 @@ template <class T> int CListHelpers::UpDownKey(T list, neutrino_msg_t msg, int l
|
|||||||
printf("CListHelpers:%s: invalid key? 0x%lx\n", __func__, msg);
|
printf("CListHelpers:%s: invalid key? 0x%lx\n", __func__, msg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int size = (int)list.size(); /* bigger than 0, because we checked for empty() before */
|
|
||||||
// printf("CListHelpers:%s: key 0x%04lx lines %d size %d sel %d\n", __func__, msg, lines, size, sel);
|
// printf("CListHelpers:%s: key 0x%04lx lines %d size %d sel %d\n", __func__, msg, lines, size, sel);
|
||||||
int new_sel = sel + step;
|
int new_sel = sel + step;
|
||||||
if (new_sel < 0) {
|
if (new_sel < 0) {
|
||||||
@@ -65,8 +64,20 @@ template <class T> int CListHelpers::UpDownKey(T list, neutrino_msg_t msg, int l
|
|||||||
return new_sel;
|
return new_sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CListHelpers::_UpDownKey(int size, neutrino_msg_t msg, int lines, int sel, _id<int>)
|
||||||
|
{
|
||||||
|
return upDownKey(size, msg, lines, sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> int CListHelpers::_UpDownKey(T list, neutrino_msg_t msg, int lines, int sel, _id<T>)
|
||||||
|
{
|
||||||
|
return upDownKey(list.size(), msg, lines, sel);
|
||||||
|
}
|
||||||
|
|
||||||
/* all used versions need to be prototyped here, to avoid linker errors */
|
/* all used versions need to be prototyped here, to avoid linker errors */
|
||||||
template int CListHelpers::UpDownKey<std::vector<CBouquet*> >(std::vector<CBouquet*>, neutrino_msg_t, int, int);
|
/* helper macro for the prototypes */
|
||||||
template int CListHelpers::UpDownKey<std::vector<CZapitBouquet*> >(std::vector<CZapitBouquet*>, neutrino_msg_t, int, int);
|
#define updown_t(x) template int CListHelpers::_UpDownKey<x >(x, neutrino_msg_t, int, int, _id<x >)
|
||||||
template int CListHelpers::UpDownKey<std::vector<CZapitChannel*> >(std::vector<CZapitChannel*>, neutrino_msg_t, int, int);
|
updown_t(std::vector<CBouquet*>);
|
||||||
template int CListHelpers::UpDownKey<std::vector<CChannelEvent> >(std::vector<CChannelEvent>, neutrino_msg_t, int, int);
|
updown_t(std::vector<CZapitBouquet*>);
|
||||||
|
updown_t(std::vector<CZapitChannel*>);
|
||||||
|
updown_t(std::vector<CChannelEvent>);
|
||||||
|
@@ -21,10 +21,18 @@
|
|||||||
|
|
||||||
#ifndef __LISTHELPERS__
|
#ifndef __LISTHELPERS__
|
||||||
#define __LISTHELPERS__
|
#define __LISTHELPERS__
|
||||||
|
/* allow to trick the compiler into overriding template definitions */
|
||||||
|
template<typename T> struct _id { typedef T type; };
|
||||||
|
|
||||||
class CListHelpers
|
class CListHelpers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template <class T> int UpDownKey(T list, neutrino_msg_t k, int lines, int sel);
|
template <typename T> int UpDownKey(T list, neutrino_msg_t k, int lines, int sel) {
|
||||||
|
return _UpDownKey(list, k, lines, sel, _id<T>());
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
/* stackoverflow.com/questions/3052579 */
|
||||||
|
template <typename T> int _UpDownKey(T list, neutrino_msg_t k, int lines, int sel, _id<T>);
|
||||||
|
int _UpDownKey(int list, neutrino_msg_t k, int lines, int sel, _id<int>);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user