/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
 *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
 *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 */

#ifndef SYNC_SEQ_NO_H
#define SYNC_SEQ_NO_H

#include <boost/cstdint.hpp>
#include "sync-digest.h"

namespace Sync {

/**
 * @ingroup sync
 * @brief Sequence number abstraction
 */
class SeqNo
{
public:
  /**
   * @brief Copy constructor
   * @param seq sequence number object to copy from
   */
  SeqNo (const SeqNo &seq)
  {
    *this = seq;
  }

  /**
   * @brief Assignment operator
   * @param seq sequence number object to copy from
   */
  SeqNo &
  operator = (const SeqNo &seq)
  {
    m_session = seq.m_session;
    m_seq = seq.m_seq;

    return *this;
  }

  /**
   * @brief Constructor with just sequence number. Session assumed to be zero
   * @param seq Sequence number
   */
  SeqNo (uint32_t seq)
    : m_session (0)
    , m_seq (seq)
  { }

  /**
   * @brief Constructor with session and sequence id
   * @param session Session ID
   * @param seq Sequence number
   */
  SeqNo (uint32_t session, uint32_t seq)
    : m_session (session)
    , m_seq (seq)
  { }

  /**
   * @brief Get sequence number digest
   *
   * Digest will be calculated every time it is requested
   */
  DigestConstPtr
  getDigest () const;

  /**
   * @brief Compare if one sequence number is lower
   * @param seq Another sequence number to compare with
   *
   * tuple (session1, seq1) is less than (session2, seq2) in two cases:
   * 1. session1 < session2
   * 2. session1 == session2 and seq1 < seq2
   */
  bool
  operator < (const SeqNo &seq) const
  {
    return m_session < seq.m_session || (m_session == seq.m_session && m_seq < seq.m_seq);
  }

  /**
   * @brief Compare if two sequence numbers are equal
   * @param seq Another sequence number to compare with
   */
  bool
  operator == (const SeqNo &seq) const
  {
    return m_session == seq.m_session && m_seq == seq.m_seq;
  }

  /**
   * @brief Get session id
   */
  uint32_t getSession () const
  { return m_session; }

  /**
   * @brief Get sequence number
   */
  uint32_t getSeq () const
  { return m_seq; }
  
private:
  /**
   * @brief Session ID (e.g., after crash, application will choose new session ID.
   *
   * Note that session IDs for the same name should always increase. So, the good choice
   * for the session ID is client's timestamp
   */
  uint32_t m_session;

  /**
   * @brief Sequence number
   *
   * Sequence number for a session always starts with 0 and goes to max value.
   *
   * For now, wrapping sequence number after max to zero is not supported
   */
  uint32_t m_seq;
};

inline std::ostream &
operator << (std::ostream &os, const SeqNo &seqno)
{
  os << seqno.getSession () << ":" << seqno.getSeq ();
  return os;
}

} // Sync

#endif // SYNC_SEQ_NO_H
