Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 0e1eba187f6aad5cbe396d2d229d92d638a77366
  • master par défaut
  • script
  • new-devel
  • devel
  • timingView-edit
  • fix-mpv
7 résultats

CRTPSubDocument.hh

Blame
  • CRTPSubDocument.hh 5,60 Kio
    #pragma once
    
    #ifndef __cplusplus
    #error "This is a C++ header"
    #endif
    
    #include "PreCompiledHeaders.hh"
    #include "VivyApplication.hh"
    #include "Lib/Log.hh"
    #include "Lib/Utils.hh"
    #include "Lib/Audio.hh"
    #include "Lib/Video.hh"
    #include "Lib/Ass/Ass.hh"
    
    #define VIVY_ENABLE_IF_TYPE(Type) \
        template <typename = typename std::enable_if<!std::is_same<Type, void>::value>>
    
    namespace Vivy
    {
    // The Big CRTP class for all common things to all the subdocuments
    template <class CRTPSubDocumentType, class Document, class Context = void> class CRTPSubDocument {
    protected:
        VIVY_APP_LOGGABLE_OBJECT(CRTPSubDocument, logger)
        friend std::unique_ptr<Document>;
    
    public:
        using Type = CRTPSubDocumentType;
    
    protected:
        QString filePath;
        Type fileType;
    
        explicit CRTPSubDocument() = default;
    
        bool isFileValid(const QString &path) const noexcept
        {
            QFileInfo file(path);
            return Document::suffixList.contains(file.suffix());
        }
    
    public:
        static std::unique_ptr<Document> fromFile(const QString &path) noexcept
        {
            auto ret = std::unique_ptr<Document>(new Document());
            ret->logDebug() << "Init document from file " << VIVY_LOG_QUOTED(path);
            ret->filePath = path;
    
            try {
                ret->initFromPath(path); // May throw
            } catch (const std::runtime_error &e) {
                ret->logDebug() << "Failed to init document from file " << VIVY_LOG_QUOTED(path) << ": "
                                << e.what();
                ret.reset();
            }
    
            return ret;
        }
    
        // Get the default stream index or -1 if not possible.
        VIVY_ENABLE_IF_TYPE(Context)
        int getDefaultStreamIndex() const noexcept
        {
            if (auto ptr = getDefaultStream())
                return ptr->getStreamIndex();
            return -1;
        }
    
        // Get a pointer to the default stream, nullptr if not possible
        VIVY_ENABLE_IF_TYPE(Context)
        auto getDefaultStream() const