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

#ifndef TANGO_SERVER_CMDHISTORYSTACK_H
#define TANGO_SERVER_CMDHISTORYSTACK_H

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

#include <chrono>
#include <vector>

namespace Tango
{
//=============================================================================
//
//            The CmdHistoryStack class
//
//
// description :     This class is simply a wrapper above a vector of
//            TimedCmdData class. It is  used to pass a command
//            value history which will be stored in the polling
//            buffer
//
//=============================================================================

/**
 * This class is a used to pass a command result history when the user
 * directly fills the command polling buffer. Each element in this stack
 * will be used to store one element of the command polling buffer
 *
 *
 * @headerfile tango.h
 * @ingroup Server
 */

template <typename T>
class CmdHistoryStack
{
  public:
    /**
     * Store a new element in the stack
     *
     * This method stores a new element in the stack
     *
     * @param elt The new element
     */
    void push(Tango::TimedCmdData<T> const &elt)
    {
        hist.push_back(elt);
    }

    /**
     * Get stack depth
     *
     * @return The stack depth
     */
    size_t length()
    {
        return hist.size();
    }

    /**
     * Reserve memory for stack elements
     *
     * @param nb The stack element number
     */
    void length(long nb)
    {
        hist.reserve(nb);
    }

    /**
     * Clear the stack
     */
    void clear()
    {
        hist.clear();
    }

    /**
     * Get stack data
     *
     * @return The stack itself
     */
    std::vector<TimedCmdData<T>> &get_data()
    {
        return hist;
    }

    /// @privatesection

    CmdHistoryStack() { }

    std::vector<Tango::TimedCmdData<T>> hist;
};
} // namespace Tango
#endif
