| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace imgdoc2 | ||
| 8 | { | ||
| 9 | /// \brief interface for outputting binary data | ||
| 10 | /// | ||
| 11 | /// This interface is used to output binary data from libimgdoc2. It is passed in to | ||
| 12 | /// the corresponding operation, then the "Reserve"-method is called for advertising | ||
| 13 | /// the size of the data. Then (multiple) calls to "SetData" follow, where the object | ||
| 14 | /// is requested to copy data into its internal storage. | ||
| 15 | class IBlobOutput | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | /// Notifies about the size of data to be returned. | ||
| 19 | /// This method must only be called once, additional calls should result in an | ||
| 20 | /// exception. If this method returns false, it is interpreted as "the client is | ||
| 21 | /// not interested in the data" and there will not be subsequent calls to "SetData". | ||
| 22 | /// \param s The size of the data being returned. | ||
| 23 | /// \returns True if it succeeds (and the object is ready to handle "SetData" calls), false if it fails. | ||
| 24 | virtual bool Reserve(size_t s) = 0; | ||
| 25 | |||
| 26 | /// Data is passed to the "blob-output"-object with this call. The pointer "data" is | ||
| 27 | /// only assumed to be valid for the duration of this call - in other words, the object | ||
| 28 | /// needs to access the memory only within the call (and e.g. make a copy of the data). | ||
| 29 | /// The address (indicated by offset and size) must be completely within the size as | ||
| 30 | /// advertised with the "Reserve"-call. The method should validate this condition and | ||
| 31 | /// throw an exception in case of a violation. | ||
| 32 | /// If the method returns "false", it is interpreted "the object is not interested in any | ||
| 33 | /// additional data", and subsequent calls may be suppressed. | ||
| 34 | /// \param offset The offset. | ||
| 35 | /// \param size The size. | ||
| 36 | /// \param data The data. | ||
| 37 | /// \returns True if it succeeds, false if it fails. | ||
| 38 | virtual bool SetData(size_t offset, size_t size, const void* data) = 0; | ||
| 39 | |||
| 40 | 28 | virtual ~IBlobOutput() = default; | |
| 41 | public: | ||
| 42 | // no copy and no move (-> https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-copy-move-or-destructor-function-define-or-delete-them-all ) | ||
| 43 | IBlobOutput() = default; | ||
| 44 | IBlobOutput(const IBlobOutput&) = delete; // copy constructor | ||
| 45 | IBlobOutput& operator=(const IBlobOutput&) = delete; // copy assignment | ||
| 46 | IBlobOutput(IBlobOutput&&) = delete; // move constructor | ||
| 47 | IBlobOutput& operator=(IBlobOutput&&) = delete; // move assignment | ||
| 48 | }; | ||
| 49 | } | ||
| 50 |