-
#include "tensorstore/context.h"
-
template <typename Provider>
class tensorstore::Context::Resource; Variant type that either specifies an unresolved context resource, or holds a shared handle to a context resource.
Unresolved context resources may either be specified directly or by a named reference, and are resolved by calling
Context::GetResource
.Types¶
- using ToJsonOptions = JsonSerializationOptions;
- using FromJsonOptions = JsonSerializationOptions;
JSON serialization options.
Constructors¶
- Resource();
Constructs an invalid handle.
Methods¶
- static Resource<Provider> DefaultSpec();
Returns a resource spec that refers to the default value within the
Context
.
- auto* get() const noexcept;
- auto* operator->() const noexcept;
- auto& operator*() const noexcept;
Returns a pointer to the resource object of type
Provider::Resource
, ornullptr
if no resource is bound.
- bool has_resource() const;
Returns
true
if this is not null and corresponds to a bound resource (rather than a resource spec).
- bool valid() const;
Returns
true
if this corresponds to a resource spec or bound resource.
-
Result<::nlohmann::json>
ToJson(const ToJsonOptions& options = ToJsonOptions{}) const; Converts to a JSON representation.
-
static Result<Resource<Provider>>
FromJson(::nlohmann::json j,
const FromJsonOptions& options = FromJsonOptions{}); Returns a resource spec from a JSON representation.
- absl::Status BindContext(const Context& context);
If
!this->has_resource()
, resolves this to a resource using the specified context. Otherwise, does nothing.
- void StripContext();
If this is non-null, resets it to
DefaultSpec()
. If this is null, it remains null.
Friend functions¶
- friend bool operator==(const Resource& a, const Resource& b);
- friend bool operator!=(const Resource& a, const Resource& b);
Checks if
a
andb
refer to the same resource or resource spec.