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

complex_parameter.cc

Go to the documentation of this file.
00001 // complex_parameter.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 // Change history:
00032 // 5/8/01:   Added constructor taking a double
00033 // 11/23/98: Added assignment and constructor to shadow real
00034 //           parameters.
00035 // 8/19/98:  Fixed default operator =
00036 
00037 #include "parameter/complex_parameter.h"
00038 #include "error.h"
00039 
00040 
00041 // constructors
00042 
00043 complex_parameter::complex_parameter(Complex v) :
00044   value(v),
00045   mode(VALUE),
00046   cp(0),
00047   rp2(0),
00048   get_flag(false)
00049 { }
00050 
00051 complex_parameter::complex_parameter(int v) :
00052   value(Complex(double(v))),
00053   mode(VALUE),
00054   cp(0),
00055   rp2(0),
00056   get_flag(false)
00057 { }
00058 
00059 complex_parameter::complex_parameter(double v) :
00060   value(Complex(v)),
00061   mode(VALUE),
00062   cp(0),
00063   rp2(0),
00064   get_flag(false)
00065 { }
00066 
00067 complex_parameter::complex_parameter(const abstract_complex_parameter *p) :
00068   value(Complex(0.0)), 
00069   mode(C_SHADOW),
00070   cp(p),
00071   rp2(0),
00072   get_flag(false)
00073 {
00074   if (p == 0) {
00075     error::warning("complex_parameter constructor: " 
00076                    "Null pointer passed to constructor; not shadowing.");
00077     mode = VALUE ;
00078   }
00079 }
00080 
00081 complex_parameter::complex_parameter(const abstract_real_parameter *p) :
00082   value(Complex(0.0)), 
00083   mode(R_SHADOW),
00084   rp1(p),
00085   rp2(0),
00086   get_flag(false)
00087 {
00088   if (p == 0) {
00089     error::warning("complex_parameter constructor: " 
00090                    "Null pointer passed to constructor; not shadowing.");
00091     mode = VALUE ;
00092   }
00093 }
00094 
00095 complex_parameter::complex_parameter(const abstract_real_parameter &p1,
00096                                      const abstract_real_parameter &p2,
00097                                      int imode) :
00098   value(Complex(0.0)), 
00099   mode(imode),
00100   rp1(&p1),
00101   rp2(&p2),
00102   get_flag(false)
00103 { 
00104   if(mode != CARTESIAN && mode != POLAR) {
00105     error::warning("complex_parameter constructor: " 
00106                    "Improper mode chosen - setting to CARTESIAN !") ;
00107     mode = CARTESIAN ;
00108   }
00109 }
00110 
00111 
00112 // other member functions
00113 
00114 Complex complex_parameter::get() const
00115 {
00116   switch(mode) {
00117 
00118   default:
00119   case VALUE:
00120     return value;
00121 
00122   case R_SHADOW:
00123     return Complex(rp1->get());
00124 
00125   case CARTESIAN:
00126     return Complex(rp1->get(), rp2->get());
00127 
00128   case POLAR:
00129     return polar(rp1->get(), rp2->get());
00130     
00131   case C_SHADOW:
00132     // if shadow loop brings us back to this object, we quit indirecting
00133     if(get_flag) {
00134       get_flag = false;  // reset it for next time
00135       error::warning("complex_parameter::get(): Terminating infinite" 
00136                      " shadowing loop, returning zero.");
00137       return Complex(0.0);
00138     }
00139 
00140     get_flag = true;
00141     Complex v = cp->get();
00142     get_flag = false;
00143     return v;
00144   }
00145 }
00146 
00147 complex_parameter & complex_parameter::shadow(const abstract_complex_parameter &p)
00148 {
00149   // do nothing in case argument is this object
00150   if (&p == this) {
00151     error::warning("complex_parameter::shadow(): a complex_parameter must not shadow itself.");
00152   }
00153   else {
00154     mode = C_SHADOW;
00155     cp = &p;
00156   }
00157   return *this;
00158 }
00159 
00160 complex_parameter & complex_parameter::shadow(const abstract_real_parameter &p)
00161 {
00162   mode = R_SHADOW;
00163   rp1 = &p;
00164   return *this;
00165 }
00166 
00167 complex_parameter & complex_parameter::shadow(const abstract_real_parameter &p1,
00168                                               const abstract_real_parameter &p2,
00169                                               int imode)
00170 {
00171   mode = imode;
00172   if(mode != CARTESIAN && mode != POLAR) {
00173     error::warning("complex_parameter::shadow(): " 
00174                    "Improper mode chosen - setting to CARTESIAN !") ;
00175     mode = CARTESIAN ;
00176   }
00177   rp1 = &p1;
00178   rp2 = &p2;
00179   return *this;
00180 }
00181 
00182 complex_parameter& complex_parameter::operator=(const abstract_complex_parameter *p)
00183 {
00184   if(p == 0) {
00185     error::warning("complex_parameter assignment: Cannot set complex_parameter"
00186                    " to shadow a null pointer !") ;
00187     return *this;
00188   }
00189   else return shadow(*p);
00190 }
00191 
00192 complex_parameter& complex_parameter::operator=(const abstract_real_parameter *p)
00193 {
00194   if(p == 0) {
00195     error::warning("complex_parameter assignment: Cannot set complex_parameter"
00196                    " to shadow a null pointer !") ;
00197     return *this;
00198   }
00199   else return shadow(*p);
00200 }
00201 
00202 complex_parameter & complex_parameter::clone(const complex_parameter &p)
00203 {
00204   // do nothing in case argument is this object or directly shadows this object
00205   if (&p == this || (p.mode == C_SHADOW && p.cp == this)) return *this;
00206 
00207   // make an identical twin of the argument
00208   value = p.value;
00209   mode = p.mode;
00210   cp = p.cp;
00211   rp2 = p.rp2;
00212 
00213   return *this;
00214 }
00215 
00216 
00217 // other operations
00218 
00219 istream &operator >>(istream & in_file, complex_parameter & cp)
00220 {
00221   Complex tmp1;
00222   double tx, ty ;
00223   in_file >> tx;
00224   in_file >> ty;
00225   tmp1 = Complex(tx, ty) ;
00226   cp.set(tmp1);
00227   return in_file;
00228 }
00229 
00230 
00231 
00232 
00233 

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