A wrapper class for storing a `DatasetBase` instance in a DT_VARIANT tensor. Objects of the wrapper class own a reference on an instance of `DatasetBase`, and the wrapper's copy constructor and destructor take care of managing the reference count. NOTE(mrry): This is not a feature-complete implementation of the DT_VARIANT specification. In particular, we cannot currently serialize an arbitrary `D
| 39 | // `DatasetBase` object, so the `Encode()` and `Decode()` methods are not |
| 40 | // implemented. |
| 41 | class DatasetVariantWrapper { |
| 42 | public: |
| 43 | DatasetVariantWrapper() : dataset_(nullptr) {} |
| 44 | |
| 45 | // Transfers ownership of `dataset` to `*this`. |
| 46 | explicit DatasetVariantWrapper(DatasetBase* dataset) : dataset_(dataset) {} |
| 47 | |
| 48 | DatasetVariantWrapper(const DatasetVariantWrapper& other) |
| 49 | : dataset_(other.dataset_) { |
| 50 | if (dataset_) dataset_->Ref(); |
| 51 | } |
| 52 | |
| 53 | DatasetVariantWrapper& operator=(DatasetVariantWrapper&& other) { |
| 54 | if (&other == this) return *this; |
| 55 | std::swap(dataset_, other.dataset_); |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | DatasetVariantWrapper& operator=(const DatasetVariantWrapper& other) = delete; |
| 60 | |
| 61 | ~DatasetVariantWrapper() { |
| 62 | if (dataset_) dataset_->Unref(); |
| 63 | } |
| 64 | |
| 65 | DatasetBase* get() const { return dataset_; } |
| 66 | |
| 67 | string TypeName() const { return "tensorflow::DatasetVariantWrapper"; } |
| 68 | string DebugString() const { |
| 69 | if (dataset_) { |
| 70 | return dataset_->DebugString(); |
| 71 | } else { |
| 72 | return "<Uninitialized DatasetVariantWrapper>"; |
| 73 | } |
| 74 | } |
| 75 | void Encode(VariantTensorData* data) const { |
| 76 | LOG(ERROR) << "The Encode() method is not implemented for " |
| 77 | "DatasetVariantWrapper objects."; |
| 78 | } |
| 79 | bool Decode(const VariantTensorData& data) { |
| 80 | LOG(ERROR) << "The Decode() method is not implemented for " |
| 81 | "DatasetVariantWrapper objects."; |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | private: |
| 86 | DatasetBase* dataset_; // Owns one reference. |
| 87 | }; |
| 88 | |
| 89 | const char kWrappedDatasetVariantTypeName[] = |
| 90 | "tensorflow::data::WrappedDatasetVariant"; |
no outgoing calls
no test coverage detected