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: VariableRepository.hpp,v 1.2 2007/05/20 23:02:48 delpinux Exp $ 00019 00020 #ifndef VARIABLE_PARSER_REPOSITORY_HPP 00021 #define VARIABLE_PARSER_REPOSITORY_HPP 00022 00023 #include <map> 00024 #include <vector> 00025 00026 #include <ReferenceCounting.hpp> 00027 #include <Variable.hpp> 00028 00029 #include <Stringify.hpp> 00030 #include <ErrorHandler.hpp> 00031 00039 class VariableRepository 00040 : public ThreadStaticBase<VariableRepository> 00041 { 00042 private: 00044 typedef std::map<std::string,ReferenceCounting<Variable> > Container; 00045 std::vector<Container> 00046 __variableList; 00048 size_t __blockLevel; 00050 VariableRepository(const VariableRepository& vpr); 00051 00052 public: 00060 ReferenceCounting<Variable> find(const std::string& name) const; 00061 00069 template <typename VariableType> 00070 ReferenceCounting<VariableType> findVariable(const std::string& name) const 00071 { 00072 ReferenceCounting<Variable> reference = this->find(name); 00073 Variable* variable = reference; 00074 ASSERT(variable != 0); 00075 00076 VariableType* castedVariable = dynamic_cast<VariableType*>(variable); 00077 if(not(castedVariable)) { 00078 throw ErrorHandler(__FILE__,__LINE__, 00079 "cannot cast "+name 00080 +" of type "+stringify(variable->type()), 00081 ErrorHandler::unexpected); 00082 } 00083 00084 return castedVariable; 00085 } 00086 00092 void add(ReferenceCounting<Variable> v); 00093 00099 void remove(const std::string& name); 00100 00105 void beginBlock(); 00106 00111 void endBlock(); 00112 00117 VariableRepository(); 00118 00123 ~VariableRepository(); 00124 }; 00125 00126 #endif // VARIABLE_PARSER_REPOSITORY_HPP
1.5.6