UnknownComponent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Scene/Component.h"
  24. namespace Atomic
  25. {
  26. /// Placeholder for allowing unregistered components to be loaded & saved along with scenes.
  27. class ATOMIC_API UnknownComponent : public Component
  28. {
  29. public:
  30. /// Construct.
  31. UnknownComponent(Context* context);
  32. /// Register object factory.
  33. static void RegisterObject(Context* context);
  34. /// Return type of the stored component.
  35. virtual StringHash GetType() const { return typeHash_; }
  36. /// Return type name of the stored component.
  37. virtual const String& GetTypeName() const { return typeName_; }
  38. /// Return attribute descriptions, or null if none defined.
  39. virtual const Vector<AttributeInfo>* GetAttributes() const { return &xmlAttributeInfos_; }
  40. /// Load from binary data. Return true if successful.
  41. virtual bool Load(Deserializer& source, bool setInstanceDefault = false);
  42. /// Load from XML data. Return true if successful.
  43. virtual bool LoadXML(const XMLElement& source, bool setInstanceDefault = false);
  44. /// Save as binary data. Return true if successful.
  45. virtual bool Save(Serializer& dest) const;
  46. /// Save as XML data. Return true if successful.
  47. virtual bool SaveXML(XMLElement& dest) const;
  48. /// Initialize the type name. Called by Node when loading.
  49. void SetTypeName(const String& typeName);
  50. /// Initialize the type hash only when type name not known. Called by Node when loading.
  51. void SetType(StringHash typeHash);
  52. /// Return the XML format attributes. Empty when loaded with binary serialization.
  53. const Vector<String>& GetXMLAttributes() const { return xmlAttributes_; }
  54. /// Return the binary attributes. Empty when loaded with XML serialization.
  55. const PODVector<unsigned char>& GetBinaryAttributes() const { return binaryAttributes_; }
  56. /// Return whether was loaded using XML data.
  57. bool GetUseXML() const { return useXML_; }
  58. /// Return static type.
  59. static Atomic::StringHash GetTypeStatic()
  60. {
  61. static const StringHash typeStatic("UnknownComponent");
  62. return typeStatic;
  63. }
  64. /// Return static type name.
  65. static const Atomic::String& GetTypeNameStatic()
  66. {
  67. static const String typeNameStatic("UnknownComponent");
  68. return typeNameStatic;
  69. }
  70. private:
  71. /// Type of stored component.
  72. StringHash typeHash_;
  73. /// Type name of the stored component.
  74. String typeName_;
  75. /// XML format attribute infos.
  76. Vector<AttributeInfo> xmlAttributeInfos_;
  77. /// XML format attribute data (as strings)
  78. Vector<String> xmlAttributes_;
  79. /// Binary attributes.
  80. PODVector<unsigned char> binaryAttributes_;
  81. /// Flag of whether was loaded using XML data.
  82. bool useXML_;
  83. };
  84. }