00001 /**** , [ bobocheTree.cc ], 00002 Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 *************************************************************************/ 00022 00023 #include "Strategy.hh" 00024 00025 00026 StrategyImp::StrategyImp(StrategyNode tag) { 00027 // cout<<"Strategy imp constructor"<<endl; 00028 pointers=1; 00029 zetag=tag; 00030 // cout<<"strategyimp constructor fini"<<endl; 00031 } 00032 00033 00034 StrategyImp::~StrategyImp() { 00035 } 00036 00037 00038 Strategy::Strategy() { 00039 // cout<<"strategy default"<<endl; 00040 StrategyNode tag = StrategyNode::Dummy(); 00041 imp = new StrategyImp(tag); 00042 } 00043 00044 Strategy::Strategy(StrategyNode tag) { 00045 // cout<<"Strategy with tag"<<endl; 00046 imp = new StrategyImp(tag); 00047 //cout<<"passed imp creation. End of strategy creator"<<endl; 00048 } 00049 00050 00051 Strategy::Strategy(bool qt,int VMin, int VMax, int scope, vector<int> values) { 00052 // cout<<"strategy with values"<<endl; 00053 StrategyNode tag(2,qt,VMin,VMax,scope); 00054 tag.valeurs=values; 00055 imp = new StrategyImp(tag); 00056 00057 } 00058 00059 00060 Strategy::Strategy(const Strategy& tree) { 00061 // cout<<"Strategy copy"<<endl; 00062 imp = tree.imp; 00063 (imp->pointers)++; 00064 } 00065 00066 00067 Strategy& Strategy::operator = (const Strategy& rvalue) { 00068 // cout<<"Strategy = "<<endl; 00069 if (imp != NULL) { 00070 (imp->pointers)--; 00071 if ( (imp->pointers) == 0) { 00072 // cout<<"no more references for the imp. Delete"<<endl; 00073 delete imp; 00074 } 00075 } 00076 imp = rvalue.imp; 00077 (imp->pointers)++; 00078 return *this; 00079 } 00080 00081 00082 Strategy::~Strategy() { 00083 // cout<<"strategy destructor"<<endl; 00084 (imp->pointers)--; 00085 if ( (imp->pointers) == 0) { 00086 // cout<<"no more references for the imp. Delete"<<endl; 00087 delete imp; 00088 } 00089 } 00090 00091 00092 StrategyNode Strategy::getTag() { 00093 return imp->zetag; 00094 } 00095 00096 00097 int Strategy::degree() { 00098 return imp->nodes.size(); 00099 } 00100 00101 00102 Strategy Strategy::getChild(int i) { 00103 if (i<0 || i>=degree() ) {cout<<"Child "<<i<<" does not exist"<<endl;abort();} 00104 return imp->nodes[i]; 00105 } 00106 00107 00108 void Strategy::attach(Strategy child) { 00109 if (child.isDummy()) { 00110 for (int i=0;i<child.degree();i++) { 00111 imp->nodes.push_back(child.getChild(i)); 00112 } 00113 } 00114 else 00115 imp->nodes.push_back(child); 00116 } 00117 00118 Strategy Strategy::STrue() { 00119 Strategy ret(StrategyNode::STrue()); 00120 return ret; 00121 } 00122 00123 Strategy Strategy::SFalse() { 00124 Strategy ret(StrategyNode::SFalse()); 00125 return ret; 00126 } 00127 00128 Strategy Strategy::Dummy() { 00129 Strategy ret(StrategyNode::Dummy()); 00130 return ret; 00131 }