home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / interface_list.h < prev    next >
C/C++ Source or Header  |  2008-01-23  |  3KB  |  104 lines

  1. #ifndef K3DSDK_INTERFACE_LIST_H
  2. #define K3DSDK_INTERFACE_LIST_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2007, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.     \author Tim Shead (tshead@k-3d.com)
  25. */
  26.  
  27. #include "iapplication_plugin_factory.h"
  28. #include "plugin_factory.h"
  29.  
  30. namespace k3d
  31. {
  32.  
  33. /// Defines a null interface type for marking the ends of an interface list
  34. class null_interface
  35. {
  36. };
  37.  
  38. /// Used to create compile-time lists of interfaces (i.e. typelists - see Alexandrescu "Modern C++ Design")
  39. template<typename head_t, typename tail_t = null_interface>
  40. struct interface_list
  41. {
  42.     typedef head_t head;
  43.     typedef tail_t tail;
  44. };
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // implements_interface
  48.  
  49. /// Generates code at compile-time that test whether an interface_list contains a specific interface type
  50. template<class interface_type>
  51. struct implements_interface;
  52.  
  53. /// Generates code at compile-time that test whether an interface_list contains a specific interface type
  54. template<>
  55. struct implements_interface<null_interface>
  56. {
  57.     bool operator()(const std::type_info& InterfaceType)
  58.     {
  59.         return false;
  60.     }
  61. };
  62.  
  63. /// Generates code at compile-time that test whether an interface_list contains a specific interface type
  64. template<typename head_t, typename tail_t>
  65. struct implements_interface<interface_list<head_t, tail_t> >
  66. {
  67.     bool operator()(const std::type_info& InterfaceType)
  68.     {
  69.         if(typeid(head_t) == InterfaceType)
  70.             return true;
  71.  
  72.         return implements_interface<tail_t>()(InterfaceType);
  73.     }
  74. };
  75.  
  76. /// Generates code at compile-time that returns a list of interface types
  77. template<class interface_type>
  78. struct get_interfaces;
  79.  
  80. /// Generates code at compile-time that returns a list of interface types
  81. template<>
  82. struct get_interfaces<null_interface>
  83. {
  84.     void operator()(iplugin_factory::interfaces_t& Interfaces)
  85.     {
  86.     }
  87. };
  88.  
  89. /// Generates code at compile-time that returns a list of interface types
  90. template<typename head_t, typename tail_t>
  91. struct get_interfaces<interface_list<head_t, tail_t> >
  92. {
  93.     void operator()(iplugin_factory::interfaces_t& Interfaces)
  94.     {
  95.         Interfaces.push_back(&typeid(head_t));
  96.         get_interfaces<tail_t>()(Interfaces);
  97.     }
  98. };
  99.  
  100. } // namespace k3d
  101.  
  102. #endif // !K3DSDK_INTERFACE_LIST_H
  103.  
  104.