Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:06:45

0001 //FJSTARTHEADER
0002 // $Id$
0003 //
0004 // Copyright (c) 2005-2021, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
0005 //
0006 //----------------------------------------------------------------------
0007 // This file is part of FastJet.
0008 //
0009 //  FastJet is free software; you can redistribute it and/or modify
0010 //  it under the terms of the GNU General Public License as published by
0011 //  the Free Software Foundation; either version 2 of the License, or
0012 //  (at your option) any later version.
0013 //
0014 //  The algorithms that underlie FastJet have required considerable
0015 //  development. They are described in the original FastJet paper,
0016 //  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
0017 //  FastJet as part of work towards a scientific publication, please
0018 //  quote the version you use and include a citation to the manual and
0019 //  optionally also to hep-ph/0512210.
0020 //
0021 //  FastJet is distributed in the hope that it will be useful,
0022 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0024 //  GNU General Public License for more details.
0025 //
0026 //  You should have received a copy of the GNU General Public License
0027 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
0028 //----------------------------------------------------------------------
0029 //FJENDHEADER
0030 
0031 #ifndef __FASTJET_INTERNAL_IS_BASE_HH__
0032 #define __FASTJET_INTERNAL_IS_BASE_HH__
0033 
0034 #include "fastjet/internal/numconsts.hh"
0035 
0036 FASTJET_BEGIN_NAMESPACE
0037 
0038 //---------------------------------------------------
0039 // define a true and a false 'type'
0040 // Note: 
0041 //  we could actually template the type and recover 
0042 //  the TR1 integral_constant type. This also 
0043 //  includes adding a typedef for the type and a
0044 //  typedef for the struct in the struct below
0045 //
0046 // This is going to be helpful to "split" a given 
0047 // call into 2 options based on a type constraint
0048 // at compilation-time (rather than doing an "if" 
0049 // which would only be resolved at runtime and could
0050 // thus resutl in compilation errors. 
0051 //---------------------------------------------------
0052 
0053 /// \if internal_doc
0054 /// \class integral_type 
0055 /// a generic construct that promotes a generic value of a generic type
0056 /// as a type
0057 ///
0058 /// this has 2 template parameters: T, the considered type, and _t, a
0059 /// value of type T
0060 /// This object is a basic construct in type traits
0061 /// \endif
0062 template<typename T, T _t>
0063 struct integral_type{
0064   static const T value = _t;         ///< the value (only member carrying info)
0065   typedef T value_type;          ///< a typedef for the type T
0066   typedef integral_type<T,_t> type;  ///< a typedef for the whole structure
0067 };
0068 
0069 // definition of the static member in integral_type
0070 template<typename T, T _t>
0071 const T integral_type<T, _t>::value;
0072 
0073 // shortcuts
0074 typedef integral_type<bool, true>  true_type;  ///< the bool 'true'  value promoted to a type
0075 typedef integral_type<bool, false> false_type; ///< the bool 'false' value promoted to a type
0076 
0077 
0078 //---------------------------------------------------
0079 // define a yes and a no type (based on their size)
0080 //---------------------------------------------------
0081 typedef char (&__yes_type)[1]; //< the yes type
0082 typedef char (&__no_type) [2]; //< the no type
0083 
0084 
0085 //---------------------------------------------------
0086 // Now deal with inheritance checks
0087 //
0088 // We want to provide a IsBaseAndDerived<B,D> type 
0089 // trait that contains a value that is true if D
0090 // is derived from B and false otherwise.
0091 //
0092 // For an explanation of how the code below works, 
0093 // have a look at 
0094 //   http://groups.google.com/group/comp.lang.c++.moderated/msg/dd6c4e4d5160bd83
0095 // and the links therein
0096 //
0097 // WARNING: according to 'boost', this may have some
0098 //   issues with MSVC7.1. See their code for a description
0099 //   of the workaround used below
0100 //---------------------------------------------------
0101 
0102 /// \if internal_doc
0103 /// \class __inheritance_helper
0104 /// helper for IsBasedAndDerived<B,D>
0105 /// \endif
0106 template<typename B, typename D>
0107 struct __inheritance_helper{
0108 #if !((_MSC_VER !=0 ) && (_MSC_VER == 1310))   // MSVC 7.1
0109   template <typename T>
0110   static __yes_type check_sig(D const volatile *, T);
0111 #else
0112   static __yes_type check_sig(D const volatile *, long);
0113 #endif
0114   static __no_type  check_sig(B const volatile *, int);
0115 };
0116 
0117 /// \if internal_doc
0118 /// \class IsBaseAndDerived
0119 /// check if the second template argument is derived from the first one
0120 /// 
0121 /// this class has 2 template dependencies: B and D. It contains a
0122 /// static boolean value that will be true if D is derived from B and
0123 /// false otherwise.
0124 ///
0125 /// Note: This construct may have a problem with MSVC7.1. See the
0126 /// boost implementation for a description and workaround
0127 /// \endif
0128 template<typename B, typename D>
0129 struct IsBaseAndDerived{
0130 #if ((_MSC_FULL_VER != 0) && (_MSC_FULL_VER >= 140050000))
0131 #pragma warning(push)
0132 #pragma warning(disable:6334)
0133 #endif
0134 
0135 
0136   /// \if internal_doc
0137   /// a helper structure that will pick between a casting to B*const
0138   /// or D.
0139   ///
0140   /// precisely how this structure works involves advanced C++
0141   /// conversion rules
0142   /// \endif
0143   struct Host{
0144 #if !((_MSC_VER !=0 ) && (_MSC_VER == 1310))
0145     operator B const volatile *() const;
0146 #else
0147     operator B const volatile * const&() const;
0148 #endif
0149     operator D const volatile *();
0150   };
0151 
0152   /// the boolean value being true if D is derived from B
0153   static const bool value = ((sizeof(B)!=0) && 
0154                  (sizeof(D)!=0) && 
0155                  (sizeof(__inheritance_helper<B,D>::check_sig(Host(), 0)) == sizeof(__yes_type)));
0156 
0157 #if ((_MSC_FULL_VER != 0) && (_MSC_FULL_VER >= 140050000))
0158 #pragma warning(pop)
0159 #endif
0160 };
0161 
0162 
0163 /// a little helper that returns a pointer to d of type B* if D is
0164 /// derived from B and NULL otherwise
0165 template<class B, class D>
0166 B* cast_if_derived(D* d){
0167   return IsBaseAndDerived<B,D>::value ? (B*)(d) : 0;
0168 }
0169 
0170 
0171 FASTJET_END_NAMESPACE
0172 
0173 
0174 #endif  // __IS_BASE_OF_HH__