Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / common / regdef / include / Link.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: Link.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named 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.
*
* The above named 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 work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef __Link_h
#define __Link_h
#include <iostream>
#include <stdlib.h>
using namespace std;
/** @file Link.h
* Link is a template class that defines a link so that instances (items)
* of some class T can be held on a doubly-linked list.
*/
template<class T> class List; // forward reference
template<class T> class ListIterator; // forward reference
/** Link<T> is used to hold a link so that items of type T can
* be held on a list of type List<T>. The design of the
* Link class is closely related to that of the List class.
*/
template<class T> class Link
{
friend class List<T>;
friend class ListIterator<T>;
public:
/** Constructor for Link<T>.
* @param i a pointer to the object associated with this link.
* @param n a pointer to the next link on the list.
* @param p a pointer to the previous link on the list.
* All parameters default to NULL if not provided.
*/
Link(T *i=NULL, Link *n=NULL, Link *p=NULL) { item = i; next = n; prev = p; }
/** Set the object, next link and previous link pointers. */
inline void setItem(T *i, Link *n, Link *p) { item = i; next = n; prev = p; }
/** Set the next and previous link pointers, clear the object pointer. */
inline void setItem(Link *n, Link *p) { item = NULL; next = n; prev = p; }
/** Set the next pointer. */
inline void setNext(Link *n) { next = n; }
/** Set the previous pointer. */
inline void setPrev(Link *p) { prev = p; }
/** Set the object pointer. */
inline void setItem(T *i) { item = i; }
/** Print the link to the specified output stream. */
void printThis(ostream &os);
/** Get the next link pointer. */
inline Link<T> *getNext() { return next; }
/** Get the previous link pointer. */
inline Link<T> *getPrev() { return prev; }
/** Get the item pointer. */
inline T *getItem() { return item; }
private:
T *item;
Link<T> *next;
Link<T> *prev;
};
#include "pLink.h"
#endif