/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_UTILITIES_TRAITS_IS_BASE_OF_HPP #define SHARE_VM_UTILITIES_TRAITS_IS_BASE_OF_HPP #include "utilities/traits/isClassOrUnion.hpp" #include "utilities/traits/isSame.hpp" #include "utilities/traits/removeCv.hpp" /** * IsBaseOfAndDerived::value is true if Derived is a derived class of Base, disgarding their CV qualifiers. * Returns false for non-class types. */ template class IsBaseOfAndDerived { typedef char yes[1]; typedef char no[2]; template static yes &check(Derived*, T); static no &check(Base*, int); template struct IsBaseOfHost { operator B*() const; operator D*(); }; template struct IsBaseOfAndDerivedInternal { static const bool value = sizeof(check(IsBaseOfHost(), int())) == sizeof(yes); }; public: static const bool value = IsClassOrUnion::value && IsBaseOfAndDerivedInternal::type, typename RemoveCv::type>::value && !IsSame::type, typename RemoveCv::type>::value; }; /** * IsBaseOf::value is true if either Derived is a derived class of Base * disregarding CV qualifiers or Derived and Base are the same type disregarding CV qualifiers. * Returns false for all non-class types. * Note: It can currently return true for unions, but that behaviour * is subject to change when compiler compatibility for detecting unions is better, and hence * that behaviour should not be relied upon. */ template class IsBaseOf { public: static const bool value = (IsBaseOfAndDerived::value || IsSame::type, typename RemoveCv::type>::value) && IsClassOrUnion::value; }; #endif // SHARE_VM_UTILITIES_TRAITS_IS_BASE_OF_HPP