#pragma once #include "codecs.h" #include namespace NCodecs { struct TNoCodecException : TCodecException { TNoCodecException(TStringBuf name) { (*this) << "unknown codec: " << name; } }; struct ICodecFactory : TAtomicRefCount { virtual ~ICodecFactory() = default; virtual TCodecPtr MakeCodec(TStringBuf name) const = 0; virtual TVector ListNames() const = 0; }; typedef TIntrusivePtr TCodecFactoryPtr; namespace NPrivate { template struct TInstanceFactory : ICodecFactory { TCodecPtr MakeCodec(TStringBuf) const override { return new TCodec; } TVector ListNames() const override { TVector vs; vs.push_back(ToString(TCodec::MyName())); return vs; } }; class TCodecRegistry { using TRegistry = THashMap>; TRegistry Registry; public: using TFactoryPtr = TIntrusivePtr; TCodecRegistry(); void RegisterFactory(TFactoryPtr fac); TCodecPtr GetCodec(TStringBuf name) const; TVector GetCodecsList() const; }; } void RegisterCodecFactory(TCodecFactoryPtr fact); template void RegisterCodec() { RegisterCodecFactory(new NPrivate::TInstanceFactory()); } }