2
0

nodeAttributes.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Filename: nodeAttributes.h
  2. // Created by: drose (20Mar00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #ifndef NODEATTRIBUTES_H
  6. #define NODEATTRIBUTES_H
  7. #include <pandabase.h>
  8. #include "nodeAttribute.h"
  9. #include <pointerTo.h>
  10. #include <map>
  11. class NodeTransitionCache;
  12. ////////////////////////////////////////////////////////////////////
  13. // Class : NodeAttributes
  14. // Description : This represents a set of zero or more NodeAttribute
  15. // pointers, organized by the attributes' get_handle()
  16. // value.
  17. ////////////////////////////////////////////////////////////////////
  18. class EXPCL_PANDA NodeAttributes {
  19. PUBLISHED:
  20. NodeAttributes();
  21. public:
  22. NodeAttributes(const NodeAttributes &copy);
  23. void operator = (const NodeAttributes &copy);
  24. ~NodeAttributes();
  25. PUBLISHED:
  26. bool is_empty() const;
  27. PT(NodeAttribute) set_attribute(TypeHandle handle, NodeAttribute *attrib);
  28. PT(NodeAttribute) clear_attribute(TypeHandle handle);
  29. bool has_attribute(TypeHandle handle) const;
  30. NodeAttribute *get_attribute(TypeHandle handle) const;
  31. void clear();
  32. bool is_initial() const;
  33. int compare_to(const NodeAttributes &other) const;
  34. private:
  35. typedef map<TypeHandle, PT(NodeAttribute)> Attributes;
  36. public:
  37. // STL-like definitions to expose the map within NodeAttributes to
  38. // external adjustment. Beware! These are not safe to use outside
  39. // of PANDA.DLL.
  40. typedef Attributes::iterator iterator;
  41. typedef Attributes::const_iterator const_iterator;
  42. typedef Attributes::value_type value_type;
  43. typedef Attributes::size_type size_type;
  44. INLINE size_type size() const;
  45. INLINE iterator begin();
  46. INLINE iterator end();
  47. INLINE const_iterator begin() const;
  48. INLINE const_iterator end() const;
  49. INLINE iterator insert(iterator position, const value_type &x);
  50. INLINE void erase(iterator position);
  51. public:
  52. INLINE void apply_in_place(const NodeTransitionCache &trans);
  53. INLINE NodeAttributes *apply(const NodeTransitionCache &trans) const;
  54. void apply_from(const NodeAttributes &other,
  55. const NodeTransitionCache &trans);
  56. public:
  57. void output(ostream &out) const;
  58. void write(ostream &out, int indent_level = 0) const;
  59. private:
  60. Attributes _attributes;
  61. friend class NodeAttributeCache;
  62. };
  63. INLINE ostream &operator << (ostream &out, const NodeAttributes &nas) {
  64. nas.output(out);
  65. return out;
  66. }
  67. template<class Attribute>
  68. INLINE bool
  69. get_attribute_into(Attribute *&ptr, const NodeAttributes &attrib,
  70. TypeHandle transition_type);
  71. #include "nodeAttributes.I"
  72. #endif