⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magnet.h

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 H
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#ifndef MagnetH
#define MagnetH

#include "istring.h"
#include "Hash.h"
//---------------------------------------------------------------------------

namespace KCeasyEngine {

class TMagnet
{
public:
    TMagnet();
    ~TMagnet();

    void Clear();
    bool Parse(const string& Uri);
    string Assemble();

    // returns true if Uri starts with "magnet:" or "sig2dat"
    static bool IsMagnetURI(const string& Uri);

    // xt
    const list<string>& GetExactTopics() { return XTList; }
    void SetExactTopics(const list<string>& Topics) { XTList = Topics; }
    void SetExactTopic(const string& Topic) { XTList.clear(); XTList.push_front(Topic); }
    const string GetExactTopic() { return XTList.empty() ? string() : XTList.front(); }
    // returns hash set of all xt urns, caller frees
    THashSet* GetExactTopicHashes() { return HashSetFromList(XTList); }
    void SetExactTopicHashes(const THashSet* Hashes) { XTList = ListFromHashSet(Hashes); }
    // xs
    const list<string>& GetExactSubstitudes() { return XSList; }
    void SetExactSubstitudes(const list<string>& Subs) { XSList = Subs; }
    void SetExactSubstitude(const string& Sub) { XSList.clear(); XSList.push_front(Sub); }
    const string GetExactSubstitude() { return XSList.empty() ? string() : XSList.front(); }
    // returns hash set of all xs urns, caller frees
    THashSet* GetExactSubstitudeHashes() { return HashSetFromList(XSList); }
    void SetExactSubstitudeHashes(const THashSet* Hashes) { XSList = ListFromHashSet(Hashes); }
    // as
    const list<string>& GetAcceptableSubstitudes() { return ASList; }
    void SetAcceptableSubstitudes(const list<string>& Subs) { ASList = Subs; }
    void SetAcceptableSubstitude(const string& Sub) { ASList.clear(); ASList.push_front(Sub); }
    const string GetAcceptableSubstitude() { return ASList.empty() ? string() : ASList.front(); }
    // returns hash set of all as urns, caller frees
    THashSet* GetAcceptableSubstitudeHashes() { return HashSetFromList(ASList); }
    void SetAcceptableSubstitudeHashes(const THashSet* Hashes) { ASList = ListFromHashSet(Hashes); }

    // accessors for dn,kt,mt
    const string& GetDisplayName() { return DN; }
    void SetDisplayName(const string& Name) { DN = Name; }
    const string& GetKeywordTopic() { return KT; }
    void SetKeywordTopic(const string& Topic) { KT = Topic; }
    const string& GetManifestTopic() { return MT; }
    void SetManifestTopic(const string& Topic) { MT = Topic; }

    // accessors for x.streamable
    bool IsStreamable() { return Streamable; }
    void SetStreamable(bool Stream) { Streamable = Stream; }

    // accessors for x.mediatype
    const string& GetMediaType() { return MediaType; }
    void SetMediaType(const string& Type) { MediaType = Type; }

    // accessors for file length. currently only non-zero for sig2dat urls
    unsigned int GetFileSize() { return FileSize; }
    void SetFileSize(unsigned int Size) { FileSize = Size; }

protected:
    THashSet* HashSetFromList(const list<string>& List);
    list<string> ListFromHashSet(const THashSet* HashSet);

    bool ParseMagnet(const string& Uri);
    bool ParseSig2Dat(const string& Uri);

    list<string> XTList; // exact topics
    list<string> XSList; // exact substitudes
    list<string> ASList; // acceptable substitudes
    string DN;           // display name
    string KT;           // keyword topic
    string MT;           // manifest topic

    // special extensions
    bool Streamable;     // x.streamable {0,1}
    string MediaType;    // x.mediatype {audio,video,image,text}
    unsigned int FileSize;
};

} // namespace KCeasyEngine

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -