#ifndef SERVICES_WEBNN_WEBNN_PENDING_CONSTANT_OPERAND_H_
#define SERVICES_WEBNN_WEBNN_PENDING_CONSTANT_OPERAND_H_
#include "base/component_export.h"
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "services/webnn/public/cpp/operand_descriptor.h"
#include "third_party/blink/public/common/tokens/tokens.h"
namespace webnn {
class WebNNConstantOperand;
class COMPONENT_EXPORT(WEBNN_SERVICE) WebNNPendingConstantOperand {
public:
WebNNPendingConstantOperand(blink::WebNNPendingConstantToken handle,
OperandDataType data_type,
base::span<const uint8_t> data);
~WebNNPendingConstantOperand();
WebNNPendingConstantOperand(const WebNNPendingConstantOperand&) = delete;
WebNNPendingConstantOperand& operator=(const WebNNPendingConstantOperand&) =
delete;
std::unique_ptr<WebNNConstantOperand> TakeAsConstantOperand(
OperandDescriptor descriptor);
bool IsValidWithDescriptor(OperandDescriptor descriptor) const;
struct Comparator {
using is_transparent = blink::WebNNPendingConstantToken;
template <class Deleter = std::default_delete<WebNNPendingConstantOperand>>
bool operator()(
const std::unique_ptr<WebNNPendingConstantOperand, Deleter>& lhs,
const std::unique_ptr<WebNNPendingConstantOperand, Deleter>& rhs)
const {
return lhs->handle() < rhs->handle();
}
template <class Deleter = std::default_delete<WebNNPendingConstantOperand>>
bool operator()(const blink::WebNNPendingConstantToken& lhs,
const std::unique_ptr<WebNNPendingConstantOperand, Deleter>&
rhs) const {
return lhs < rhs->handle();
}
template <class Deleter = std::default_delete<WebNNPendingConstantOperand>>
bool operator()(
const std::unique_ptr<WebNNPendingConstantOperand, Deleter>& lhs,
const blink::WebNNPendingConstantToken& rhs) const {
return lhs->handle() < rhs;
}
};
const blink::WebNNPendingConstantToken& handle() const { return handle_; }
private:
blink::WebNNPendingConstantToken handle_;
const OperandDataType data_type_;
base::HeapArray<uint8_t> data_;
};
}
#endif