xFileDataNodeReference.cxx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Filename: xFileDataNodeReference.cxx
  2. // Created by: drose (08Oct04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "xFileDataNodeReference.h"
  19. #include "indent.h"
  20. TypeHandle XFileDataNodeReference::_type_handle;
  21. ////////////////////////////////////////////////////////////////////
  22. // Function: XFileDataNodeReference::Constructor
  23. // Access: Public
  24. // Description:
  25. ////////////////////////////////////////////////////////////////////
  26. XFileDataNodeReference::
  27. XFileDataNodeReference(XFileDataNodeTemplate *object) :
  28. XFileDataNode(object->get_x_file(), object->get_name()),
  29. _object(object)
  30. {
  31. }
  32. ////////////////////////////////////////////////////////////////////
  33. // Function: XFileDataNodeReference::is_complex_object
  34. // Access: Public, Virtual
  35. // Description: Returns true if this kind of data object is a complex
  36. // object that can hold nested data elements, false
  37. // otherwise.
  38. ////////////////////////////////////////////////////////////////////
  39. bool XFileDataNodeReference::
  40. is_complex_object() const {
  41. return true;
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: XFileDataNodeReference::write_text
  45. // Access: Public, Virtual
  46. // Description: Writes a suitable representation of this node to an
  47. // .x file in text mode.
  48. ////////////////////////////////////////////////////////////////////
  49. void XFileDataNodeReference::
  50. write_text(ostream &out, int indent_level) const {
  51. indent(out, indent_level)
  52. << "{ " << _object->get_name() << " }\n";
  53. }
  54. ////////////////////////////////////////////////////////////////////
  55. // Function: XFileDataNodeReference::get_num_elements
  56. // Access: Protected, Virtual
  57. // Description: Returns the number of nested data elements within the
  58. // object. This may be, e.g. the size of the array, if
  59. // it is an array.
  60. ////////////////////////////////////////////////////////////////////
  61. int XFileDataNodeReference::
  62. get_num_elements() const {
  63. return _object->size();
  64. }
  65. ////////////////////////////////////////////////////////////////////
  66. // Function: XFileDataNodeReference::get_element
  67. // Access: Protected, Virtual
  68. // Description: Returns the nth nested data element within the
  69. // object.
  70. ////////////////////////////////////////////////////////////////////
  71. const XFileDataObject *XFileDataNodeReference::
  72. get_element(int n) const {
  73. return &((*_object)[n]);
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: XFileDataNodeReference::get_element
  77. // Access: Protected, Virtual
  78. // Description: Returns the nested data element within the
  79. // object that has the indicated name.
  80. ////////////////////////////////////////////////////////////////////
  81. const XFileDataObject *XFileDataNodeReference::
  82. get_element(const string &name) const {
  83. return &((*_object)[name]);
  84. }