.. _program_listing_file_src_VALfiles_FastEnvironment.h: Program Listing for File FastEnvironment.h ========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/VALfiles/FastEnvironment.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /************************************************************************ * Copyright 2008, Strathclyde Planning Group, * Department of Computer and Information Sciences, * University of Strathclyde, Glasgow, UK * http://planning.cis.strath.ac.uk/ * * Maria Fox, Richard Howey and Derek Long - VAL * Stephen Cresswell - PDDL Parser * * This file is part of VAL, the PDDL validator. * * VAL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * VAL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAL. If not, see . * ************************************************************************/ #ifndef __FASTENV #define __FASTENV #include using std::vector; #include #include #include namespace VAL { template class IDsymbol : public U { private: int symId; public: IDsymbol(const string & nm,int Id) : U(nm), symId(Id) {}; int getId() const {return symId;}; }; template class IDSymbolFactory : public SymbolFactory { private: static int cnt; int symId; public: IDSymbolFactory() : symId(0) {cnt = 0;}; IDSymbolFactory(int n) : symId(n) {}; T * build(const string & nm) { ++cnt;return new IDsymbol(nm,symId++);}; int numSyms() const {return symId;}; static int getCount() {return cnt;}; }; template int IDSymbolFactory::cnt = 0; class id_var_symbol_table : public var_symbol_table { private: IDSymbolFactory * symFac; public: id_var_symbol_table() : symFac(new IDSymbolFactory()) { setFactory(symFac); }; id_var_symbol_table(id_var_symbol_table * i) : symFac(new IDSymbolFactory(IDSymbolFactory::getCount())) { setFactory(symFac); }; int numSyms() const {return symFac->numSyms();}; }; class IDopTabFactory : public VarTabFactory { private: id_var_symbol_table * idv; public: var_symbol_table * buildOpTab() { idv = new id_var_symbol_table; return idv; }; var_symbol_table * buildRuleTab() { idv = new id_var_symbol_table; return idv; }; var_symbol_table * buildExistsTab() { return new id_var_symbol_table(idv); }; var_symbol_table * buildForallTab() { return new id_var_symbol_table(idv); }; }; class FastEnvironment { private: vector syms; public: FastEnvironment(const FastEnvironment & other) : syms(other.syms) {}; FastEnvironment(int x) : syms(x,static_cast(0)) {}; void extend(int x) { syms.resize(syms.size()+x,static_cast(0)); }; FastEnvironment * copy() const { return new FastEnvironment(*this); }; const_symbol * operator[](const symbol * s) const { if(const const_symbol * c = dynamic_cast(s)) { return const_cast(c); }; return syms[static_cast*>(s)->getId()]; }; const_symbol * & operator[](const symbol * s) { static const_symbol * c; if((c = const_cast(dynamic_cast(s)))) { return c; }; return syms[static_cast*>(s)->getId()]; }; typedef vector::const_iterator const_iterator; const_iterator begin() const {return syms.begin();}; const_iterator end() const {return syms.end();}; const vector & getCore() const {return syms;}; }; template class LiteralParameterIterator { private: FastEnvironment * env; TI pi; public: LiteralParameterIterator(FastEnvironment * f,TI p) : env(f), pi(p) {}; const_symbol * operator*() { return (*env)[*pi]; }; LiteralParameterIterator & operator++() { ++pi; return *this; }; bool operator==(const LiteralParameterIterator & li) const { return pi==li.pi; }; bool operator!=(const LiteralParameterIterator & li) const { return pi!=li.pi; }; LiteralParameterIterator operator+(int x); }; template struct plusIt { LiteralParameterIterator operator()(TI pi,FastEnvironment * env,int x) const { for(int c = 0;c < x;++c,++pi); return LiteralParameterIterator(env,pi); }; }; template struct plusIt { LiteralParameterIterator operator()(TI pi,FastEnvironment * env,int x) const { return LiteralParameterIterator(env,pi+x); }; }; template LiteralParameterIterator LiteralParameterIterator::operator+(int x) { return plusIt::iterator_category>()(pi,env,x); }; template LiteralParameterIterator makeIterator(FastEnvironment * f,TI p) { return LiteralParameterIterator(f,p); }; }; #endif