00001 // 00002 // Copyright (c) 2006 by Rafael Ostertag 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 // 00019 // $Id: casfuncobj.cc,v 1.15 2006/12/31 00:51:31 rafi Exp $ 00020 // 00021 00022 #include "casfuncobj.h" 00023 #include "casnumeric.h" 00024 #include "casgarbage.h" 00039 // --------------------------------------------------------------------------- 00040 // CASDestroyObject 00041 // --------------------------------------------------------------------------- 00051 void 00052 CASDestroyObject::operator() ( CASObject* o ) const { 00053 checkptr ( o ); 00054 delete o; 00055 } 00056 // --------------------------------------------------------------------------- 00057 00058 // --------------------------------------------------------------------------- 00059 // CASExpandObject 00060 // --------------------------------------------------------------------------- 00075 CASObject* 00076 CASExpandObject::operator() ( const CASObject* o ) const { 00077 checkptr ( o ); 00078 const CASTerm *term = dynamic_cast<const CASTerm*> ( o ); 00079 if ( term != 0 ) 00080 return term->Expand(); 00081 else 00082 return o->Clone(); 00083 } 00084 // --------------------------------------------------------------------------- 00085 00086 // --------------------------------------------------------------------------- 00087 // CASCloneObject 00088 // --------------------------------------------------------------------------- 00098 CASObject* 00099 CASCloneObject::operator() ( const CASObject* o ) const { 00100 checkptr ( o ); 00101 return o->Clone(); 00102 } 00103 // --------------------------------------------------------------------------- 00104 00105 // --------------------------------------------------------------------------- 00106 // CASInvertObject 00107 // --------------------------------------------------------------------------- 00117 CASObject* 00118 CASInvertObject::operator() ( const CASObject* o ) const { 00119 checkptr ( o ); 00120 return o->Invert(); 00121 } 00122 // --------------------------------------------------------------------------- 00123 00124 // --------------------------------------------------------------------------- 00125 // CASInvertObjectIP 00126 // --------------------------------------------------------------------------- 00137 void 00138 CASInvertObjectIP::operator() ( CASObject* o ) const { 00139 checkptr ( o ); 00140 o->InvertIP(); 00141 o->meta.UnsetSorted(); 00142 } 00143 // --------------------------------------------------------------------------- 00144 00145 // --------------------------------------------------------------------------- 00146 // CASAbsoluteObjectIP 00147 // --------------------------------------------------------------------------- 00158 void 00159 CASAbsoluteObjectIP::operator() ( CASObject* o ) const { 00160 checkptr ( o ); 00161 o->AbsoluteIP(); 00162 o->meta.UnsetSorted(); 00163 } 00164 // --------------------------------------------------------------------------- 00165 00166 // --------------------------------------------------------------------------- 00167 // CASSortObject 00168 // --------------------------------------------------------------------------- 00185 bool 00186 CASSortObject::operator() ( const CASObject* o1, const CASObject* o2 ) const { 00187 checkptr ( o1 ); 00188 checkptr ( o2 ); 00189 if ( o1->GetType() == o2->GetType() ) { 00190 CASObject *sort_weight_o1 = o1->SortWeight(); 00191 CASObject *sort_weight_o2 = o2->SortWeight(); 00192 if ( sort_weight_o1->IsEqual ( sort_weight_o2 ) && 00193 ! ( o1->exponent == 0 || o2->exponent == 0 ) ) { 00194 CASObject::Garbage->Put ( sort_weight_o1 ); 00195 CASObject::Garbage->Put ( sort_weight_o2 ); 00196 sort_weight_o1 = o1->exponent->SortWeight(); 00197 sort_weight_o2 = o2->exponent->SortWeight(); 00198 bool result = sort_weight_o1->IsLT ( sort_weight_o2 ); 00199 CASObject::Garbage->Put ( sort_weight_o1 ); 00200 CASObject::Garbage->Put ( sort_weight_o2 ); 00201 return result; 00202 } 00203 bool result = sort_weight_o1->IsLT ( sort_weight_o2 ); 00204 CASObject::Garbage->Put ( sort_weight_o1 ); 00205 CASObject::Garbage->Put ( sort_weight_o2 ); 00206 return result; 00207 } 00208 00209 return o1->GetType() < o2->GetType(); 00210 } 00211 // --------------------------------------------------------------------------- 00212 00213 // --------------------------------------------------------------------------- 00214 // CASGarbageSort_Cmp 00215 // --------------------------------------------------------------------------- 00225 bool 00226 CASGarbageSort_Cmp::operator() ( const CASObject* o1, const CASObject* o2 ) const { 00227 checkptr ( o1 ); 00228 checkptr ( o2 ); 00229 return o1 > o2; 00230 } 00231 // --------------------------------------------------------------------------- 00232 00233 00234 // --------------------------------------------------------------------------- 00235 // CASObjectEqual 00236 // --------------------------------------------------------------------------- 00246 bool 00247 CASObjectEqual::operator() ( const CASObject* o1, const CASObject* o2 ) { 00248 checkptr ( o1 ); 00249 checkptr ( o2 ); 00250 return o1->IsEqual ( o2 ); 00251 } 00252 // --------------------------------------------------------------------------- 00253 00254 00255 // --------------------------------------------------------------------------- 00256 // CASObjectFindType 00257 // --------------------------------------------------------------------------- 00263 CASObjectFindType::CASObjectFindType ( int type ) : t ( type ) { 00264 } 00265 00279 bool 00280 CASObjectFindType::operator() ( const CASObject* o ) const { 00281 // This is special: It does not throw an exception if it finds a 00282 // NULL pointer. So it can be used to search list holding NULL 00283 // pointer as markers. 00284 if ( o == 0 ) { 00285 return false; 00286 } 00287 return o->GetType() == t; 00288 } 00289 // --------------------------------------------------------------------------- 00290 00291 00292 00293 // --------------------------------------------------------------------------- 00294 // CASObjectFindType_Not 00295 // --------------------------------------------------------------------------- 00301 CASObjectFindType_Not::CASObjectFindType_Not ( int type ) { 00302 t = type; 00303 } 00304 00318 bool 00319 CASObjectFindType_Not::operator() ( const CASObject* o ) const { 00320 // This is special: It does not raise an exception 00321 // if it finds a NULL pointer. So it can be used to 00322 // search list holding NULL pointer as markers. 00323 if ( o == 0 ) { 00324 return false; 00325 } 00326 return o->GetType() != t; 00327 } 00328 // --------------------------------------------------------------------------- 00329 00330 // --------------------------------------------------------------------------- 00331 // CASObjectFindByAddr 00332 // --------------------------------------------------------------------------- 00340 bool 00341 CASObjectFindByAddr::operator() ( const CASObject* o ) const { 00342 if ( needle == o ) 00343 return true; 00344 return false; 00345 } 00346 00347 // --------------------------------------------------------------------------- 00348 00349 // --------------------------------------------------------------------------- 00350 // CASIsPureNumerical 00351 // --------------------------------------------------------------------------- 00360 void 00361 CASIsPureNumerical::operator() ( const CASObject* o ) { 00362 if ( !o->meta.IsPureNumerical() ) 00363 b = false; 00364 } 00365 // --------------------------------------------------------------------------- 00366 00367 // --------------------------------------------------------------------------- 00368 // CASExtractSingleValues 00369 // --------------------------------------------------------------------------- 00375 CASExtractSingleValues::CASExtractSingleValues ( const CASExtractSingleValues& o ) { 00376 l = o.l; 00377 } 00378 00384 const CASExtractSingleValues& 00385 CASExtractSingleValues::operator= ( const CASExtractSingleValues &o ) { 00386 if ( this == &o ) { 00387 return *this; 00388 } 00389 00390 l.clear(); 00391 l = o.l; 00392 00393 return *this; 00394 } 00395 00407 void 00408 CASExtractSingleValues::operator() ( CASObject* o ) { 00409 checkptr ( o ); 00410 if ( o->meta.IsSingleValue() ) { 00411 l.push_back ( o ); 00412 } 00413 } 00414 00425 void 00426 CASExtractSingleValues::Result ( std::vector<const CASObject*> &rl ) const { 00427 rl = l; 00428 } 00429 // --------------------------------------------------------------------------- 00430 00431 // --------------------------------------------------------------------------- 00432 // CASExtractNonSingleValues 00433 // --------------------------------------------------------------------------- 00439 CASExtractNonSingleValues::CASExtractNonSingleValues ( const CASExtractNonSingleValues& o ) { 00440 l = o.l; 00441 } 00442 00448 const CASExtractNonSingleValues& 00449 CASExtractNonSingleValues::operator= ( const CASExtractNonSingleValues &o ) { 00450 if ( this == &o ) { 00451 return *this; 00452 } 00453 00454 l.clear(); 00455 l = o.l; 00456 00457 return *this; 00458 } 00459 00471 void 00472 CASExtractNonSingleValues::operator() ( CASObject* o ) { 00473 checkptr ( o ); 00474 if ( !o->meta.IsSingleValue() ) { 00475 l.push_back ( o ); 00476 } 00477 } 00478 00489 void 00490 CASExtractNonSingleValues::Result ( std::vector<const CASObject*> &rl ) const { 00491 rl = l; 00492 } 00493 // --------------------------------------------------------------------------- 00494 00495 // --------------------------------------------------------------------------- 00496 // CASCalculateSortWeight 00497 // --------------------------------------------------------------------------- 00501 CASCalculateSortWeight::~CASCalculateSortWeight() { 00502 if ( weight != 0 ) 00503 CASObject::Garbage->Put ( weight ); 00504 } 00505 00511 CASCalculateSortWeight::CASCalculateSortWeight ( const CASCalculateSortWeight& o ) { 00512 weight = o.weight->Clone(); 00513 } 00514 00524 void 00525 CASCalculateSortWeight::operator() ( CASObject* o ) { 00526 if ( o->meta.IsCoefficient() ) 00527 return; 00528 00529 if ( weight == 0 ) { 00530 weight = o->SortWeight(); 00531 } else { 00532 CASObject* oldweight = weight; 00533 CASObject* weight_o = o->SortWeight(); 00534 weight = oldweight->Add ( weight_o ); 00535 CASObject::Garbage->Put ( weight_o ); 00536 CASObject::Garbage->Put ( oldweight ); 00537 } 00538 } 00539 00545 const CASCalculateSortWeight& 00546 CASCalculateSortWeight::operator= ( const CASCalculateSortWeight &o ) { 00547 if ( &o == this ) 00548 return *this; 00549 00550 if ( weight != 0 ) 00551 CASObject::Garbage->Put ( weight ); 00552 00553 weight = o.weight->Clone(); 00554 00555 return *this; 00556 } 00557 00566 CASObject* 00567 CASCalculateSortWeight::Result() const { 00568 return weight->Clone(); 00569 } 00570 // --------------------------------------------------------------------------- 00571
1.4.7