src/tools/values/vCollection.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "vCore.h"
00029 #include "vCollection.h"
00030 
00031 namespace vValue {
00032 namespace Expr {
00033 namespace Collection {
00034 
00035 myCol BaseExt::GetCol(void) const {
00036     myCol col;
00037     BasePtr node(this->copy());
00038     col.insert(node);
00039     return col;
00040 }
00041 
00042 
00043 Variant ColNode::GetValue(void) const         { return (*m_col.begin())->GetValue(); }
00044 int ColNode::GetInt(void) const               { return (*m_col.begin())->GetInt(); }
00045 float ColNode::GetFloat(void) const           { return (*m_col.begin())->GetFloat(); }
00046 myCol ColNode::GetCol(void) const { return m_col; }
00047 
00048 myCol getCol(BasePtr base) {
00049     BaseExt const *baseExt = dynamic_cast<BaseExt*>(base->copy());
00050     myCol ijk(baseExt->GetCol());
00051     return ijk;
00052 }
00053 
00054 
00055 bool ColNode::operator==(Base const &other) const {
00056     //    return m_col == static_cast<myCol >(other);
00057     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00058     return m_col == static_cast<myCol >(*baseExt) ;
00059 }
00060 bool ColNode::operator!=(Base const &other) const {
00061     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00062     return m_col != static_cast<myCol >(*baseExt);
00063 }
00064 bool ColNode::operator>=(Base const &other) const {
00065     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00066     return m_col >= static_cast<myCol >(*baseExt);
00067 }
00068 bool ColNode::operator<=(Base const &other) const {
00069     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00070     return m_col <= static_cast<myCol >(*baseExt);
00071 }
00072 bool ColNode::operator> (Base const &other) const {
00073     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00074     return m_col >  static_cast<myCol >(*baseExt);
00075 }
00076 bool ColNode::operator< (Base const &other) const {
00077     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00078     return m_col <  static_cast<myCol >(*baseExt);
00079 }
00080 
00081 
00082 Variant ColUnary::GetValue(void) const         { return (*_operation().begin())->GetValue(); }
00083 int ColUnary::GetInt(void) const               { return (*_operation().begin())->GetInt(); }
00084 float ColUnary::GetFloat(void) const           { return (*_operation().begin())->GetFloat(); }
00085 myCol ColUnary::GetCol(void) const { return _operation(); }
00086 
00087 bool ColUnary::operator==(Base const &other) const {
00088     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00089     return _operation() == static_cast<myCol >(*baseExt);
00090 }
00091 bool ColUnary::operator!=(Base const &other) const {
00092     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00093     return _operation() != static_cast<myCol >(*baseExt);
00094 }
00095 bool ColUnary::operator>=(Base const &other) const {
00096     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00097     return _operation() >= static_cast<myCol >(*baseExt);
00098 }
00099 bool ColUnary::operator<=(Base const &other) const {
00100     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00101     return _operation() <= static_cast<myCol >(*baseExt);
00102 }
00103 bool ColUnary::operator> (Base const &other) const {
00104     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00105     return _operation() >  static_cast<myCol >(*baseExt);
00106 }
00107 bool ColUnary::operator< (Base const &other) const {
00108     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00109     return _operation() <  static_cast<myCol >(*baseExt);
00110 }
00111 
00112 
00113 myCol ColPickOne::_operation() const
00114 {
00115     myCol ijk = getCol(ColUnary::m_child);
00116 
00117     myCol tempCol;
00118     int number = ijk.size();
00119     if(number != 0) {
00120         int ran = number / 2;
00121 
00122         myCol::iterator iter = ijk.begin();
00123         int i=0;
00124         for (i=0; i<ran; i++)
00125             ++iter;
00126         BasePtr asdf((*iter)->copy());
00127         tempCol.insert(asdf);
00128     }
00129     return tempCol;
00130 }
00131 
00132 
00133 myCol ColBinary::_operation(void) const {
00134     myCol res;
00135 
00136     myCol a = getCol(ColBinary::r_child);
00137     myCol b = getCol(ColBinary::l_child);
00138 
00139     set_union(a.begin(),
00140               a.end(),
00141               b.begin(),
00142               b.end(),
00143               inserter(res, res.begin()),
00144               FooPtrOps());
00145 
00146     return res;
00147 }
00148 
00149 bool ColBinary::operator==(Base const &other) const {
00150     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00151     return _operation() == static_cast<myCol >(*baseExt);
00152 }
00153 bool ColBinary::operator!=(Base const &other) const {
00154     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00155     return _operation() != static_cast<myCol >(*baseExt);
00156 }
00157 bool ColBinary::operator>=(Base const &other) const {
00158     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00159     return _operation() >= static_cast<myCol >(*baseExt);
00160 }
00161 bool ColBinary::operator<=(Base const &other) const {
00162     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00163     return _operation() <= static_cast<myCol >(*baseExt);
00164 }
00165 bool ColBinary::operator> (Base const &other) const {
00166     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00167     return _operation() >  static_cast<myCol >(*baseExt);
00168 }
00169 bool ColBinary::operator< (Base const &other) const {
00170     BaseExt const *baseExt = dynamic_cast<BaseExt*>(const_cast<Base*>(&other));
00171     return _operation() <  static_cast<myCol >(*baseExt);
00172 }
00173 
00174 Variant ColBinary::GetValue(void) const         { return (*_operation().begin())->GetValue(); }
00175 int ColBinary::GetInt(void) const               { return (*_operation().begin())->GetInt(); }
00176 float ColBinary::GetFloat(void) const           { return (*_operation().begin())->GetFloat(); }
00177 myCol ColBinary::GetCol(void) const             { return _operation(); }
00178 
00179 void displayCol(myCol res) {
00180     myCol::iterator iter;
00181     for(iter = res.begin();
00182             iter != res.end();
00183             ++iter) {
00184         std::cout << (*iter)->GetInt() << " ";
00185     }
00186     std::cout << std::endl;
00187 }
00188 
00189 myCol ColUnion::_operation(void) const {
00190     myCol res;
00191 
00192     myCol a = getCol(ColBinary::r_child);
00193     myCol b = getCol(ColBinary::l_child);
00194 
00195     set_union(a.begin(),
00196               a.end(),
00197               b.begin(),
00198               b.end(),
00199               inserter(res, res.begin()),
00200               FooPtrOps());
00201 
00202     return res;
00203 }
00204 
00205 
00206 myCol ColIntersection::_operation(void) const {
00207     myCol res;
00208     myCol a = getCol(ColBinary::r_child);
00209     myCol b = getCol(ColBinary::l_child);
00210 
00211     set_intersection(a.begin(),
00212                      a.end(),
00213                      b.begin(),
00214                      b.end(),
00215                      inserter(res, res.begin()),
00216                      FooPtrOps());
00217 
00218     return res;
00219 }
00220 
00221 
00222 
00223 
00224 myCol ColDifference::_operation(void) const {
00225     myCol res;
00226     myCol a = getCol(ColBinary::r_child);
00227     myCol b = getCol(ColBinary::l_child);
00228 
00229     set_difference(a.begin(),
00230                    a.end(),
00231                    b.begin(),
00232                    b.end(),
00233                    inserter(res, res.begin()),
00234                    FooPtrOps());
00235 
00236     return res;
00237 }
00238 
00239 }
00240 }
00241 }
00242 
00243 

Generated on Sat Mar 15 22:56:03 2008 for Armagetron Advanced by  doxygen 1.5.4