2
0

CRWObjectModel.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "CRWObjectModel.h"
  2. CRWDescriptor::CRWDescriptor(CRWObjectModel* crwObjectModel, CRWDescriptor* parent, const Crown::Descriptor& descriptor, Crown::uint offset):
  3. mCRWObjectModel(crwObjectModel), mParent(parent), mChildren(NULL), mDescriptorOffset(offset)
  4. {
  5. AddProperty(new UIntProperty("ID", &mID));
  6. AddProperty(new UShortProperty("Type", &mType));
  7. AddProperty(new StrProperty("Name", &mName));
  8. AddProperty(new UIntProperty("ContentOffset", &mContentOffset));
  9. AddProperty(new UIntProperty("ContentSize", &mContentSize));
  10. AddProperty(new UShortProperty("Flags", &mFlags));
  11. AddProperty(new UIntProperty("DescriptorOffset", &mDescriptorOffset));
  12. AddProperty(new GenericListProperty("Children", &mChildrenGenericWrapper));
  13. mID = descriptor.ID;
  14. mType = descriptor.type;
  15. mName = descriptor.name;
  16. mContentOffset = descriptor.contentOffset;
  17. mContentSize = descriptor.contentSize;
  18. mDescriptorOffset = offset;
  19. }
  20. CRWDescriptor::~CRWDescriptor()
  21. {
  22. delete mChildren;
  23. }
  24. Crown::Str CRWDescriptor::ToStr() const
  25. {
  26. return "CRWDescriptor\"" + mName + "\"";
  27. }
  28. void CRWDescriptor::OnGetProperty(const Crown::Str& name)
  29. {
  30. if (name == "Children")
  31. {
  32. if (mChildren == NULL)
  33. {
  34. GetChildren();
  35. mChildrenGenericWrapper = new Crown::ListGenericWrapper<CRWDescriptor*>(mChildren);
  36. }
  37. }
  38. }
  39. Generic CRWDescriptor::GetPropertyValue(const Str& name) const
  40. {
  41. return WithProperties::GetPropertyValue(name);
  42. }
  43. Crown::Str CRWDescriptor::GetFullName()
  44. {
  45. Crown::Str name;
  46. name = mName;
  47. if (!mParent)
  48. return "/" + name;
  49. else
  50. return mParent->GetFullName() + "/" + name;
  51. }
  52. CRWObjectModel* CRWDescriptor::GetCRWObjectModel()
  53. {
  54. return mCRWObjectModel;
  55. }
  56. Crown::List<CRWDescriptor*>* CRWObjectModel::LoadChildren(CRWDescriptor* crwDescriptor)
  57. {
  58. Crown::Str path = "/";
  59. if (crwDescriptor)
  60. {
  61. path = crwDescriptor->GetFullName();
  62. }
  63. Crown::List<CRWDescriptor*>* list = new Crown::List<CRWDescriptor*>();
  64. //If seek fails, the path is not a directory and therefore there's no children
  65. if (!mDecoder->Seek(path))
  66. return list;
  67. while (mDecoder->NextDescriptor())
  68. {
  69. const Crown::Descriptor& descriptor = mDecoder->GetDescriptor();
  70. Crown::uint offset = mDecoder->GetDescriptorOffset();
  71. list->Append(new CRWDescriptor(this, crwDescriptor, descriptor, offset));
  72. }
  73. return list;
  74. }
  75. CRWObjectModel::CRWObjectModel(Crown::CRWDecoder* decoder):
  76. mDecoder(decoder), mRoot(NULL)
  77. {
  78. GetRoot();
  79. }
  80. CRWObjectModel::~CRWObjectModel()
  81. {
  82. }
  83. Str CRWObjectModel::GetCRWLibraryPath()
  84. {
  85. return mDecoder->GetLibraryPath();
  86. }
  87. Generic CRWObjectModel::GetPropertyValue(const Str& name) const
  88. {
  89. if (name == "Root")
  90. {
  91. //This does not generate leaks because Generic stores the pointer in a Shared<>
  92. return new ListGenericWrapper<CRWDescriptor*>(mRoot.GetPointer());
  93. }
  94. return Generic();
  95. }
  96. void CRWObjectModel::SetPropertyValue(const Str& name, const Generic& value)
  97. {
  98. }