home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / properties.h < prev    next >
C/C++ Source or Header  |  2009-03-18  |  7KB  |  146 lines

  1. #ifndef K3DSDK_PROPERTIES_H
  2. #define K3DSDK_PROPERTIES_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2008, 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 "iproperty.h"
  28. #include <vector>
  29.  
  30. namespace k3d
  31. {
  32.  
  33. class idocument;
  34. class inode;
  35. class iunknown;
  36.  
  37. namespace property
  38. {
  39.  
  40. /// Makes a connection from one property to another.
  41. void connect(idocument& Document, iproperty* const From, iproperty* const To);
  42.  
  43. /// Returns a matching property by name, or NULL
  44. iproperty* get(iunknown& Object, const string_t& Name);
  45.  
  46. /// Returns a matching property by name and type, or NULL
  47. template<typename value_t>
  48. iproperty* get(iunknown& Object, const string_t& Name)
  49. {
  50.     iproperty* const property = get(Object, Name);
  51.     return property && (property->property_type() == typeid(value_t)) ? property : 0;
  52. }
  53.  
  54. /// Returns the "internal" value of a property - the value of the property itself, regardless of any pipeline dependencies
  55. const boost::any internal_value(iunknown& Object, const string_t& Name);
  56. /// Returns the "internal" value of a property - the value of the property itself, regardless of any pipeline dependencies
  57. template<typename value_t>
  58. const value_t internal_value(iunknown& Object, const string_t& Name)
  59. {
  60.     return boost::any_cast<value_t>(internal_value(Object, Name));
  61. }
  62.  
  63. /// Returns the "internal" value of a property - the value of the property itself, regardless of any pipeline dependencies
  64. const boost::any internal_value(iproperty& Property);
  65. /// Returns the "internal" value of a property - the value of the property itself, regardless of any pipeline dependencies
  66. template<typename value_t>
  67. const value_t internal_value(iproperty& Property)
  68. {
  69.     return boost::any_cast<value_t>(internal_value(Property));
  70. }
  71.  
  72. /// Returns the "pipeline" value of a property - the value of the property, possibly overridden by pipeline dependencies
  73. const boost::any pipeline_value(iunknown& Object, const string_t& Name);
  74. /// Returns the "pipeline" value of a property - the value of the property, possibly overridden by pipeline dependencies
  75. template<typename value_t>
  76. const value_t pipeline_value(iunknown& Object, const string_t& Name)
  77. {
  78.     return boost::any_cast<value_t>(pipeline_value(Object, Name));
  79. }
  80. /// Returns the "pipeline" value of a property - the value of the property, possibly overridden by pipeline dependencies
  81. const boost::any pipeline_value(iproperty& Property);
  82. /// Returns the "pipeline" value of a property - the value of the property, possibly overridden by pipeline dependencies
  83. template<typename value_t>
  84. const value_t pipeline_value(iproperty& Property)
  85. {
  86.     return boost::any_cast<value_t>(pipeline_value(Property));
  87. }
  88.  
  89. /** \brief Sets the value of a named property
  90.     \return true, iff the value was set successfully, false otherwise (couldn't find a property with a matching name, it wasn't writable, or the type didn't match)
  91. */
  92. bool set_internal_value(iunknown& Object, const string_t Name, const boost::any& Value);
  93.  
  94. /** \brief Sets the value of a property
  95.     \return true, iff the value was set successfully, false otherwise (the property wasn't writable or the type didn't match)
  96. */
  97. bool set_internal_value(iproperty& Property, const boost::any& Value);
  98.  
  99. /// Returns the set of user properties (if any) owned by an object
  100. const std::vector<iproperty*> user_properties(iunknown& Object);
  101.  
  102. /// Creates a new user property with the given type and initial value.
  103. iproperty* create(inode& Owner, const std::type_info& Type, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  104. /// Creates a new user property with the given type and initial value.
  105. iproperty* create(inode& Owner, const string_t& Type, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  106. /// Creates a new user property with the given type and initial value.
  107. template<typename T>
  108. iproperty* create(inode& Owner, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any())
  109. {
  110.     return create(Owner, typeid(T), Name, Label, Description, Value);
  111. }
  112.  
  113. namespace ri
  114. {
  115.  
  116. /// Creates a new RenderMan attribute with the given type, name, and value
  117. iproperty* create_attribute(inode& Owner, const std::type_info& Type, const string_t& AttributeName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  118. /// Creates a new RenderMan attribute with the given type, name, and value
  119. iproperty* create_attribute(inode& Owner, const string_t& Type, const string_t& AttributeName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  120. /// Creates a new RenderMan attribute with the given type, name, and value
  121. template<typename T>
  122. iproperty* create_attribute(inode& Owner, const string_t& AttributeName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any())
  123. {
  124.     return create_attribute(Owner, typeid(T), AttributeName, Name, Label, Description, Value);
  125. }
  126.  
  127. /// Creates a new RenderMan option with the given type, name, and value
  128. iproperty* create_option(inode& Owner, const std::type_info& Type, const string_t& OptionName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  129. /// Creates a new RenderMan option with the given type, name, and value
  130. iproperty* create_option(inode& Owner, const string_t& Type, const string_t& OptionName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any());
  131. /// Creates a new RenderMan option with the given type, name, and value
  132. template<typename T>
  133. iproperty* create_option(inode& Owner, const string_t& OptionName, const string_t& Name, const string_t& Label, const string_t& Description, const boost::any& Value = boost::any())
  134. {
  135.     return create_option(Owner, typeid(T), OptionName, Name, Label, Description, Value);
  136. }
  137.  
  138. } // namespace ri
  139.  
  140. } // namespace property
  141.  
  142. } // namespace k3d
  143.  
  144. #endif // !K3DSDK_PROPERTIES_H
  145.  
  146.