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 "dependencyset.h" 00036 00037 DependencySet::DependencySet(unsigned _var):var(_var) { 00038 } 00039 00040 DependencySet::~DependencySet() { 00041 for (unsigned i = 0; i < tuples.size(); i++) { 00042 delete tuples[i]; 00043 } 00044 } 00045 00046 void DependencySet::insertTuple(PathExpression * path, bool pos, bool dos, 00047 bool cond) { 00048 PathExpression *path_copy = path ? path->clone() : new PathExpression(); 00049 00050 if (pos && !path_copy->isEmptyPath()) { 00051 path_copy->getTailPathStep()-> 00052 setAttribute(new PathStepAttributePosition(1)); 00053 } 00054 if (dos) { 00055 path_copy->addPathStep(new PathStepNodeExpression(at_dos)); 00056 } 00057 DependencyTuple *tuple = new DependencyTuple(path_copy, cond); 00058 00059 tuples.push_back(tuple); 00060 } 00061 00062 void DependencySet::print(OutputStream & dos) { 00063 for (unsigned i = 0; i < tuples.size(); i++) { 00064 tuples[i]->print(dos); 00065 if (i != tuples.size() - 1) { 00066 dos << ", " << NEWLINE << " "; 00067 } 00068 } 00069 } 00070 00071 void DependencySet::removeSyntacticallyEqualTuple(PassiveProjectionTree * ppt) { 00072 for (unsigned i = 0; i < tuples.size() - 1; i++) { 00073 for (unsigned j = i + 1; j < tuples.size(); j++) { 00074 if (tuples[i]->isSyntacticallyEqualTo(tuples[j])) { 00075 tuples[j]->registerToPassiveProjectionTree(var, ppt); 00076 delete tuples[j]; 00077 00078 tuples.erase(tuples.begin() + j); 00079 j--; 00080 } 00081 } 00082 } 00083 } 00084 00085 void DependencySet::removeSemanticallyContainedTuple(PassiveProjectionTree * 00086 ppt) { 00087 for (unsigned i = 0; i < tuples.size(); i++) { 00088 for (unsigned j = 0; j < tuples.size(); j++) { 00089 if (j != i) { 00090 if (tuples[j]->isSemanticallyContainedIn(tuples[i])) { 00091 tuples[j]->registerToPassiveProjectionTree(var, ppt); 00092 delete tuples[j]; 00093 00094 tuples.erase(tuples.begin() + j); 00095 if (j >= i) { 00096 j--; 00097 } else { 00098 i--; 00099 if (i < tuples.size()) { 00100 j--; 00101 } else { 00102 j = tuples.size(); 00103 } 00104 } 00105 } 00106 } 00107 } 00108 } 00109 }