Ticket #11525: 0001-remove-duplication-and-magic-numbers-in-category-typ.patch

File 0001-remove-duplication-and-magic-numbers-in-category-typ.patch, 2.7 KB (added by Karl Egly, 11 years ago)

a variation on the patch

  • mythtv/libs/libmyth/programinfo.cpp

    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) 
    8181        flags |= flag_to_set;
    8282}
    8383
     84static const char *ProgramInfo::cattype[] =
     85    { "", "movie", "series", "sports", "tvshow", };
     86
    8487QString myth_category_type_to_string(ProgramInfo::CategoryType category_type)
    8588{
    86     static int NUM_CAT_TYPES = 5;
    87     static const char *cattype[] =
    88         { "", "movie", "series", "sports", "tvshow", };
    89 
    9089    if ((category_type > ProgramInfo::kCategoryNone) &&
    91         ((int)category_type < NUM_CAT_TYPES))
     90        ((int)category_type < ProgramInfo::kCategoryCount))
    9291        return QString(cattype[category_type]);
    9392
    9493    return "";
    QString myth_category_type_to_string(ProgramInfo::CategoryType category_type) 
    9695
    9796ProgramInfo::CategoryType string_to_myth_category_type(const QString &category_type)
    9897{
    99     static int NUM_CAT_TYPES = 5;
    100     static const char *cattype[] =
    101         { "", "movie", "series", "sports", "tvshow", };
    10298
    103     for (uint i = 1; i < NUM_CAT_TYPES; i++)
     99    for (uint i = 1; i < ProgramInfo::kCategoryCount; i++)
    104100        if (category_type == cattype[i])
    105101            return (ProgramInfo::CategoryType) i;
    106102    return ProgramInfo::kCategoryNone;
  • mythtv/libs/libmyth/programinfo.h

    diff --git a/mythtv/libs/libmyth/programinfo.h b/mythtv/libs/libmyth/programinfo.h
    index 6e8e263..92064fd 100644
    a b class MPUBLIC ProgramInfo 
    7373{
    7474    friend int pginfo_init_statics(void);
    7575  public:
    76     enum CategoryType { kCategoryNone, kCategoryMovie, kCategorySeries,
    77                         kCategorySports, kCategoryTVShow };
     76    enum CategoryType { kCategoryNone = 0, kCategoryMovie, kCategorySeries,
     77                        kCategorySports, kCategoryTVShow, kCategoryCount };
    7878                       
    7979    /// Null constructor
    8080    ProgramInfo(void);
    class MPUBLIC ProgramInfo 
    734734    static QMutex staticDataLock;
    735735    static ProgramInfoUpdater *updater;
    736736    static bool usingProgIDAuth;
     737
     738    static const char *ProgramInfo::cattype[]; ///< category type strings for conversion helpers
    737739};
    738740
    739741