00001 00002 /* 00003 | Author: Michael Schmidt; 00004 | Gunnar Jehl 00005 | 00006 | ************************* SOFTWARE LICENSE AGREEMENT *********************** 00007 | This source code is published under the BSD License. 00008 | 00009 | See file 'LICENSE.txt' that comes with this distribution or 00010 | http://dbis.informatik.uni-freiburg.de/index.php?project=GCX/license.php 00011 | for the full license agreement. 00012 | 00013 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00017 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 | POSSIBILITY OF SUCH DAMAGE. 00024 | **************************************************************************** 00025 */ 00026 00035 #include "pathenvironment.h" 00036 00037 PathEnvironment::PathEnvironment() { 00038 env[TAGID_ROOT] = new PathExpression(); 00039 ParVarMap *parvarmap = ParVarMap::getInstance(); 00040 vector < unsigned >*varsq = parvarmap->getVarsq(); 00041 PathExpression *p; 00042 unsigned parvar; 00043 00044 vector < PathExpression * >insert_paths; 00045 vector < PathStepExpression * >*insert_steps; 00046 for (unsigned i = 1; i < varsq->size(); i++) { // omit root variable! 00047 insert_paths.clear(); 00048 p = new PathExpression(); 00049 if (parvarmap->getPath((*varsq)[i])) { 00050 insert_paths.push_back(parvarmap->getPath((*varsq)[i])); 00051 } 00052 00053 parvar = parvarmap->getParVar((*varsq)[i]); 00054 while (parvar != TAGID_ROOT) { 00055 if (parvarmap->getPath(parvar)) { 00056 insert_paths.push_back(parvarmap->getPath(parvar)); 00057 } 00058 parvar = parvarmap->getParVar(parvar); 00059 } 00060 00061 for (int j = insert_paths.size() - 1; j >= 0; j--) { 00062 insert_steps = insert_paths[j]->getPathSteps(); 00063 for (unsigned k = 0; k < insert_steps->size(); k++) { 00064 p->addPathStep((*insert_steps)[k]->clone()); 00065 } 00066 } 00067 00068 insertPath((*varsq)[i], p); 00069 } 00070 } 00071 00072 PathEnvironment::~PathEnvironment() { 00073 PEnv::iterator it = env.begin(); 00074 00075 while (it != env.end()) { 00076 delete it->second; 00077 00078 env.erase(it); 00079 it = env.begin(); 00080 } 00081 } 00082 00083 void PathEnvironment::insertPath(unsigned var, PathExpression * path) { 00084 env[var] = path; 00085 } 00086 00087 void PathEnvironment::print(OutputStream & dos) { 00088 PEnv::iterator it; 00089 00090 for (it = env.begin(); it != env.end(); it++) { 00091 dos << "$" << VarName::getInstance()->getVarname(it->first) << " -> "; 00092 if (!it->second->isEmptyPath()) { 00093 dos << *(it->second); 00094 } else { 00095 dos << "%"; 00096 } 00097 dos << NEWLINE; 00098 } 00099 } 00100 00101 PathExpression *PathEnvironment::getPath(unsigned var) { 00102 PEnv::iterator it = env.find(var); 00103 00104 return it->second; 00105 } 00106 00107 PathExpression *PathEnvironment::getPathBetween(unsigned end, unsigned start) { 00108 PathExpression *p = new PathExpression(); 00109 00110 PathExpression *end_path = getPath(end); 00111 00112 for (unsigned i = getPath(start)->getPathSteps()->size(); 00113 i < end_path->getPathSteps()->size(); i++) { 00114 p->addPathStep(end_path->getPathStepAt(i)->clone()); 00115 } 00116 00117 return p; 00118 }