/*
    libMakeMKV - MKV multiplexer library

    Copyright (C) 2007-2019 GuinpinSoft inc <libmkv@makemkv.com>

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

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/
#ifndef CASSERT_LGPL_H_INCLUDED
#define CASSERT_LGPL_H_INCLUDED

#include <lgpl/stl.h>
#include <lgpl/stdstring.h>

class mkv_error_exception_unbuffered : public std::exception
{
    const char* m_message;
public:
    mkv_error_exception_unbuffered(const char* Message) throw()
        : m_message(Message)
    {
    }
    ~mkv_error_exception_unbuffered() throw()
    {
    }
    const char* what() const throw()
    {
      return m_message;
    }
};

class mkv_error_exception_buffered : public std::exception
{
    buf::string m_message;
public:
    mkv_error_exception_buffered(const char* Message) throw()
        : m_message(Message)
    {
    }
    mkv_error_exception_buffered(const StringPointer& Message) throw()
        : m_message(Message)
    {
    }
    ~mkv_error_exception_buffered() throw()
    {
    }
    const char* what() const throw()
    {
        return m_message.c_str();
    }
};

typedef mkv_error_exception_buffered mkv_logic_error;

#define mkv_error_exception(x) mkv_error_exception_unbuffered(x "\0")

int MkvAssertHelper(const char* Message);

#define MKV_ASSERT(_Expression_) \
    (void)( (!!(_Expression_)) || (MkvAssertHelper("MKV_ASSERT: " #_Expression_ )) );

#ifdef assert
#error assert
#endif

#define assert MKV_ASSERT

#endif // CASSERT_LGPL_H_INCLUDED
