/*
 * SPDX-FileCopyrightText: 2000-2002 Copyright LifeLine Networks BV (www.lifeline.nl)
 * SPDX-FileCopyrightText: 2000-2002 Copyright Bastiaan Bakker
 * SPDX-FileCopyrightText: 2004 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <tango/common/log4tango/LayoutAppender.h>

#include <tango/common/log4tango/Portability.h>

namespace log4tango
{

LayoutAppender::LayoutAppender(const std::string &name) :
    Appender(name),
    _layout(new DefaultLayoutType())
{
    // no-op
}

LayoutAppender::~LayoutAppender()
{
    if(_layout != nullptr)
    {
        delete _layout;
        _layout = nullptr;
    }
}

bool LayoutAppender::requires_layout() const
{
    return true;
}

void LayoutAppender::set_layout(Layout *layout)
{
    if(layout != _layout)
    {
        if(_layout != nullptr)
        {
            delete _layout;
            _layout = nullptr;
        }
        _layout = (layout == nullptr) ? new DefaultLayoutType() : layout;
    }
}

Layout &LayoutAppender::get_layout()
{
    return *_layout;
}

} // namespace log4tango
