Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

port.cc

Go to the documentation of this file.
00001 // port.cc
00002 // SuperMix version 1.0  C++ source file
00003 //
00004 // Copyright (c) 1999 California Institute of Technology.
00005 // All rights reserved.
00006 //
00007 // Redistribution and use in source and binary forms for noncommercial
00008 // purposes are permitted provided that the above copyright notice and
00009 // this paragraph are duplicated in all such forms and that any
00010 // documentation and other materials related to such distribution and
00011 // use acknowledge that the software was developed by California
00012 // Institute of Technology. Redistribution and/or use in source or
00013 // binary forms is not permitted for any commercial purpose. Use of
00014 // this software does not include a permitted use of the Institute's
00015 // name or trademark for any purpose.
00016 //
00017 // DISCLAIMER:
00018 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00019 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00020 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00021 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00022 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00023 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00024 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00025 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00026 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00027 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00028 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00029 // MATERIALS.
00030 
00031 #include "port.h"
00032 #include "error.h"
00033 
00034 port::port()
00035 {
00036   id = 0;
00037   index = 0;
00038 }
00039  
00040 port::port(unsigned long a, int b)
00041 {
00042   id = a;
00043   index = b;
00044 }
00045  
00046 int operator ==(const port& a, const port& b)
00047 {
00048   return (a.id == b.id) && (a.index == b.index);
00049 }
00050  
00051 int operator >(const port& a, const port& b)
00052 {
00053   if(a == b) return 0;
00054   if(a.id > b.id) return 1;
00055   return (a.index > b.index);
00056 }
00057  
00058 portArray::portArray()
00059 {
00060   length =0;
00061   data = 0;
00062 }
00063 
00064 portArray::portArray(int l)
00065 {
00066   length = l;
00067   data = new port [length];
00068 }
00069 
00070 portArray::portArray(const portArray & a)
00071 {
00072   length = a.length;
00073   data = new port [length];
00074   for(int i = 0; i<length; i++)
00075     data[i] = a.data[i];
00076 }
00077 
00078 portArray::~portArray()
00079 {
00080   delete [] data;
00081 }
00082 
00083 int portArray::len()
00084 {
00085   return length;
00086 }
00087 
00088 void portArray::set(int index, port value)
00089 {
00090   if((index<1) || (index>length))
00091     error::warning("Index out of bounds for portArray set.");
00092   else
00093     data[index-1] = value;
00094 }
00095 
00096 void portArray::zero()
00097 {
00098   for(int i=1; i<=length; i++)
00099       set(i, port());
00100 }
00101 
00102 port portArray::get(int index) const
00103 {
00104   if((index<1) || (index>length))
00105   {
00106     error::warning("Index out of bounds for portArray get.");
00107     return port();
00108   }
00109   else
00110     return data[index-1];
00111 }
00112 
00113 portArray& portArray::operator=(const portArray& a)
00114 {
00115   int i;
00116 
00117   // Beware of self assignment: a = a
00118   if(this != &a) {
00119 
00120     // Delete the current portArray
00121     delete [] data;
00122 
00123     // Copy the old portArray over to the new one
00124     length = a.length;
00125     data = new port [length];
00126     for(i = 0; i<length; i++)
00127       data[i] = a.data[i];
00128   }
00129   return *this;
00130 }

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7