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

real_parameter.cc

Go to the documentation of this file.
00001 // real_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 // 8/19/98:  Fixed default operator =
00033 
00034 #include "parameter/real_parameter.h"
00035 #include "global.h"
00036 #include "error.h"
00037 
00038 
00039 // default constructor
00040 real_parameter::real_parameter(double v) :
00041   value(v),
00042   shadowed(0),
00043   get_flag(false),
00044   use_min(false), min(0.0),
00045   use_max(false), max(0.0)
00046 { }
00047 
00048 real_parameter::real_parameter(int v) :
00049   value(double(v)),
00050   shadowed(0),
00051   get_flag(false),
00052   use_min(false), min(0.0),
00053   use_max(false), max(0.0)
00054 { }
00055 
00056 // shadow another parameter
00057 real_parameter::real_parameter(const abstract_real_parameter *p) :
00058   value(0.0),
00059   shadowed(p),
00060   get_flag(false),
00061   use_min(false), min(0.0),
00062   use_max(false), max(0.0)
00063 {
00064   if (p == 0) {
00065     error::warning("real_parameter constructor: " 
00066                    "Null pointer passed to constructor; not shadowing.");
00067   }
00068 }
00069 
00070 double real_parameter::get() const
00071 {
00072   if (is_local()) return value;
00073 
00074   else {
00075 
00076     // if shadow loop brings us back to this object, we quit indirecting
00077     if(get_flag) {
00078       get_flag = false;  // reset it for next time
00079       error::warning("real_parameter::get(): Terminating infinite" 
00080                      " shadowing loop, returning zero.");
00081       return 0.0;
00082     }
00083 
00084     // use indirection through the shadowing pointer
00085     get_flag = true;
00086     double v = shadowed->get();
00087     get_flag = false;
00088 
00089     return limit(v);
00090   }
00091 }
00092 
00093 real_parameter & real_parameter::shadow(const abstract_real_parameter &p)
00094 {
00095   // do nothing in case argument is this object
00096   if (&p == this) {
00097     error::warning("real_parameter::shadow(): a real_parameter must not shadow itself.");
00098   }
00099   else {
00100     shadowed = &p;
00101   }
00102   return *this;
00103 }
00104 
00105 real_parameter & real_parameter::set_min(double m)
00106 {
00107   if(use_max && m >= max) {
00108     error::warning("real_parameter::set_min(): minimum should be"
00109                    " less than real_parameter maximum.");
00110     m = max;
00111   }
00112 
00113   use_min = true;
00114   min = m;
00115   if(is_local() && value < min) value = min;
00116   return *this;
00117 }
00118 
00119 real_parameter & real_parameter::set_max(double m)
00120 {
00121   if(use_min && m <= min) {
00122     error::warning("real_parameter::set_max(): maximum should be"
00123                    " greater than real_parameter minimum.");
00124     m = min;
00125   }
00126 
00127   use_max = true;
00128   max = m;
00129   if(is_local() && value > max) value = max;
00130   return *this;
00131 }
00132 
00133 real_parameter& real_parameter::operator=(const abstract_real_parameter *p)
00134 {
00135   if(p == 0) {
00136     error::warning("real_parameter assignment: Cannot set real_parameter"
00137                    " to shadow a null pointer !") ;
00138     return *this;
00139   }
00140   else return shadow(*p);
00141 }
00142 
00143 real_parameter& real_parameter::clone(const real_parameter & p)
00144 {
00145   // do nothing in case argument is this object or directly shadows this object
00146   if (&p == this || p.shadowed == this) return *this;
00147 
00148   // make an identical twin of the argument
00149   value = p.value;
00150   shadowed = p.shadowed;
00151   use_min = p.use_min;
00152   min = p.min;
00153   use_max = p.use_max;
00154   max = p.max;
00155 
00156   return *this;
00157 }
00158 
00159 istream &operator >>(istream & in_file, real_parameter & p)
00160 {
00161   double temp;
00162   in_file >> temp;
00163   p.set(temp);
00164   return in_file;
00165 }

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