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

#ifndef TANGO_SERVER_ATTRDATA_H
#define TANGO_SERVER_ATTRDATA_H

#include <tango/server/Except.h>

namespace Tango
{
template <typename T>
class AttrData
{
  public:
    const T *ptr;
    Tango::AttrQuality qual;
    long x;
    long y;
    bool release;
    DevErrorList err;

    long wr_x;
    long wr_y;
    const T *wr_ptr;

    AttrData(const T *p) :
        AttrData(p, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, Tango::AttrQuality q) :
        AttrData(p, q, false)
    {
    }

    AttrData(const T *p, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        release(rel),
        wr_x(0),
        wr_y(0),
        wr_ptr(nullptr)
    {
        x = 1;
        y = 0;
    }

    AttrData(const T *p, const T *wr_p) :
        AttrData(p, wr_p, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, const T *wr_p, Tango::AttrQuality q) :
        AttrData(p, wr_p, q, false)
    {
    }

    AttrData(const T *p, const T *wr_p, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        release(rel),
        wr_y(0),
        wr_ptr(wr_p)
    {
        x = 1;
        y = 0;
        wr_x = 1;
    }

    // For spectrum

    AttrData(const T *p, long nb) :
        AttrData(p, nb, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, long nb, Tango::AttrQuality q) :
        AttrData(p, nb, q, false)
    {
    }

    AttrData(const T *p, long nb, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        x(nb),
        release(rel),
        wr_x(0),
        wr_y(0),
        wr_ptr(nullptr)
    {
        if(x == 0)
        {
            TANGO_THROW_EXCEPTION(API_AttrOptProp, "X dimension cannot be 0 for spectrum or image attribute");
        }
        y = 0;
    }

    AttrData(const T *p, long nb, const T *wr_p, long wr_nb) :
        AttrData(p, nb, wr_p, wr_nb, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, long nb, const T *wr_p, long wr_nb, Tango::AttrQuality q) :
        AttrData(p, nb, wr_p, wr_nb, q, false)
    {
    }

    AttrData(const T *p, long nb, const T *wr_p, long wr_nb, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        x(nb),
        release(rel),
        wr_x(wr_nb),
        wr_y(0),
        wr_ptr(wr_p)
    {
        if(x == 0)
        {
            TANGO_THROW_EXCEPTION(API_AttrOptProp, "X dimension cannot be 0 for spectrum or image attribute");
        }
        y = 0;
    }

    // For image

    AttrData(const T *p, long nb, long nb2) :
        AttrData(p, nb, nb2, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, long nb, long nb2, Tango::AttrQuality q) :
        AttrData(p, nb, nb2, q, false)
    {
    }

    AttrData(const T *p, long nb, long nb2, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        x(nb),
        y(nb2),
        release(rel),
        wr_x(0),
        wr_y(0),
        wr_ptr(nullptr)
    {
        if((x == 0) || (y == 0))
        {
            TANGO_THROW_EXCEPTION(API_AttrOptProp, "X or Y dimension cannot be 0 for image attribute");
        }
    }

    AttrData(const T *p, long nb, long nb2, const T *wr_p, long wr_nb, long wr_nb2) :
        AttrData(p, nb, nb2, wr_p, wr_nb, wr_nb2, Tango::ATTR_VALID)
    {
    }

    AttrData(const T *p, long nb, long nb2, const T *wr_p, long wr_nb, long wr_nb2, Tango::AttrQuality q) :
        AttrData(p, nb, nb2, wr_p, wr_nb, wr_nb2, q, false)
    {
    }

    AttrData(const T *p, long nb, long nb2, const T *wr_p, long wr_nb, long wr_nb2, Tango::AttrQuality q, bool rel) :
        ptr(p),
        qual(q),
        x(nb),
        y(nb2),
        release(rel),
        wr_x(wr_nb),
        wr_y(wr_nb2),
        wr_ptr(wr_p)
    {
        if((x == 0) || (y == 0))
        {
            TANGO_THROW_EXCEPTION(API_AttrOptProp, "X or Y dimension cannot be 0 for image attribute");
        }
    }

    // For error

    AttrData(DevErrorList &e) :
        ptr(nullptr),
        x(0),
        y(0),
        release(false),
        err(e),
        wr_x(0),
        wr_y(0),
        wr_ptr(nullptr)
    {
    }
};
} // namespace Tango
#endif
