From 2c7f4fc3c2ad7476fb443491744e094f091e3fb8 Mon Sep 17 00:00:00 2001
From: Karl Dietz <dekarl@mythtv.org>
Date: Sun, 14 Apr 2013 22:11:39 +0200
Subject: [PATCH 01/21] remove duplication and magic numbers in category types
inspired by Rick Scott and Stuart Morgan
Refs #11525
---
mythtv/libs/libmyth/programinfo.cpp | 14 +++++---------
mythtv/libs/libmyth/programinfo.h | 6 ++++--
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/mythtv/libs/libmyth/programinfo.cpp b/mythtv/libs/libmyth/programinfo.cpp
index 968a85c..d7afa4e 100644
a
|
b
|
static void set_flag(uint32_t &flags, int flag_to_set, bool is_set) |
81 | 81 | flags |= flag_to_set; |
82 | 82 | } |
83 | 83 | |
| 84 | static const char *ProgramInfo::cattype[] = |
| 85 | { "", "movie", "series", "sports", "tvshow", }; |
| 86 | |
84 | 87 | QString myth_category_type_to_string(ProgramInfo::CategoryType category_type) |
85 | 88 | { |
86 | | static int NUM_CAT_TYPES = 5; |
87 | | static const char *cattype[] = |
88 | | { "", "movie", "series", "sports", "tvshow", }; |
89 | | |
90 | 89 | if ((category_type > ProgramInfo::kCategoryNone) && |
91 | | ((int)category_type < NUM_CAT_TYPES)) |
| 90 | ((int)category_type < ProgramInfo::kCategoryCount)) |
92 | 91 | return QString(cattype[category_type]); |
93 | 92 | |
94 | 93 | return ""; |
… |
… |
QString myth_category_type_to_string(ProgramInfo::CategoryType category_type) |
96 | 95 | |
97 | 96 | ProgramInfo::CategoryType string_to_myth_category_type(const QString &category_type) |
98 | 97 | { |
99 | | static int NUM_CAT_TYPES = 5; |
100 | | static const char *cattype[] = |
101 | | { "", "movie", "series", "sports", "tvshow", }; |
102 | 98 | |
103 | | for (uint i = 1; i < NUM_CAT_TYPES; i++) |
| 99 | for (uint i = 1; i < ProgramInfo::kCategoryCount; i++) |
104 | 100 | if (category_type == cattype[i]) |
105 | 101 | return (ProgramInfo::CategoryType) i; |
106 | 102 | return ProgramInfo::kCategoryNone; |
diff --git a/mythtv/libs/libmyth/programinfo.h b/mythtv/libs/libmyth/programinfo.h
index 6e8e263..92064fd 100644
a
|
b
|
class MPUBLIC ProgramInfo |
73 | 73 | { |
74 | 74 | friend int pginfo_init_statics(void); |
75 | 75 | public: |
76 | | enum CategoryType { kCategoryNone, kCategoryMovie, kCategorySeries, |
77 | | kCategorySports, kCategoryTVShow }; |
| 76 | enum CategoryType { kCategoryNone = 0, kCategoryMovie, kCategorySeries, |
| 77 | kCategorySports, kCategoryTVShow, kCategoryCount }; |
78 | 78 | |
79 | 79 | /// Null constructor |
80 | 80 | ProgramInfo(void); |
… |
… |
class MPUBLIC ProgramInfo |
734 | 734 | static QMutex staticDataLock; |
735 | 735 | static ProgramInfoUpdater *updater; |
736 | 736 | static bool usingProgIDAuth; |
| 737 | |
| 738 | static const char *ProgramInfo::cattype[]; ///< category type strings for conversion helpers |
737 | 739 | }; |
738 | 740 | |
739 | 741 | |