#ifndef __sref_H #define __sref_H /* * Copyright (c) 1999 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form 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. In order to redistribute the software in * binary form, you will need a Picture Elements Binary Software * License. * * 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 */ #if !defined(WINNT) #ident "$Id: sref.h,v 1.4 1999/08/05 04:58:17 steve Exp $" #endif # include # include "svector.h" /* * The sref class is a reference with automatic reference counting. It * implementes a many-to-one linkage where T1 is the many type and T2 * is the one type. */ template class sref; template class sref_back; template class sref_back { friend class sref; public: sref_back() : sback_(0) { } ~sref_back() { assert(sback_ == 0); } svector* back_list() const; svector* back_list(); private: void desert_(sref*); sref*sback_; }; template class sref { friend class sref_back; public: sref(T1*d) : dest_(d) { insert_(); } virtual ~sref() { dest_->desert_(this); } T1*fore_ptr() { return dest_; } const T1*fore_ptr() const { return dest_; } private: T1*dest_; sref*next_; void insert_() { if (dest_->sback_ == 0) { next_ = this; dest_->sback_ = this; } else { next_ = dest_->sback_->next_; dest_->sback_->next_ = this; } } }; template svector* sref_back::back_list() const { if (sback_ == 0) return 0; unsigned cnt = 1; sref*cur = sback_->next_; while (cur != sback_) { cnt += 1; cur = cur->next_; } svector* result = new svector(cnt); (*result)[0] = dynamic_cast(sback_); cur = sback_->next_; cnt = 1; while (cur != sback_) { (*result)[cnt] = dynamic_cast(cur); cnt += 1; cur = cur->next_; } return result; } template svector* sref_back::back_list() { if (sback_ == 0) return 0; unsigned cnt = 1; sref*cur = sback_->next_; while (cur != sback_) { cnt += 1; cur = cur->next_; } svector* result = new svector(cnt); (*result)[0] = dynamic_cast(sback_); cur = sback_->next_; cnt = 1; while (cur != sback_) { (*result)[cnt] = dynamic_cast(cur); cnt += 1; cur = cur->next_; } return result; } template void sref_back::desert_(sref*item) { if (item == sback_) sback_ = item->next_; if (item == sback_) { sback_ = 0; } else { sref*cur = sback_; while (cur->next_ != item) { assert(cur->next_); cur = cur->next_; } cur->next_ = item->next_; } } /* * $Log: sref.h,v $ * Revision 1.4 1999/08/05 04:58:17 steve * Fix compile error with gcc 2.95 * * Revision 1.3 1999/07/18 21:17:51 steve * Add support for CE input to XNF DFF, and do * complete cleanup of replaced design nodes. * * Revision 1.2 1999/07/18 05:52:47 steve * xnfsyn generates DFF objects for XNF output, and * properly rewrites the Design netlist in the process. * * Revision 1.1 1999/05/01 02:57:53 steve * Handle much more complex event expressions. * */ #endif