00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 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, or (at your option) 00007 // 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 Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: BoundaryExpressionReferences.cpp,v 1.1 2006/08/27 21:33:53 delpinux Exp $ 00019 00020 #include <BoundaryExpressionReferences.hpp> 00021 #include <BoundaryReferences.hpp> 00022 00023 std::ostream& 00024 BoundaryExpressionReferences:: 00025 put(std::ostream& os) const 00026 { 00027 for (BoundaryExpressionReferences::ReferencesSet::const_iterator i 00028 = __references.begin(); 00029 i != __references.end(); ++i) { 00030 if (i != __references.begin()) { 00031 os << ','; 00032 } 00033 os << (**i); 00034 } 00035 return os; 00036 } 00037 00038 void 00039 BoundaryExpressionReferences:: 00040 execute() 00041 { 00042 for (BoundaryExpressionReferences::ReferencesSet::iterator i 00043 = __references.begin(); 00044 i != __references.end(); ++i) 00045 { 00046 ReferenceCounting<RealExpression> ref = *i; 00047 (*ref).execute(); 00048 } 00049 00050 BoundaryReferences* b= new BoundaryReferences(); 00051 00052 for (BoundaryExpressionReferences::ReferencesSet::iterator i 00053 = __references.begin(); 00054 i != __references.end(); ++i) { 00055 ReferenceCounting<RealExpression> ref = *i; 00056 const double value = (*ref).realValue(); 00057 if ((value<0) or (value != int(value))) { 00058 throw ErrorHandler(__FILE__,__LINE__, 00059 stringify(value) 00060 +" is not a correct boundary reference\n" 00061 +"Boundary references must be positive integers", 00062 ErrorHandler::normal); 00063 } 00064 b->add(static_cast<size_t>(value)); 00065 } 00066 __boundary = b; 00067 } 00068 00069 00070 BoundaryExpressionReferences:: 00071 BoundaryExpressionReferences() 00072 : BoundaryExpression(BoundaryExpression::references) 00073 { 00074 ; 00075 } 00076 00077 BoundaryExpressionReferences:: 00078 BoundaryExpressionReferences(const std::string& boundaryName) 00079 : BoundaryExpression(BoundaryExpression::references) 00080 { 00081 if (boundaryName=="xmin") { 00082 __references.insert(new RealExpressionValue(0)); 00083 return; 00084 } 00085 if (boundaryName=="xmax") { 00086 __references.insert(new RealExpressionValue(1)); 00087 return; 00088 } 00089 if (boundaryName=="ymin") { 00090 __references.insert(new RealExpressionValue(2)); 00091 return; 00092 } 00093 if (boundaryName=="ymax") { 00094 __references.insert(new RealExpressionValue(3)); 00095 return; 00096 } 00097 if (boundaryName=="zmin") { 00098 __references.insert(new RealExpressionValue(4)); 00099 return; 00100 } 00101 if (boundaryName=="zmax") { 00102 __references.insert(new RealExpressionValue(5)); 00103 return; 00104 } 00105 throw ErrorHandler(__FILE__,__LINE__, 00106 "unknown boundary name: '"+boundaryName+"'", 00107 ErrorHandler::unexpected); 00108 } 00109 00110 BoundaryExpressionReferences:: 00111 BoundaryExpressionReferences(const BoundaryExpressionReferences& r) 00112 : BoundaryExpression(r), 00113 __references(r.__references) 00114 { 00115 ; 00116 } 00117 00118 BoundaryExpressionReferences:: 00119 ~BoundaryExpressionReferences() 00120 { 00121 ; 00122 }
1.5.6