CmResources.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "CmResources.h"
  2. #include "CmResource.h"
  3. #include "CmException.h"
  4. #include "CmFileSerializer.h"
  5. namespace CamelotEngine
  6. {
  7. Resources::Resources()
  8. {
  9. }
  10. Resources::~Resources()
  11. {
  12. }
  13. ResourcePtr Resources::load(const String& filePath)
  14. {
  15. FileSerializer fs;
  16. std::shared_ptr<IReflectable> resource = fs.decode(filePath);
  17. // TODO - Low priority. Check is file path valid?
  18. if(resource == nullptr)
  19. CM_EXCEPT(InternalErrorException, "Unable to load resource.");
  20. if(!resource->isDerivedFrom(Resource::getRTTIStatic()))
  21. CM_EXCEPT(InternalErrorException, "Loaded class doesn't derive from Resource.");
  22. return std::static_pointer_cast<Resource>(resource);
  23. }
  24. ResourcePtr Resources::load(const UUID& uuid)
  25. {
  26. CM_EXCEPT(NotImplementedException, "Not implemented");
  27. }
  28. void Resources::save(ResourcePtr resource, const String& filePath)
  29. {
  30. assert(resource != nullptr);
  31. // TODO - Low priority. Check is file path valid?
  32. FileSerializer fs;
  33. fs.encode(resource.get(), filePath);
  34. }
  35. }