00001 // SuperMix version 1.0 C++ source file 00002 // 00003 // Copyright (c) 1999 California Institute of Technology. 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms for noncommercial 00007 // purposes are permitted provided that the above copyright notice and 00008 // this paragraph are duplicated in all such forms and that any 00009 // documentation and other materials related to such distribution and 00010 // use acknowledge that the software was developed by California 00011 // Institute of Technology. Redistribution and/or use in source or 00012 // binary forms is not permitted for any commercial purpose. Use of 00013 // this software does not include a permitted use of the Institute's 00014 // name or trademark for any purpose. 00015 // 00016 // DISCLAIMER: 00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT 00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR 00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET 00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 00021 // LICENSED PRODUCT, HOWEVER USED. IN NO EVENT SHALL CALTECH/JPL BE 00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO 00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC 00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF 00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN 00026 // FACT SHALL KNOW OF THE POSSIBILITY. THE USER BEARS ALL RISK 00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED 00028 // MATERIALS. 00029 // 00030 // ************************************************************************** 00031 00046 // ************************************************************************** 00047 // 00048 // 5/13/02: changed comments to javadoc format 00049 // 12/10/99: added simple_nport class 00050 // 11/16/99: changes to support new noise calculations 00051 // 11/1/99: added is_active() and is_source() 00052 // 10/22/99: class device is now in device.h 00053 // 10/22/99: device::Z0 is back to a parameter again 00054 // 8/23/99: added definition of size() to alias 00055 // 7/26/99: removed the superfluous sdata_nport class 00056 // 7/25/99: minor changes to remove some compiler warnings 00057 // 4/28/99: added support for state_tags. 00058 // 9/30/98: changed the fixes to device. 00059 // 9/22/98: fixed bug by adding assigment operator to device. 00060 // 9/18/98: class alias is now a subclass of data_ptr_nport. 00061 // 9/18/98: created data_ptr_nport class. 00062 // 9/18/98: improved S, C, and B function fo class nport. 00063 // 9/16/98: fixed sdata_nport = sdata_nport() bug. 00064 // 7/27/98: added nport::get_last_data(); some other minor 00065 // changes to nport 00066 // 7/21/98: changed generic_nport to sdata_nport 00067 // 7/8/98: added generic_nport; added nport::mode(); 00068 // moved recalc() to nport; added new nport constuctor 00069 // 12/30/97: changed device::Z0 to a double vice parameter 00070 // 12/23/97: pulled out sdata and compute_passive_noise to 00071 // sdata.h (FR). Includes sdata.h. 00072 // 12/19/97: modified by FR for matmath classes 00073 // 00074 // ************************************************************************** 00075 00076 #ifndef NPORT_H 00077 #define NPORT_H 00078 00079 #include "device.h" 00080 #include "global.h" 00081 #include "port.h" 00082 #include "state_tag.h" 00083 #include "parameter.h" 00084 #include "sdata.h" 00085 00086 // ************************************************************************** 00087 00098 class nport : public device 00099 { 00100 00101 public: 00107 struct data_info { 00108 00110 bool noise; 00111 00121 bool active; 00122 00126 bool source; 00127 }; 00128 00129 protected: 00131 sdata data; 00132 00134 data_info info; 00135 00145 virtual void recalc() = 0; 00146 00151 virtual void recalc_S() { recalc(); } 00152 00153 public: 00159 nport(int n = 0) : data(n) 00160 { info.noise = info.active = info.source = true; } 00161 00162 // Virtual destructor is necessary to ensure proper subclass destruction. 00163 virtual ~nport() { } 00164 00166 virtual const sdata& get_data() { last_state.reset(); recalc(); return data; } 00167 00175 virtual const sdata& get_data(state_tag calc_id) 00176 { 00177 if(last_state == calc_id) return data; 00178 last_state = calc_id; 00179 recalc(); 00180 return data; 00181 } 00182 00188 virtual const sdata& get_last_data() const { return data; } 00189 00197 virtual const sdata& get_data_S() { last_state.reset(); recalc_S(); return data; } 00198 00208 virtual const sdata& get_data_S(state_tag calc_id) 00209 { 00210 if(last_state == calc_id) return data; 00211 last_state = calc_id; 00212 recalc_S(); 00213 return data; 00214 } 00215 00221 virtual int size() { return data.size(); } // return the number of ports 00222 00224 virtual const data_info & get_data_info() { return info; } 00225 00227 virtual bool has_noise() { return get_data_info().noise; } 00228 00233 virtual bool is_active() { return get_data_info().active; } 00234 00239 virtual bool is_source() { return get_data_info().source; } 00240 00248 virtual complex S(int p1, int p2); 00249 00258 virtual complex C(int p1, int p2); 00259 00266 virtual complex B(int p); 00267 00274 virtual port get_port(int index); 00275 00282 virtual int get_port(port p); 00283 00288 virtual v_index_mode mode() { return data.mode(); } // sdata indexing mode 00289 00290 }; 00291 00292 // ************************************************************************** 00293 00308 class data_ptr_nport : public nport 00309 { 00310 protected: 00316 const sdata * data_ptr; 00317 00318 public: 00323 data_ptr_nport() : nport(0), data_ptr(&data) { } 00324 00329 data_ptr_nport(const data_ptr_nport & c) : nport(c), data_ptr(&data) { } 00330 00335 data_ptr_nport & operator=(const data_ptr_nport & c) 00336 { data = c.data; data_ptr = &data; return *this; } 00337 00338 // Virtual destructor is necessary to ensure proper subclass destruction. 00339 virtual ~data_ptr_nport() { } 00340 00342 virtual const sdata& get_data() 00343 { 00344 last_state.reset(); recalc(); return *data_ptr; 00345 } 00346 00354 virtual const sdata& get_data(state_tag calc_id) 00355 { 00356 if(last_state == calc_id) return *data_ptr; 00357 last_state = calc_id; 00358 recalc(); 00359 return *data_ptr; 00360 } 00361 00369 virtual const sdata& get_data_S() 00370 { 00371 last_state.reset(); recalc_S(); return *data_ptr; 00372 } 00373 00383 virtual const sdata& get_data_S(state_tag calc_id) 00384 { 00385 if(last_state == calc_id) return *data_ptr; 00386 last_state = calc_id; 00387 recalc_S(); 00388 return *data_ptr; 00389 } 00390 00396 virtual const sdata& get_last_data() const { return *data_ptr; } 00397 00403 virtual int size() { return data_ptr->size(); } // return the number of ports 00404 00409 virtual v_index_mode mode() { return data_ptr->mode(); } 00410 }; 00411 00412 // ************************************************************************** 00413 00431 class alias : public data_ptr_nport 00432 { 00433 private: 00435 nport *original; 00436 00438 void recalc() { if(original) data_ptr = &original->get_data(); } 00439 00441 void recalc_S() { if(original) data_ptr = &original->get_data_S(); } 00442 00443 public: 00444 // The default constructor. 00445 alias() : data_ptr_nport(), original(0) { } 00446 00450 alias(nport & o) : data_ptr_nport(), original(&o) { } 00451 00452 // return the number of ports 00453 // (need this definition since data may not be properly sized until get_data()) 00454 int size() { return (original) ? original->size() : 0; } 00455 00457 const nport::data_info & get_data_info() 00458 { return (original) ? original->get_data_info() : info; } 00459 00465 alias & operator=(nport & n); 00466 }; 00467 00468 // ************************************************************************** 00469 00476 class simple_nport : public nport 00477 { 00478 00479 public: 00485 simple_nport(int n = 0) : nport(n) { } 00486 00488 sdata & operator()() { return data; } 00489 00491 data_info & set_info() { return info; } 00492 00493 private: 00495 void recalc() { } 00496 00498 void recalc_S() { } 00499 00500 }; 00501 00502 #endif /* NPORT_H */
Please direct comments and corrections to
supermix@submm.caltech.edu
Go to the supermix home page
Generated by
1.2.7