Internal.hpp 1.99 KB
Newer Older
1
/*****************************************************************************
2
 * Internal.hpp: Wraps an internal vlc type.
3
 *****************************************************************************
4
 * Copyright © 2014 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef VLCPP_H
#define VLCPP_H

#include <cassert>
#include <stdlib.h>
#include <vlc/libvlc.h>
29 30
#include <memory>
#include <stdexcept>
31 32 33 34

namespace VLC
{

35
template <typename T, typename Releaser = void(*)(T*)>
36
class Internal
37 38
{
    public:
39 40
        using InternalType  = T;
        using InternalPtr   = T*;
41 42 43
        using Pointer       = std::shared_ptr<T>;

        InternalPtr get() const { return m_obj.get(); }
44 45

        bool isValid() const { return (bool)m_obj; }
46 47 48

        operator T*() const { return m_obj.get(); }

49
    protected:
50 51
        Internal() = default;

52

53 54 55 56 57 58
        Internal( InternalPtr obj, Releaser releaser )
            : m_obj{ obj, releaser }
        {
            if ( obj == nullptr )
                throw std::runtime_error("Wrapping a NULL instance");
        }
59

60 61
        Internal(Releaser releaser)
            : m_obj{ nullptr, releaser }
62 63
        {
        }
64

65 66
    protected:
        Pointer     m_obj;
67 68 69 70 71
};

}

#endif // VLCPP_H