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

#ifndef TANGO_SERVER_TIMEDATTRDATA_H
#define TANGO_SERVER_TIMEDATTRDATA_H

#include <tango/server/AttrData.h>
#include <tango/server/TangoTimestamp.h>

namespace Tango
{
//=============================================================================
//
//            The TimedAttrData class
//
//
// description :     This class inherits from the AttrData class and adds
//            a date to all the data contains in the AttrData
//            class
//
//=============================================================================

template <typename T>
class TimedAttrData : public Tango::AttrData<T>
{
  public:
    /**@name Miscellaneous constructors for scalar attribute
     */
    //@{
    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param when The date
     */
    TimedAttrData(const T *p_data, const TangoTimestamp &when) :
        AttrData<T>(p_data),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param when The date
     */
    TimedAttrData(const T *p_data, const T *p_wr_data, const TangoTimestamp &when) :
        AttrData<T>(p_data, p_wr_data),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(const T *p_data, Tango::AttrQuality qual, const TangoTimestamp &when) :
        AttrData<T>(p_data, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(const T *p_data, const T *p_wr_data, Tango::AttrQuality qual, const TangoTimestamp &when) :
        AttrData<T>(p_data, p_wr_data, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * @param p_data Pointer to the attribute value
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> parameter must be freed
     * @param when The date
     */
    TimedAttrData(const T *p_data, Tango::AttrQuality qual, bool rel, const TangoTimestamp &when) :
        AttrData<T>(p_data, qual, rel),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * @param p_data Pointer to the attribute value
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters must be
     * freed
     * @param when The date
     */
    TimedAttrData(const T *p_data, const T *p_wr_data, Tango::AttrQuality qual, bool rel, const TangoTimestamp &when) :
        AttrData<T>(p_data, p_wr_data, qual, rel),
        tp(when)
    {
    }

    //@}

    // For spectrum

    /**@name Miscellaneous constructors for spectrum attribute
     */
    //@{
    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, const TangoTimestamp &when) :
        AttrData<T>(p_data, x),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, const T *p_wr_data, long x_wr, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, p_wr_data, x_wr),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, Tango::AttrQuality qual, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(
        const T *p_data, long x, const T *p_wr_data, long x_wr, Tango::AttrQuality qual, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, p_wr_data, x_wr, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> parameter must be freed
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, Tango::AttrQuality qual, bool rel, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, qual, rel),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters must be
     * freed
     * @param when The date
     */
    TimedAttrData(const T *p_data,
                  long x,
                  const T *p_wr_data,
                  long x_wr,
                  Tango::AttrQuality qual,
                  bool rel,
                  const TangoTimestamp &when) :
        AttrData<T>(p_data, x, p_wr_data, x_wr, qual, rel),
        tp(when)
    {
    }

    //@}

    // For image

    /**@name Miscellaneous constructors for image attribute
     */
    //@{
    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, long y, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     * The attribute quality factor will be set to ATTR_VALID
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param y_wr The attribute written part y length
     * @param when The date
     */
    TimedAttrData(
        const T *p_data, long x, long y, const T *p_wr_data, long x_wr, long y_wr, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y, p_wr_data, x_wr, y_wr),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * The memory pointed to by the <i>p_data</i> parameter will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, long y, Tango::AttrQuality qual, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * The memory pointed to by the <i>p_data</i> and <i>p_wr_data</i> parameters will not be freed
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param y_wr The attribute written part y length
     * @param qual The attribute quality factor
     * @param when The date
     */
    TimedAttrData(const T *p_data,
                  long x,
                  long y,
                  const T *p_wr_data,
                  long x_wr,
                  long y_wr,
                  Tango::AttrQuality qual,
                  const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y, p_wr_data, x_wr, y_wr, qual),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object.
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> parameter must be freed
     * @param when The date
     */
    TimedAttrData(const T *p_data, long x, long y, Tango::AttrQuality qual, bool rel, const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y, qual, rel),
        tp(when)
    {
    }

    /**
     * Create a new TimedAttrData object for a R/W attribute.
     *
     * @param p_data Pointer to the attribute value
     * @param x The attribute x length
     * @param y The attribute y length
     * @param p_wr_data Pointer to the written part of the attribute value
     * @param x_wr The attribute written part x length
     * @param y_wr The attribute written part y length
     * @param qual The attribute quality factor
     * @param rel Set to true if the memory pointed to by the <i>p_data</i> abd <i>p_wr_data</i> parameters must be
     * freed
     * @param when The date
     */
    TimedAttrData(const T *p_data,
                  long x,
                  long y,
                  const T *p_wr_data,
                  long x_wr,
                  long y_wr,
                  Tango::AttrQuality qual,
                  bool rel,
                  const TangoTimestamp &when) :
        AttrData<T>(p_data, x, y, p_wr_data, x_wr, y_wr, qual, rel),
        tp(when)
    {
    }

    //@}

    // For error

    /**@name Miscellaneous constructors for errors
     */
    //@{
    /**
     * Create a new TimedAttrData object for errors.
     *
     * The created TimedAttrData is used to store attribute errors
     * in the attribute history stack
     *
     * @param errs The error stack
     * @param when The date
     */
    TimedAttrData(DevErrorList &errs, const TangoTimestamp &when) :
        AttrData<T>(errs),
        tp(when)
    {
    }

    //@}
    //@}

    /// @privatesection
    std::chrono::system_clock::time_point tp;
};
} // namespace Tango
#endif
