DerivedPseudoJetHelper.hh

00001 //STARTHEADER
00002 // $Id: DerivedPseudoJetHelper.hh 1885 2011-01-27 14:50:21Z salam $
00003 //
00004 // Copyright (c) 2005-2010, Matteo Cacciari, Gavin Salam and Gregory Soyez
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet; if not, write to the Free Software
00026 //  Foundation, Inc.:
00027 //      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //----------------------------------------------------------------------
00029 //ENDHEADER
00030 
00031 #ifndef __DERIVED_PSEUDOJET_HELPER_HH__
00032 #define __DERIVED_PSEUDOJET_HELPER_HH__
00033 
00034 #include "fastjet/internal/numconsts.hh"
00035 
00036 FASTJET_BEGIN_NAMESPACE
00037 
00038 //-------------------------------------------------------------------
00039 // since C++ does not support partial specialisation of template
00040 // member functions, we shall need an extra class that actually does
00041 // the job (partial spec is allowed in the case of a class)
00042 //-------------------------------------------------------------------
00043 
00044 // fwd declaration of PJ
00045 class PseudoJet;
00046 
00047 /// \if internal_doc
00048 /// @ingroup internal
00049 /// \class DerivedPseudoJetHelper
00050 /// Template helper to see if a class is derived from PseudoJet
00051 /// (default version)
00052 ///
00053 /// This template construct depends on a type and a boolean value.  we
00054 /// shall implement a generic definition that is supposed to hold for a
00055 /// type T that just has T[0--3] and, below, specialise it to the case
00056 /// where T inherits from PseudoJet, thus giving access to more
00057 /// information
00058 /// \endif
00059 template<typename T, bool b>
00060 class DerivedPseudoJetHelper{
00061 public:
00062   // ctor
00063   DerivedPseudoJetHelper(const T &t){ _t = &t;};
00064 
00065   // conversion to PJ*
00066   PseudoJet * operator()(){
00067     return NULL;
00068   }
00069 
00070 protected:
00071   // a pointer to the actual data (we can use a pointer as it's always
00072   // going to be a temporary object
00073   const T* _t; 
00074 };
00075 
00076 
00077 /// \if internal_doc
00078 /// @ingroup internal
00079 /// specialisation for the case where T is derived from a PseudoJet
00080 /// the default handler that does not support extra info
00081 /// \endif
00082 template<typename T>
00083 class DerivedPseudoJetHelper<T, true>{
00084 public:
00085   // ctor
00086   DerivedPseudoJetHelper(const T &t){ _t = &t;};
00087 
00088   // conversion to PJ*
00089   PseudoJet * operator()(){
00090     return _t;
00091   }
00092   
00093 protected:
00094   // a pointer to the actual data (we can use a pointer as it's always
00095   // going to be a temporary object
00096   const T* _t;
00097 };
00098 
00099 
00100 FASTJET_END_NAMESPACE
00101 
00102 #endif  // __DERIVED_PSEUDOJET_HELPER_HH__