/***************************************************************************
*   Copyright (C) 2006 by Ian Reinhart Geiser   *
*   geiseri@sourcextreme.com   *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   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.             *
***************************************************************************/
#ifndef NODEID_H
#define NODEID_H

#include <QVector>
#include <QMetaType>

class QDataStream;

namespace KRPC
{
/**
 * A node id data type.  This encapsulates the underlying hash key implementation.
	@author Ian Reinhart Geiser <geiseri@sourcextreme.com>
*/
class NodeID
{
public:
	/**
	 *    Creates a null node.
	 */
	NodeID();

	/**
	 *    Copies an existing node.
	 * @param other node to copy
	 */
	NodeID( const NodeID &other );
	/**
	 *    Create a new node with the source data.
	 * @param source The source data for the id.
	 */
	NodeID( const QByteArray &source );
	~NodeID();

	/**
	 *    Replace the current key id with the new one from the generated source.
	 * @param source New source data.
	 */
	void generateId( const QByteArray &source );
	/**
	 *    Revert the current id to a null id.
	 */
	void clear();

	NodeID operator=( const NodeID &other);
	bool operator<( const NodeID &other ) const;
	bool operator>( const NodeID &other ) const;
	bool operator==( const NodeID &other ) const;
	const QByteArray toString() const;

	friend QDataStream &operator<<(QDataStream &out, const KRPC::NodeID &nodeid);
	friend QDataStream &operator>>(QDataStream &in, KRPC::NodeID &nodeid);

	static void registerNodeID();
private:
	QVector<uint> m_id;

};

QDataStream &operator<<(QDataStream &out, const KRPC::NodeID &nodeid);
QDataStream &operator>>(QDataStream &in, KRPC::NodeID &nodeid);

}

Q_DECLARE_METATYPE(KRPC::NodeID);

QDebug operator<<(QDebug dbg, KRPC::NodeID node );


#endif

