Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

BaseCut.C

Go to the documentation of this file.
00001 
00014 #include "BaseCut.h"
00015 #include "BaseCutHelpers.h"
00016 #include "FillIterator.h"
00017 
00018 #include <cassert>
00019 #include <stdio.h>
00020 #include <cstring>
00021 #include <iostream>
00022 
00023 static const char *ident="@(#)$Id: BaseCut.C,v 1.7 2005/07/08 15:01:34 blist Exp $";
00024 
00025 FloatFun& BaseCut::Float () const {
00026   return *new FloatBaseCut(*this);
00027 }
00028 
00029 IntFun& BaseCut::Int () const {
00030   return *new IntBaseCut(*this);
00031 }
00032 
00033 FloatBaseCut::FloatBaseCut (const BaseCut& theBaseCut_, const char *name_) 
00034 : FloatFun (name_ ? name_ : std::string("float(")+theBaseCut_.getName()+")"),
00035   theBaseCut (theBaseCut_) 
00036 {}
00037 
00038 IntBaseCut::IntBaseCut (const BaseCut& theBaseCut_, const char *name_) 
00039 : IntFun (name_ ? name_ : std::string("int(")+theBaseCut_.getName()+")"),
00040   theBaseCut (theBaseCut_) 
00041 {}
00042 
00043    
00044 TwoCutCompound::TwoCutCompound (const BaseCut& lhs_, const std::string opname_, const BaseCut& rhs_) 
00045 : BaseCut (str('(')+lhs_.getName()+')'+opname_+'('+rhs_.getName()+')'), 
00046   lhs (lhs_), 
00047   rhs (rhs_)
00048 {}
00049 
00050 TwoCutCompound::TwoCutCompound (const BaseCut& lhs_, const BaseCut& rhs_, const std::string name_) 
00051 : BaseCut (name_), 
00052   lhs (lhs_), 
00053   rhs (rhs_)
00054 {}
00055 
00056 
00057 const FillIterator *TwoCutCompound::getIterator() const { 
00058   assert (!lhs.getIterator() || !rhs.getIterator() || lhs.getIterator()==rhs.getIterator());
00059   return (lhs.getIterator()) ? lhs.getIterator() : rhs.getIterator();
00060 }
00061    
00062 OneCutCompound::OneCutCompound (const std::string& funname_, const BaseCut& arg_) 
00063 : BaseCut (funname_+'('+arg_.getName()+')'), 
00064   arg (arg_)
00065 {}
00066 
00067 OneCutCompound::OneCutCompound (const BaseCut& arg_, const std::string& name_) 
00068 : BaseCut (name_), 
00069   arg (arg_)
00070 {}
00071 
00072 CachedBaseCut::CachedBaseCut (const ROListPoR& rol,
00073                               const BaseCut&  arg_ 
00074                              )
00075 : BaseCut (std::string("cached(")+arg_.getName()+')'), 
00076   CachedO (rol), 
00077   arg(arg_), 
00078   cacheValid (false)                    
00079 {}   
00080 
00081 CachedBaseCut::CachedBaseCut (const ROListPoR& rol,
00082                               const BaseCut&  arg_,
00083                               const std::string& name_ 
00084                              )
00085 : BaseCut (name_), 
00086   CachedO (rol), 
00087   arg(arg_), 
00088   cacheValid (false)                    
00089 {}   
00090 
00091 bool CachedBaseCut::operator() () const {
00092   if (!cacheValid) {
00093     cachedValue = arg();
00094     cacheValid = true;
00095   }
00096   return cachedValue;
00097 }
00098 
00099 CachedBaseCutIt::CachedBaseCutIt (const ROListPoR&     rol, 
00100                                   const BaseCut&      arg_, 
00101                                   const FillIterator&  iter_ 
00102                                  )
00103 : BaseCut (std::string("cached(")+arg_.getName()+')'),
00104   CachedO (rol),
00105   arg (arg_), 
00106   iter (iter_), 
00107   cacheValid (), 
00108   cachedValues ()              
00109 {} 
00110   
00111 CachedBaseCutIt::CachedBaseCutIt (const ROListPoR&     rol, 
00112                                   const BaseCut&      arg_
00113                                  )
00114 : BaseCut (std::string("cached(")+arg_.getName()+')'),
00115   CachedO (rol),
00116   arg (arg_), 
00117   iter (*(arg_.getIterator())), 
00118   cacheValid (), 
00119   cachedValues ()              
00120 {
00121   assert (&iter);
00122 }   
00123 
00124 CachedBaseCutIt::CachedBaseCutIt (const ROListPoR&     rol, 
00125                                   const BaseCut&       arg_, 
00126                                   const FillIterator&  iter_,
00127                                   const std::string  & name_ 
00128                                  )
00129 : BaseCut (name_),
00130   CachedO (rol),
00131   arg (arg_), 
00132   iter (iter_), 
00133   cacheValid (), 
00134   cachedValues ()              
00135 {} 
00136   
00137 CachedBaseCutIt::CachedBaseCutIt (const ROListPoR&    rol, 
00138                                   const BaseCut&      arg_,
00139                                   const std::string&  name_ 
00140                                  )
00141 : BaseCut (name_),
00142   CachedO (rol),
00143   arg (arg_), 
00144   iter (*(arg_.getIterator())), 
00145   cacheValid (), 
00146   cachedValues ()              
00147 {
00148   assert (&iter);
00149 }   
00150 
00151 bool CachedBaseCutIt::operator() () const {
00152   int i = iter();
00153   assert (i >= 0);
00154   if (static_cast<unsigned int>(i) >= cacheValid.size()) growCache (i+1); 
00155   if (!cacheValid[i]) {
00156     cacheValid[i] = true;
00157     cachedValues[i] = arg();
00158   }
00159   return cachedValues[i];
00160 }
00161 
00162 void CachedBaseCutIt::growCache (unsigned int s) const {
00163   unsigned int oldsize = cacheValid.size();
00164   if (s < oldsize) return;
00165   cacheValid.resize (s);
00166   cachedValues.resize(s);
00167   for (unsigned int i = oldsize; i < s; ++i) cacheValid[i] = false;
00168 }
00169 
00170 BaseCut& cached (const ROListPoR&   rol,    
00171                   const BaseCutPoR& cut,    
00172                   const FillIteratorPoR& iter
00173                  ) {
00174   assert (cut.pbc);                     
00175   if (iter.pfi) return *new CachedBaseCutIt (rol, *cut.pbc, *iter.pfi);
00176   if (const FillIterator *fi = cut.pbc->getIterator()) 
00177     return  *new CachedBaseCutIt (rol, *cut.pbc, *fi);
00178   return *new CachedBaseCut (rol, *cut.pbc);                  
00179 }
00180     
00181 
00182 // External functions that implement logical operators between
00183 // BaseCut objects, so that we can write e.g. "cuta && (cutb || !cutc)"
00184 
00185 BaseCut& operator&& (const BaseCut& lhs_, const BaseCut& rhs_) {
00186   return *new AndOfTwoCuts (lhs_, rhs_);
00187 }
00188 
00189 BaseCut& operator|| (const BaseCut& lhs_, const BaseCut& rhs_) {
00190   return *new OrOfTwoCuts (lhs_, rhs_);
00191 }
00192 
00193 BaseCut& operator! (const BaseCut& rhs_) {
00194   return *new NotOfACut (rhs_);
00195 }
00196 
00197 FloatFun& Float (const BaseCut& arg) {
00198   return *new FloatBaseCut(arg);
00199 }
00200 
00201 IntFun& Int (const BaseCut& arg) {
00202   return *new IntBaseCut(arg);
00203 }
00204 

Generated on Thu Oct 26 12:52:55 2006 for SFH by doxygen 1.3.2