/*
 * SPDX-FileCopyrightText: 2004 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <tango/server/SpectrumAttr.h>

#include <tango/server/Except.h>
#include <tango/server/Logging.h>

#include <bitset>

namespace Tango
{

//+-----------------------------------------------------------------------------------------------------------------
//
// method :
//        SpectrumAttr::SpectrumAttr
//
// description :
//        Constructor for the SpectrumAttr class. This constructor simply set the internal values
//
//-------------------------------------------------------------------------------------------------------------------

SpectrumAttr::SpectrumAttr(const char *att_name, long att_type, long x) :
    Attr(att_name, att_type),
    ext(nullptr)
{
    format = Tango::SPECTRUM;
    if(x <= 0)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute : " << name << ": ";
        o << " Maximum x dim. wrongly defined" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }

    if(type == DEV_ENCODED)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute: " << name << ": ";
        o << "DevEncode data type allowed only for SCALAR attribute" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }
    max_x = x;
}

SpectrumAttr::SpectrumAttr(const char *att_name, long att_type, Tango::AttrWriteType w_type, long x) :
    Attr(att_name, att_type, w_type),
    ext(nullptr)
{
    format = Tango::SPECTRUM;
    if(x <= 0)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute : " << name << ": ";
        o << " Maximum x dim. wrongly defined" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }

    if(type == DEV_ENCODED)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute: " << name << ": ";
        o << "DevEncode data type allowed only for SCALAR attribute" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }
    max_x = x;
}

SpectrumAttr::SpectrumAttr(const char *att_name, long att_type, long x, DispLevel level) :
    Attr(att_name, att_type, level),
    ext(nullptr)
{
    format = Tango::SPECTRUM;
    if(x <= 0)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute : " << name << ": ";
        o << " Maximum x dim. wrongly defined" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }

    if(type == DEV_ENCODED)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute: " << name << ": ";
        o << "DevEncode data type allowed only for SCALAR attribute" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }
    max_x = x;
}

SpectrumAttr::SpectrumAttr(const char *att_name, long att_type, Tango::AttrWriteType w_type, long x, DispLevel level) :
    Attr(att_name, att_type, level, w_type),
    ext(nullptr)
{
    format = Tango::SPECTRUM;
    if(x <= 0)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute : " << name << ": ";
        o << " Maximum x dim. wrongly defined" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }

    if(type == DEV_ENCODED)
    {
        TANGO_LOG_DEBUG << "SpectrumAttr::SpectrumAttr throwing exception" << std::endl;
        TangoSys_OMemStream o;

        o << "Attribute: " << name << ": ";
        o << "DevEncode data type allowed only for SCALAR attribute" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrWrongDefined, o.str());
    }
    max_x = x;
}

SpectrumAttr::SpectrumAttr(const SpectrumAttr &sou) :
    Attr(sou)
{
    max_x = sou.max_x;
}

} // namespace Tango
