?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. // https://github.com/vinniefalco/LuaBridge
  2. // Copyright 2019, Dmitry Tarakanov
  3. // Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
  4. // SPDX-License-Identifier: MIT
  5.  
  6. #pragma once
  7.  
  8. #include <LuaBridge/detail/Config.h>
  9.  
  10. #include <string>
  11.  
  12. namespace luabridge {
  13.  
  14. //------------------------------------------------------------------------------
  15. /**
  16.     Container traits.
  17.  
  18.     Unspecialized ContainerTraits has the isNotContainer typedef for SFINAE.
  19.     All user defined containers must supply an appropriate specialization for
  20.     ContinerTraits (without the typedef isNotContainer). The containers that
  21.     come with LuaBridge also come with the appropriate ContainerTraits
  22.     specialization. See the corresponding declaration for details.
  23.  
  24.     A specialization of ContainerTraits for some generic type ContainerType
  25.     looks like this:
  26.  
  27.         template <class T>
  28.         struct ContainerTraits <ContainerType <T>>
  29.         {
  30.           typedef typename T Type;
  31.  
  32.           static T* get (ContainerType <T> const& c)
  33.           {
  34.             return c.get (); // Implementation-dependent on ContainerType
  35.           }
  36.         };
  37. */
  38. template<class T>
  39. struct ContainerTraits
  40. {
  41.     typedef bool isNotContainer;
  42.     typedef T Type;
  43. };
  44.  
  45. namespace detail {
  46.  
  47. //------------------------------------------------------------------------------
  48. /**
  49.     Type traits.
  50.  
  51.     Specializations return information about a type.
  52. */
  53. struct TypeTraits
  54. {
  55.     /** Determine if type T is a container.
  56.  
  57.         To be considered a container, there must be a specialization of
  58.         ContainerTraits with the required fields.
  59.     */
  60.     template<typename T>
  61.     class isContainer
  62.     {
  63.     private:
  64.         typedef char yes[1]; // sizeof (yes) == 1
  65.         typedef char no[2]; // sizeof (no)  == 2
  66.  
  67.         template<typename C>
  68.         static no& test(typename C::isNotContainer*);
  69.  
  70.         template<typename>
  71.         static yes& test(...);
  72.  
  73.     public:
  74.         static const bool value = sizeof(test<ContainerTraits<T>>(0)) == sizeof(yes);
  75.     };
  76.  
  77.     /** Determine if T is const qualified.
  78.      */
  79.     /** @{ */
  80.     template<class T>
  81.     struct isConst
  82.     {
  83.         static bool const value = false;
  84.     };
  85.  
  86.     template<class T>
  87.     struct isConst<T const>
  88.     {
  89.         static bool const value = true;
  90.     };
  91.     /** @} */
  92.  
  93.     /** Remove the const qualifier from T.
  94.      */
  95.     /** @{ */
  96.     template<class T>
  97.     struct removeConst
  98.     {
  99.         typedef T Type;
  100.     };
  101.  
  102.     template<class T>
  103.     struct removeConst<T const>
  104.     {
  105.         typedef T Type;
  106.     };
  107.     /**@}*/
  108. };
  109.  
  110. } // namespace detail
  111.  
  112. } // namespace luabridge
  113.