LCOV - code coverage report
Current view: top level - xenolith/application - XLTemporaryResource.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-05-12 00:16:13 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       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             : 
      23             : #ifndef XENOLITH_APPLICATION_XLTEMPORARYRESOURCE_H_
      24             : #define XENOLITH_APPLICATION_XLTEMPORARYRESOURCE_H_
      25             : 
      26             : #include "XLEventHeader.h"
      27             : #include "XLResourceOwner.h"
      28             : #include "XLCoreResource.h"
      29             : #include "XLResourceCache.h"
      30             : #include "XLTexture.h"
      31             : #include "XLMeshIndex.h"
      32             : 
      33             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      34             : 
      35             : class ResourceObject;
      36             : class Texture;
      37             : class MeshIndex;
      38             : 
      39             : class TemporaryResource : public Ref {
      40             : public:
      41             :         static EventHeader onLoaded; // bool - true если ресурс загружен, false если выгружен
      42             : 
      43             :         virtual ~TemporaryResource();
      44             : 
      45             :         bool init(Rc<core::Resource> &&, TimeInterval timeout, TemporaryResourceFlags flags);
      46             :         void invalidate();
      47             : 
      48             :         Rc<Texture> acquireTexture(StringView);
      49             :         Rc<MeshIndex> acquireMeshIndex(StringView);
      50             : 
      51             :         void setLoaded(bool);
      52             :         void setRequested(bool);
      53             :         void setTimeout(TimeInterval);
      54             : 
      55             :         // Загружает ресурс в память, вызывает функцию по завершению со значением true
      56             :         // Если ресурс уже загружен, вызывает функцию немедленно со значением false
      57             :         // Возвращает true если загрузка начата и false есть ресурс уже загружен
      58             :         bool load(Ref *, Function<void(bool)> &&);
      59             : 
      60             :         void onEnter(ResourceOwner *, ResourceObject *);
      61             :         void onExit(ResourceOwner *, ResourceObject *);
      62             : 
      63             :         bool clear();
      64             : 
      65             :         StringView getName() const;
      66             : 
      67         105 :         bool isRequested() const { return _requested; }
      68         297 :         bool isLoaded() const { return _loaded; }
      69             : 
      70             :         Time getAccessTime() const { return _atime; }
      71             :         TimeInterval getTimeout() const { return _timeout; }
      72        1125 :         size_t getUsersCount() const { return _users; }
      73             : 
      74          15 :         const Rc<core::Resource> &getResource() const { return _resource; }
      75             : 
      76             :         bool isDeprecated(const UpdateTime &) const;
      77             : 
      78             : protected:
      79             :         bool _requested = false;
      80             :         bool _loaded = false;
      81             :         bool _removeOnClear = false;
      82             :         size_t _users = 0;
      83             :         uint64_t _atime;
      84             :         TimeInterval _timeout;
      85             :         String _name;
      86             :         Rc<core::Resource> _resource;
      87             :         Map<const core::ImageData *, Rc<Texture>> _textures;
      88             :         Map<const core::BufferData *, Rc<MeshIndex>> _meshIndexes;
      89             :         Set<Rc<ResourceOwner>> _owners;
      90             :         Vector<Pair<Rc<Ref>, Function<void(bool)>>> _callbacks;
      91             : };
      92             : 
      93             : }
      94             : 
      95             : #endif /* XENOLITH_APPLICATION_XLTEMPORARYRESOURCE_H_ */

Generated by: LCOV version 1.14