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: UnknownListExpression.hpp,v 1.7 2007/02/08 23:19:38 delpinux Exp $ 00019 00020 #ifndef UNKNOWN_LIST_EXPRESSION_HPP 00021 #define UNKNOWN_LIST_EXPRESSION_HPP 00022 00023 #include <Expression.hpp> 00024 #include <Variable.hpp> 00025 00026 #include <UnknownExpression.hpp> 00027 00028 #include <Stringify.hpp> 00029 #include <ErrorHandler.hpp> 00030 00031 #include <list> 00032 00040 class UnknownListExpression 00041 : public Expression 00042 { 00043 public: 00044 typedef std::list<ReferenceCounting<UnknownExpression> > listType; 00045 00046 typedef listType::iterator iterator; 00047 typedef listType::const_iterator const_iterator; 00048 00049 virtual UnknownListExpression::iterator begin() = 0; 00050 virtual UnknownListExpression::const_iterator begin() const = 0; 00051 virtual UnknownListExpression::const_iterator end() const = 0; 00052 00053 virtual size_t size() const = 0; 00054 00055 virtual size_t number(const std::string& name) const = 0; 00056 00057 UnknownListExpression() 00058 : Expression(Expression::unknownList) 00059 { 00060 ; 00061 } 00062 00063 UnknownListExpression(const UnknownListExpression& u) 00064 : Expression(u) 00065 { 00066 ; 00067 } 00068 00069 virtual ~UnknownListExpression() 00070 { 00071 ; 00072 } 00073 }; 00074 00075 /* 00076 class UnknownListExpressionVariable 00077 : public UnknownListExpression 00078 { 00079 private: 00080 ReferenceCounting<UnknownListVariable> __unknownlistVariable; 00081 00082 std::ostream& put(std::ostream& os) const 00083 { 00084 os << (*__unknownlistVariable).name() << ": " << (*(*__unknownlistVariable).expression()); 00085 return os; 00086 } 00087 00088 public: 00089 void execute() 00090 { 00091 ; 00092 } 00093 00094 UnknownListExpressionVariable(ReferenceCounting<UnknownListVariable> r); 00095 00096 UnknownListExpressionVariable(const UnknownListExpressionVariable& e); 00097 00098 ~UnknownListExpressionVariable(); 00099 }; 00100 */ 00101 00102 class UnknownListExpressionSet 00103 : public UnknownListExpression 00104 { 00105 protected: 00106 listType __list; 00107 00108 private: 00109 std::ostream& put(std::ostream& os) const; 00110 00111 public: 00112 UnknownListExpressionSet::listType::iterator begin() 00113 { 00114 return __list.begin(); 00115 } 00116 00117 UnknownListExpressionSet::listType::const_iterator begin() const 00118 { 00119 return __list.begin(); 00120 } 00121 00122 UnknownListExpressionSet::listType::const_iterator end() const 00123 { 00124 return __list.end(); 00125 } 00126 00127 inline size_t size() const 00128 { 00129 return __list.size(); 00130 } 00131 00132 inline size_t number(const std::string& name) const 00133 { 00134 size_t n = 0; 00135 for(listType::const_iterator i = __list.begin(); i != __list.end(); ++i) { 00136 if ((*i)->name() == name) { 00137 return n; 00138 } 00139 ++n; 00140 } 00141 00142 const std::string errorMsg 00143 = "\""+name+"\" is not a variable of the unkown list"; 00144 00145 throw ErrorHandler(__FILE__,__LINE__, 00146 errorMsg, 00147 ErrorHandler::unexpected); 00148 return 0; 00149 } 00150 00151 listType& giveList() 00152 { 00153 return __list; 00154 } 00155 00156 void add(ReferenceCounting<UnknownExpression> u) { 00157 for (listType::const_iterator i = __list.begin(); 00158 i != __list.end(); ++i) { 00159 if (*i == u) { 00160 const std::string errorMsg 00161 = stringify(*u)+" has been declared twice in unknown list"; 00162 00163 throw ErrorHandler(__FILE__,__LINE__, 00164 errorMsg, 00165 ErrorHandler::normal); 00166 } 00167 } 00168 __list.push_back(u); 00169 } 00170 00171 void execute() 00172 { 00173 ; 00174 } 00175 00176 UnknownListExpressionSet() 00177 : UnknownListExpression() 00178 { 00179 ; 00180 } 00181 00182 UnknownListExpressionSet(const UnknownListExpressionSet& l) 00183 : UnknownListExpression(l), 00184 __list(l.__list) 00185 { 00186 ; 00187 } 00188 00189 ~UnknownListExpressionSet() 00190 { 00191 ; 00192 } 00193 }; 00194 00195 #endif // UNKNOWN_LIST_EXPRESSION_HPP
1.5.6