BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Kinetic/internal/Instantaneous_adaptor.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Stanford University (USA).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Kinetic/internal/Instantaneous_adaptor.h $
00016 // $Id: Instantaneous_adaptor.h 44363 2008-07-23 15:07:16Z hoffmann $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 #ifndef CGAL_INSTANTANEOUS_ADAPTOR_H
00022 #define CGAL_INSTANTANEOUS_ADAPTOR_H
00023 #include <CGAL/Kinetic/basic.h>
00024 #include <functional>
00025 
00026 CGAL_KINETIC_BEGIN_NAMESPACE;
00027 
00029 
00034 template <class Static_predicate, class Kinetic_predicate, class Rep, class Argument>
00035 class Instantaneous_adaptor
00036 {
00037   typedef typename Rep::Time Time;
00038 
00039   BOOST_STATIC_ASSERT((boost::is_convertible<Time, typename Kinetic_predicate::Time>::value));
00040 public:
00041   Instantaneous_adaptor(typename Rep::Handle rep,
00042                         Static_predicate pred,
00043                         Kinetic_predicate kpred): rep_(rep), pred_(pred), kpred_(kpred) {
00044   }
00045 
00046   typedef typename Static_predicate::result_type result_type;
00047   typedef Argument argument_type;
00048   typedef argument_type first_argument_type;
00049   typedef argument_type second_argument_type;
00050   typedef argument_type third_argument_type;
00051   typedef argument_type fourth_argument_type;
00052   typedef argument_type fifth_argument_type;
00053 
00054   result_type operator()(const first_argument_type &arg0) const
00055   {
00056     result_type ret;
00057     //bool check;
00058 
00059     if (rep_->time_is_nt() && !rep_->time_after()) {
00060       ret= pred_(rep_->static_object(arg0));
00061       //check= kpred_(rep_->kinetic_object(arg0), rep_->time());
00062     } else if (rep_->time_after()) {
00063       ret= static_cast<result_type>(kpred_(rep_->kinetic_object(arg0), rep_->time()));
00064     } else {
00065       ret= static_cast<result_type>(kpred_(rep_->kinetic_object(arg0), rep_->time()));
00066     }
00067     return ret;
00068   }
00069 
00070   result_type operator()(const first_argument_type &arg0,
00071                          const second_argument_type &arg1) const
00072   {
00073     if (rep_->time_is_nt() && !rep_->time_after()) {
00074       //std::cout << "Comparing " << arg0 << " and " << arg1 << " at time " << rep_->time() << std::endl;
00075       result_type ret= pred_(rep_->static_object(arg0), rep_->static_object(arg1));
00076       //std::cout << "Got " << ret << std::endl;
00077       //result_type check= kpred_(rep_->kinetic_object(arg0), rep_->kinetic_object(arg1), rep_->time());
00078       //CGAL_assertion(ret==check || ret== CGAL::ZERO);
00079       return ret;
00080     } else if (rep_->time_after()) {
00081       return static_cast<result_type>(kpred_.sign_after(rep_->kinetic_object(arg0),
00082                                                         rep_->kinetic_object(arg1),
00083                                                         rep_->time()));
00084     } else {
00085       return static_cast<result_type>(kpred_.sign_at(rep_->kinetic_object(arg0),
00086                                                      rep_->kinetic_object(arg1),
00087                                                      rep_->time()));
00088     }
00089   }
00090 
00091   result_type operator()(const first_argument_type &arg0,
00092                          const second_argument_type &arg1,
00093                          const third_argument_type &arg2) const
00094   {
00095     if (rep_->time_is_nt() && !rep_->time_after()) {
00096       return pred_(rep_->static_object(arg0), rep_->static_object(arg1),
00097                    rep_->static_object(arg2));
00098     } else if (rep_->time_after()) {
00099       return static_cast<result_type>(kpred_.sign_after(rep_->kinetic_object(arg0),
00100                                                         rep_->kinetic_object(arg1),
00101                                                         rep_->kinetic_object(arg2),
00102                                                         rep_->time()));
00103     } else {
00104       return static_cast<result_type>(kpred_.sign_at(rep_->kinetic_object(arg0),
00105                                                      rep_->kinetic_object(arg1),
00106                                                      rep_->kinetic_object(arg2),
00107                                                      rep_->time()));
00108     }
00109   }
00110 
00111   result_type operator()(const first_argument_type &arg0,
00112                          const second_argument_type &arg1,
00113                          const third_argument_type &arg2,
00114                          const fourth_argument_type &arg3) const
00115   {
00116     if (rep_->time_is_nt() && !rep_->time_after()) {
00117       return pred_(rep_->static_object(arg0), rep_->static_object(arg1),
00118                    rep_->static_object(arg2), rep_->static_object(arg3));
00119     } else if (rep_->time_after()){
00120       return static_cast<result_type>(kpred_.sign_after(rep_->kinetic_object(arg0),
00121                                                         rep_->kinetic_object(arg1),
00122                                                         rep_->kinetic_object(arg2),
00123                                                         rep_->kinetic_object(arg3),
00124                                                         rep_->time()));
00125     } else {
00126       return static_cast<result_type>(kpred_.sign_at(rep_->kinetic_object(arg0),
00127                                                      rep_->kinetic_object(arg1),
00128                                                      rep_->kinetic_object(arg2),
00129                                                      rep_->kinetic_object(arg3),
00130                                                      Time(rep_->time())));
00131     }
00132   }
00133 
00134   result_type operator()(const first_argument_type &arg0,
00135                          const second_argument_type &arg1,
00136                          const third_argument_type &arg2,
00137                          const fourth_argument_type &arg3,
00138                          const fifth_argument_type &arg4) const
00139   {
00140     if (rep_->time_is_nt() && !rep_->time_after()) {
00141       return pred_(rep_->static_object(arg0), rep_->static_object(arg1),
00142                    rep_->static_object(arg2), rep_->static_object(arg3),
00143                    rep_->static_object(arg4));
00144     } else if (rep_->time_after()) {
00145       return static_cast<result_type>(kpred_.sign_at(rep_->kinetic_object(arg0),
00146                                                      rep_->kinetic_object(arg1),
00147                                                      rep_->kinetic_object(arg2),
00148                                                      rep_->kinetic_object(arg3),
00149                                                      rep_->kinetic_object(arg4),
00150                                                      rep_->time()));
00151     } else {
00152       return static_cast<result_type>(kpred_.sign_at(rep_->kinetic_object(arg0),
00153                                                      rep_->kinetic_object(arg1),
00154                                                      rep_->kinetic_object(arg2),
00155                                                      rep_->kinetic_object(arg3),
00156                                                      rep_->kinetic_object(arg4),
00157                                                      rep_->time()));
00158     }
00159   }
00160 
00161 protected:
00162 
00163   typename Rep::Handle rep_;
00164   Static_predicate pred_;
00165   Kinetic_predicate kpred_;
00166 };
00167 
00168 CGAL_KINETIC_END_NAMESPACE;
00169 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines