Opaque handle to a sketch-local asset. Value type: cheap to copy (a single pointer + size). Created via the `FL_ASSET()` macro or `fl::asset(const char*)` below. The `FL_ASSET()` macro performs an `FL_STATIC_ASSERT` that the path contains no `..` segments.
| 82 | /// `FL_ASSET()` macro or `fl::asset(const char*)` below. The `FL_ASSET()` |
| 83 | /// macro performs an `FL_STATIC_ASSERT` that the path contains no `..` segments. |
| 84 | class asset_ref { |
| 85 | public: |
| 86 | /// Construct from a pointer to a null-terminated string with known length. |
| 87 | /// The pointer MUST outlive the `asset_ref` — typically a string literal. |
| 88 | constexpr asset_ref(const char* path, fl::size length) FL_NOEXCEPT |
| 89 | : mPath(path), mLength(length) {} |
| 90 | |
| 91 | /// Default-constructed handle refers to no asset. |
| 92 | constexpr asset_ref() FL_NOEXCEPT : mPath(nullptr), mLength(0) {} |
| 93 | |
| 94 | /// Copy/move: trivial — pointer + length. Can't combine `constexpr` with |
| 95 | /// `= default` on the assignment operator pre-C++14, so we leave these as |
| 96 | /// the implicitly-declared operations (the class is trivially copyable). |
| 97 | asset_ref(const asset_ref&) FL_NOEXCEPT = default; |
| 98 | asset_ref& operator=(const asset_ref&) FL_NOEXCEPT = default; |
| 99 | |
| 100 | /// True if this handle refers to an asset path. |
| 101 | constexpr explicit operator bool() const FL_NOEXCEPT { |
| 102 | return mPath != nullptr && mLength > 0; |
| 103 | } |
| 104 | |
| 105 | /// The relative asset path as a string view (e.g. "data/track.mp3"). |
| 106 | fl::string_view path() const FL_NOEXCEPT { |
| 107 | return fl::string_view(mPath, mLength); |
| 108 | } |
| 109 | |
| 110 | /// Pointer accessor — useful for JSON serialization. |
| 111 | constexpr const char* c_str() const FL_NOEXCEPT { return mPath; } |
| 112 | constexpr fl::size size() const FL_NOEXCEPT { return mLength; } |
| 113 | |
| 114 | private: |
| 115 | const char* mPath; |
| 116 | fl::size mLength; |
| 117 | }; |
| 118 | |
| 119 | /// Construct an asset handle from a relative sketch path at runtime. |
| 120 | /// |