From: APTX Date: Sun, 19 Jun 2011 15:59:37 +0000 (+0200) Subject: Add 5th byte of File FileFlag (FMask). X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=a5422ca073c97acf27c63c5e98176735984aa85f;p=anidbudpclient.git Add 5th byte of File FileFlag (FMask). This change uses enum type features from C++0x which should be available in at least 2 most recent major releases of MSVC&GCC. Modified QFlags & friends are added to handle enums with arbitrary types. The use and API did not change. --- diff --git a/anidbudpclient.pro b/anidbudpclient.pro index 5d00749..4995cc5 100644 --- a/anidbudpclient.pro +++ b/anidbudpclient.pro @@ -42,6 +42,7 @@ SOURCES += client.cpp \ HEADERS += client.h \ anidbudpclient_global.h \ + aniqflags.h \ abstractcommand.h \ authcommand.h \ rawcommand.h \ @@ -60,7 +61,7 @@ HEADERS += client.h \ clientqueuedcommandsmodel.h \ filerenamedelegate.h \ clientinterface.h \ - myliststate.h + myliststate.h CONV_HEADERS += include/AniDBUdpClient/Client \ include/AniDBUdpClient/AbstractCommand \ @@ -149,3 +150,4 @@ conv_headers.path = $${PREFIX}/include/AniDBUdpClient conv_headers.files = $$CONV_HEADERS INSTALLS += target headers conv_headers + diff --git a/anidbudpclient_global.h b/anidbudpclient_global.h index 7b04f03..35b9629 100644 --- a/anidbudpclient_global.h +++ b/anidbudpclient_global.h @@ -16,6 +16,8 @@ # define ANIDBUDPCLIENTSHARED_EXPORT Q_DECL_IMPORT #endif +#include "aniqflags.h" + namespace AniDBUdpClient { enum Error @@ -201,61 +203,73 @@ namespace AniDBUdpClient Q_ENUMS(Error IdlePolicy ReplyCode State FileState); namespace FileFlag { - enum FileFlag { - AniDBFileName = 0x00000001, - // Unused = 0x00000002, - // Unused = 0x00000004, - AiredDate = 0x00000008, - Description = 0x00000010, - LengthInSeconds = 0x00000020, - SubLanguage = 0x00000040, - DubLanguage = 0x00000080, - - FileType = 0x00000100, - VideoResolution = 0x00000200, - VideoBitrate = 0x00000400, - VideoCodec = 0x00000800, - AudioBitrate = 0x00001000, - AudioCodec = 0x00002000, - Source = 0x00004000, - Quality = 0x00008000, - - // Reserved = 0x00010000, - // Unused = 0x00020000, - // Unused = 0x00040000, - Crc32 = 0x00080000, - Sha1 = 0x00100000, - Md5 = 0x00200000, - Ed2k = 0x00400000, - Size = 0x00800000, - - State = 0x01000000, - IsDeprecated = 0x02000000, - OtherEpisodes = 0x04000000, - Lid = 0x08000000, - Gid = 0x10000000, - Eid = 0x20000000, - Aid = 0x40000000, - // Unused = 0x80000000, - - Extension = FileType, - - Byte4 = AniDBFileName | AiredDate | Description - | LengthInSeconds | SubLanguage | DubLanguage, - Byte3 = FileType | VideoResolution | VideoBitrate - | VideoCodec | AudioBitrate | AudioCodec - | Source | Quality, - Byte2 = Crc32 | Sha1 | Md5 | Ed2k, - Byte1 = State | IsDeprecated | OtherEpisodes - | Lid | Gid | Eid | Aid, - AllData = Byte1 | Byte2 | Byte3 | Byte4, - InvalidBits = ~AllData + enum FileFlag : quint64 + { + // Unused = Q_UINT64_C(0x0000000000000001), + MyListOther = Q_UINT64_C(0x0000000000000002), + MyListSource = Q_UINT64_C(0x0000000000000004), + MyListStorage = Q_UINT64_C(0x0000000000000008), + MyListViewDate = Q_UINT64_C(0x0000000000000010), + MyListViewed = Q_UINT64_C(0x0000000000000020), + MyListFileState = Q_UINT64_C(0x0000000000000040), + MyListState = Q_UINT64_C(0x0000000000000080), + + AniDBFileName = Q_UINT64_C(0x0000000000000100), + // Unused = Q_UINT64_C(0x0000000000000200), + // Unused = Q_UINT64_C(0x0000000000000400), + AiredDate = Q_UINT64_C(0x0000000000000800), + Description = Q_UINT64_C(0x0000000000001000), + LengthInSeconds = Q_UINT64_C(0x0000000000002000), + SubLanguage = Q_UINT64_C(0x0000000000004000), + DubLanguage = Q_UINT64_C(0x0000000000008000), + + FileType = Q_UINT64_C(0x0000000000010000), + VideoResolution = Q_UINT64_C(0x0000000000020000), + VideoBitrate = Q_UINT64_C(0x0000000000040000), + VideoCodec = Q_UINT64_C(0x0000000000080000), + AudioBitrate = Q_UINT64_C(0x0000000000100000), + AudioCodec = Q_UINT64_C(0x0000000000200000), + Source = Q_UINT64_C(0x0000000000400000), + Quality = Q_UINT64_C(0x0000000000800000), + + // Reserved = Q_UINT64_C(0x0000000001000000), + // Unused = Q_UINT64_C(0x0000000002000000), + // Unused = Q_UINT64_C(0x0000000004000000), + Crc32 = Q_UINT64_C(0x0000000008000000), + Sha1 = Q_UINT64_C(0x0000000010000000), + Md5 = Q_UINT64_C(0x0000000020000000), + Ed2k = Q_UINT64_C(0x0000000040000000), + Size = Q_UINT64_C(0x0000000080000000), + + State = Q_UINT64_C(0x0000000100000000), + IsDeprecated = Q_UINT64_C(0x0000000200000000), + OtherEpisodes = Q_UINT64_C(0x0000000400000000), + Lid = Q_UINT64_C(0x0000000800000000), + Gid = Q_UINT64_C(0x0000001000000000), + Eid = Q_UINT64_C(0x0000002000000000), + Aid = Q_UINT64_C(0x0000004000000000), + // Unused = Q_UINT64_C(0x0000008000000000), + + Extension = FileType, + + Byte5 = MyListOther | MyListSource | MyListStorage + | MyListViewDate | MyListViewed | MyListFileState + | MyListState, + Byte4 = AniDBFileName | AiredDate | Description + | LengthInSeconds | SubLanguage | DubLanguage, + Byte3 = FileType | VideoResolution | VideoBitrate + | VideoCodec | AudioBitrate | AudioCodec + | Source | Quality, + Byte2 = Crc32 | Sha1 | Md5 | Ed2k, + Byte1 = State | IsDeprecated | OtherEpisodes + | Lid | Gid | Eid | Aid, + AllData = Byte1 | Byte2 | Byte3 | Byte4 | Byte5, + InvalidBits = ~AllData, }; } - Q_FLAGS(FileFlag::FileFlag); - Q_DECLARE_FLAGS(FileFlags, FileFlag::FileFlag); - Q_DECLARE_OPERATORS_FOR_FLAGS(FileFlags); + AniQ_DECLARE_FLAGS(FileFlags, FileFlag::FileFlag, quint64) + AniQ_DECLARE_OPERATORS_FOR_FLAGS(FileFlags) typedef FileFlags FMask; namespace FileAnimeFlag { @@ -319,79 +333,80 @@ namespace AniDBUdpClient typedef FileAnimeFlags FileAMask; namespace AnimeFlag { - static const qint64 CategoryWeightList = Q_INT64_C(0x0000000000000001); - static const qint64 CategoryList = Q_INT64_C(0x0000000000000002); - static const qint64 RelatedAidType = Q_INT64_C(0x0000000000000004); - static const qint64 RelatedAidList = Q_INT64_C(0x0000000000000008); - static const qint64 Type = Q_INT64_C(0x0000000000000010); - static const qint64 Year = Q_INT64_C(0x0000000000000020); - // static const qint64 Unused = Q_INT64_C(0x0000000000000040); - static const qint64 Aid = Q_INT64_C(0x0000000000000080); - - // static const qint64 Retired = Q_INT64_C(0x0000000000000100); - // static const qint64 Retired = Q_INT64_C(0x0000000000000200); - static const qint64 SynonymList = Q_INT64_C(0x0000000000000400); - static const qint64 ShortNameList = Q_INT64_C(0x0000000000000800); - static const qint64 OtherName = Q_INT64_C(0x0000000000001000); - static const qint64 EnglishName = Q_INT64_C(0x0000000000002000); - static const qint64 KanjiName = Q_INT64_C(0x0000000000004000); - static const qint64 RomajiName = Q_INT64_C(0x0000000000008000); - - static const qint64 CategoryIdList = Q_INT64_C(0x0000000000010000); - static const qint64 PicName = Q_INT64_C(0x0000000000020000); - static const qint64 Url = Q_INT64_C(0x0000000000040000); - static const qint64 EndDate = Q_INT64_C(0x0000000000080000); - static const qint64 AirDate = Q_INT64_C(0x0000000000100000); - static const qint64 SpecialEpCount = Q_INT64_C(0x0000000000200000); - static const qint64 NormalEpCount = Q_INT64_C(0x0000000000400000); - static const qint64 Episodes = Q_INT64_C(0x0000000000800000); - - static const qint64 Is18Restricted = Q_INT64_C(0x0000000001000000); - static const qint64 AwardList = Q_INT64_C(0x0000000002000000); - static const qint64 ReviewCount = Q_INT64_C(0x0000000004000000); - static const qint64 AverageReviewRating = Q_INT64_C(0x0000000008000000); - static const qint64 TempVoteCount = Q_INT64_C(0x0000000010000000); - static const qint64 TempRating = Q_INT64_C(0x0000000020000000); - static const qint64 VoteCount = Q_INT64_C(0x0000000040000000); - static const qint64 Rating = Q_INT64_C(0x0000000080000000); - - static const qint64 DateRecordUpdated = Q_INT64_C(0x0000000100000000); - // static const qint64 Unused = Q_INT64_C(0x0000000200000000); - // static const qint64 Unused = Q_INT64_C(0x0000000400000000); - // static const qint64 Unused = Q_INT64_C(0x0000000800000000); - static const qint64 AniemNfoId = Q_INT64_C(0x0000001000000000); - static const qint64 AllCinemaId = Q_INT64_C(0x0000002000000000); - static const qint64 ANNId = Q_INT64_C(0x0000004000000000); - static const qint64 AnimePlanetId = Q_INT64_C(0x0000008000000000); - - // static const qint64 Unused = Q_INT64_C(0x0000010000000000); - // static const qint64 Unused = Q_INT64_C(0x0000020000000000); - // static const qint64 Unused = Q_INT64_C(0x0000040000000000); - // static const qint64 Unused = Q_INT64_C(0x0000080000000000); - static const qint64 ProducerNameList = Q_INT64_C(0x0000100000000000); - static const qint64 ProducerIdList = Q_INT64_C(0x0000200000000000); - static const qint64 CreatorIdList = Q_INT64_C(0x0000400000000000); - static const qint64 CharacterIdList = Q_INT64_C(0x0000800000000000); - - static const qint64 Byte1 = CategoryWeightList | CategoryList | RelatedAidType + typedef quint64 AnimeFlag; + static const AnimeFlag CategoryWeightList = Q_UINT64_C(0x0000000000000001); + static const AnimeFlag CategoryList = Q_UINT64_C(0x0000000000000002); + static const AnimeFlag RelatedAidType = Q_UINT64_C(0x0000000000000004); + static const AnimeFlag RelatedAidList = Q_UINT64_C(0x0000000000000008); + static const AnimeFlag Type = Q_UINT64_C(0x0000000000000010); + static const AnimeFlag Year = Q_UINT64_C(0x0000000000000020); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000000000000040); + static const AnimeFlag Aid = Q_UINT64_C(0x0000000000000080); + + // static const AnimeFlag Retired = Q_UINT64_C(0x0000000000000100); + // static const AnimeFlag Retired = Q_UINT64_C(0x0000000000000200); + static const AnimeFlag SynonymList = Q_UINT64_C(0x0000000000000400); + static const AnimeFlag ShortNameList = Q_UINT64_C(0x0000000000000800); + static const AnimeFlag OtherName = Q_UINT64_C(0x0000000000001000); + static const AnimeFlag EnglishName = Q_UINT64_C(0x0000000000002000); + static const AnimeFlag KanjiName = Q_UINT64_C(0x0000000000004000); + static const AnimeFlag RomajiName = Q_UINT64_C(0x0000000000008000); + + static const AnimeFlag CategoryIdList = Q_UINT64_C(0x0000000000010000); + static const AnimeFlag PicName = Q_UINT64_C(0x0000000000020000); + static const AnimeFlag Url = Q_UINT64_C(0x0000000000040000); + static const AnimeFlag EndDate = Q_UINT64_C(0x0000000000080000); + static const AnimeFlag AirDate = Q_UINT64_C(0x0000000000100000); + static const AnimeFlag SpecialEpCount = Q_UINT64_C(0x0000000000200000); + static const AnimeFlag NormalEpCount = Q_UINT64_C(0x0000000000400000); + static const AnimeFlag Episodes = Q_UINT64_C(0x0000000000800000); + + static const AnimeFlag Is18Restricted = Q_UINT64_C(0x0000000001000000); + static const AnimeFlag AwardList = Q_UINT64_C(0x0000000002000000); + static const AnimeFlag ReviewCount = Q_UINT64_C(0x0000000004000000); + static const AnimeFlag AverageReviewRating = Q_UINT64_C(0x0000000008000000); + static const AnimeFlag TempVoteCount = Q_UINT64_C(0x0000000010000000); + static const AnimeFlag TempRating = Q_UINT64_C(0x0000000020000000); + static const AnimeFlag VoteCount = Q_UINT64_C(0x0000000040000000); + static const AnimeFlag Rating = Q_UINT64_C(0x0000000080000000); + + static const AnimeFlag DateRecordUpdated = Q_UINT64_C(0x0000000100000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000000200000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000000400000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000000800000000); + static const AnimeFlag AniemNfoId = Q_UINT64_C(0x0000001000000000); + static const AnimeFlag AllCinemaId = Q_UINT64_C(0x0000002000000000); + static const AnimeFlag ANNId = Q_UINT64_C(0x0000004000000000); + static const AnimeFlag AnimePlanetId = Q_UINT64_C(0x0000008000000000); + + // static const AnimeFlag Unused = Q_UINT64_C(0x0000010000000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000020000000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000040000000000); + // static const AnimeFlag Unused = Q_UINT64_C(0x0000080000000000); + static const AnimeFlag ProducerNameList = Q_UINT64_C(0x0000100000000000); + static const AnimeFlag ProducerIdList = Q_UINT64_C(0x0000200000000000); + static const AnimeFlag CreatorIdList = Q_UINT64_C(0x0000400000000000); + static const AnimeFlag CharacterIdList = Q_UINT64_C(0x0000800000000000); + + static const AnimeFlag Byte1 = CategoryWeightList | CategoryList | RelatedAidType | RelatedAidList | Type | Year | Aid; - static const qint64 Byte2 = SynonymList | ShortNameList | OtherName + static const AnimeFlag Byte2 = SynonymList | ShortNameList | OtherName | EnglishName | KanjiName | RomajiName; - static const qint64 Byte3 = CategoryIdList | PicName | Url | EndDate | AirDate + static const AnimeFlag Byte3 = CategoryIdList | PicName | Url | EndDate | AirDate | SpecialEpCount | NormalEpCount | Episodes; - static const qint64 Byte4 = Is18Restricted | AwardList | ReviewCount + static const AnimeFlag Byte4 = Is18Restricted | AwardList | ReviewCount | AverageReviewRating | TempVoteCount | TempRating | VoteCount | Rating; - static const qint64 Byte5 = DateRecordUpdated | AniemNfoId | AllCinemaId + static const AnimeFlag Byte5 = DateRecordUpdated | AniemNfoId | AllCinemaId | ANNId | AnimePlanetId; - static const qint64 Byte6 = ProducerNameList | ProducerIdList | CreatorIdList + static const AnimeFlag Byte6 = ProducerNameList | ProducerIdList | CreatorIdList | CharacterIdList; - static const qint64 AllData = Byte1 | Byte2 | Byte3 | Byte4 + static const AnimeFlag AllData = Byte1 | Byte2 | Byte3 | Byte4 | Byte5 | Byte6; - static const qint64 InvalidBits = ~AllData; + static const AnimeFlag InvalidBits = ~AllData; } - typedef qint64 AnimeFlags; + typedef AnimeFlag::AnimeFlag AnimeFlags; typedef AnimeFlags AMask; namespace HashPrivate { diff --git a/aniqflags.h b/aniqflags.h new file mode 100644 index 0000000..addc738 --- /dev/null +++ b/aniqflags.h @@ -0,0 +1,79 @@ +#ifndef ANIQFLAGS_H +#define ANIQFLAGS_H + +namespace AniDBUdpClient { + +template +class AniQFlag +{ + T i; +public: + inline AniQFlag(T ai) : i(ai) {} + inline operator T() const { return i; } +}; + +template +class AniQIncompatibleFlag +{ + T i; +public: + inline explicit AniQIncompatibleFlag(T ai) : i(ai) {} + inline operator T() const { return i; } +}; + + +template +class AniQFlags +{ + typedef void **Zero; + T i; +public: + typedef Enum enum_type; + typedef T flag_type; + inline AniQFlags(const AniQFlags &f) : i(f.i) {} + inline AniQFlags(Enum f) : i(f) {} + inline AniQFlags(Zero = 0) : i(0) {} + inline AniQFlags(QFlag f) : i(f) {} + + inline AniQFlags &operator=(const AniQFlags &f) { i = f.i; return *this; } + inline AniQFlags &operator&=(T mask) { i &= mask; return *this; } + inline AniQFlags &operator|=(AniQFlags f) { i |= f.i; return *this; } + inline AniQFlags &operator|=(Enum f) { i |= f; return *this; } + inline AniQFlags &operator^=(AniQFlags f) { i ^= f.i; return *this; } + inline AniQFlags &operator^=(Enum f) { i ^= f; return *this; } + + inline operator T() const { return i; } + + inline AniQFlags operator|(AniQFlags f) const { AniQFlags g; g.i = i | f.i; return g; } + inline AniQFlags operator|(Enum f) const { AniQFlags g; g.i = i | f; return g; } + inline AniQFlags operator^(AniQFlags f) const { AniQFlags g; g.i = i ^ f.i; return g; } + inline AniQFlags operator^(Enum f) const { AniQFlags g; g.i = i ^ f; return g; } + inline AniQFlags operator&(T mask) const { AniQFlags g; g.i = i & mask; return g; } + inline AniQFlags operator&(Enum f) const { AniQFlags g; g.i = i & f; return g; } + inline AniQFlags operator~() const { AniQFlags g; g.i = ~i; return g; } + + inline bool operator!() const { return !i; } + + inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == T(f) ); } +}; + +#define AniQ_DECLARE_FLAGS(Flags, Enum, Type)\ +typedef AniQFlags Flags; + +#if defined Q_CC_MSVC && _MSC_VER < 1300 +# define AniQ_DECLARE_INCOMPATIBLE_FLAGS(Flags) +#else +# define AniQ_DECLARE_INCOMPATIBLE_FLAGS(Flags) \ +inline AniQIncompatibleFlag operator|(Flags::enum_type f1, Flags::flag_type f2) \ +{ return AniQIncompatibleFlag(Flags::flag_type(f1) | f2); } +#endif + +#define AniQ_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ +inline AniQFlags operator|(Flags::enum_type f1, Flags::enum_type f2) \ +{ return AniQFlags(f1) | f2; } \ +inline AniQFlags operator|(Flags::enum_type f1, AniQFlags f2) \ +{ return f2 | f1; } AniQ_DECLARE_INCOMPATIBLE_FLAGS(Flags) + +} // namespace AniDBUdpClient + +#endif // ANIQFLAGS_H diff --git a/filecommand.cpp b/filecommand.cpp index ac5ac95..4fa8836 100644 --- a/filecommand.cpp +++ b/filecommand.cpp @@ -223,8 +223,8 @@ Command FileCommand::rawCommand() const } // Clear any bits which aren't known and pad to 8 characters - cmd.second["fmask"] = QString::number(quint32(m_fmask & FileFlag::AllData), 16) - .rightJustified(8, QLatin1Char('0')); + cmd.second["fmask"] = QString::number(m_fmask & FileFlag::AllData, 16) + .rightJustified(10, QLatin1Char('0')); cmd.second["amask"] = QString::number(quint32(m_amask & FileAnimeFlag::AllData), 16) .rightJustified(8, QLatin1Char('0')); @@ -301,17 +301,20 @@ void FileReply::readReplyData(const QString &reply) } int partNo = 1; - for (int i = 0, flag = 1 << 31; i < 32; ++i, flag = (flag >> 1) & ~(1 << 31)) { - if (command().fmask() & flag) + FileFlags::flag_type flag = Q_UINT64_C(1) << 63; + for (int i = 0; i < 64; ++i, flag = flag >> 1) { - if (partNo >= parts.size()) + if (command().fmask() & flag) { - qWarning() << "Not enough parts in reply."; - continue; + if (partNo >= parts.size()) + { + qWarning() << "Not enough parts in reply."; + continue; + } + fileFlagData.insert(FileFlags(flag), parts[partNo]); + ++partNo; } - fileFlagData.insert(FileFlags(flag), parts[partNo]); - ++partNo; } }