home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / nodes.h < prev    next >
C/C++ Source or Header  |  2008-12-14  |  4KB  |  112 lines

  1. #ifndef K3DSDK_NODES_H
  2. #define K3DSDK_NODES_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2005, 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 "uuid.h"
  28. #include "imetadata.h"
  29. #include "inode_collection.h"
  30. #include "inode.h"
  31.  
  32. #include "utility.h"
  33.  
  34. #include <vector>
  35.  
  36. #ifdef interface
  37. #undef interface
  38. #endif // interface
  39.  
  40. namespace k3d
  41. {
  42.  
  43. // Forward declarations
  44. class idocument;
  45. class iproperty;
  46. class inode_collection_sink;
  47.  
  48. /// Defines a collection of nodes
  49. typedef inode_collection::nodes_t nodes_t;
  50.  
  51. /// Returns the node that matches the given name (returns NULL if no node matches or if more-than-one node matches)
  52. inode* find_node(inode_collection& Nodes, const std::string& NodeName);
  53.  
  54. /// Returns the node that owns the given property (could return NULL)
  55. inode* find_node(inode_collection& Nodes, iproperty& Property);
  56.  
  57. /// Returns the set of nodes that match a specific uuid (could return empty set!)
  58. const nodes_t find_nodes(inode_collection& Nodes, const uuid ClassID);
  59.  
  60. /// Returns the set of nodes that match the given name (be prepared to handle zero, one, or many results)
  61. const nodes_t find_nodes(inode_collection& Nodes, const std::string& NodeName);
  62.  
  63. /// Returns the set of nodes that implement a specific interface type (could return empty set!)
  64. template<typename interface_t>
  65. const nodes_t find_nodes(inode_collection& Nodes)
  66. {
  67.     nodes_t nodes;
  68.  
  69.     const nodes_t::const_iterator end(Nodes.collection().end());
  70.     for(nodes_t::const_iterator node = Nodes.collection().begin(); node != end; ++node)
  71.     {
  72.         if(dynamic_cast<interface_t*>(*node))
  73.             nodes.insert(nodes.end(), *node);
  74.     }
  75.  
  76.     return nodes;
  77. }
  78.  
  79. template<typename interface_t>
  80. const nodes_t find_nodes(inode_collection& Nodes, const string_t& MetaName, const string_t& MetaValue)
  81. {
  82.     nodes_t meta_nodes = find_nodes<imetadata>(Nodes);
  83.     nodes_t nodes;
  84.     for(nodes_t::iterator node = meta_nodes.begin(); node != meta_nodes.end(); ++node)
  85.     {
  86.         imetadata* meta_node = dynamic_cast<imetadata*>(*node);
  87.         imetadata::metadata_t metadata = meta_node->get_metadata();
  88.         imetadata::metadata_t::iterator pair = metadata.find(MetaName);
  89.         if(pair != metadata.end() && pair->second == MetaValue)
  90.         {
  91.             if(dynamic_cast<interface_t*>(*node))
  92.                 nodes.push_back(*node);
  93.         }
  94.     }
  95.     
  96.     return nodes;
  97. }
  98.  
  99. /// Returns a unique node name based on the one supplied
  100. const std::string unique_name(inode_collection& Nodes, const std::string& Name);
  101.  
  102. /// Deletes a collection of nodes, cleaning-up all references and resources (this operation is undo-able, if state change recording is in effect)
  103. void delete_nodes(idocument& Document, const nodes_t& Nodes);
  104.  
  105. /// Marks the given nodes as visible in the given node collection sink
  106. void make_visible(const nodes_t& Nodes, inode_collection_sink& NodeCollectionSink);
  107.  
  108. } // namespace k3d
  109.  
  110. #endif // !K3DSDK_NODES_H
  111.  
  112.