* Manages the lifetime of a tiledb_string_t* handle and provides operations on * it. */
| 47 | * it. |
| 48 | */ |
| 49 | class CAPIString { |
| 50 | public: |
| 51 | /** |
| 52 | * Constructor. Takes ownership of the handle. |
| 53 | * |
| 54 | * @param handle A pointer to the string handle. Must not be null and must not |
| 55 | * point to a null handle. |
| 56 | */ |
| 57 | CAPIString(tiledb_string_t** handle) { |
| 58 | if (handle == nullptr || *handle == nullptr) { |
| 59 | throw std::invalid_argument( |
| 60 | "Pointer to string handle cannot be null or point to null handle."); |
| 61 | } |
| 62 | string_ = *handle; |
| 63 | *handle = nullptr; |
| 64 | } |
| 65 | |
| 66 | ~CAPIString() { |
| 67 | auto result = tiledb_status(tiledb_string_free(&string_)); |
| 68 | if (result != TILEDB_OK) { |
| 69 | log_warn("Could not free string; Error code: " + std::to_string(result)); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Disable copy and move. Because this class owns a resource, |
| 74 | // copying it must not be supported, but moving it could be. |
| 75 | CAPIString(const CAPIString&) = delete; |
| 76 | CAPIString operator=(const CAPIString&) = delete; |
| 77 | CAPIString(const CAPIString&&) = delete; |
| 78 | CAPIString operator=(const CAPIString&&) = delete; |
| 79 | |
| 80 | std::string str() const { |
| 81 | const char* c; |
| 82 | size_t size; |
| 83 | auto status = tiledb_status(tiledb_string_view(string_, &c, &size)); |
| 84 | if (status != TILEDB_OK) { |
| 85 | throw TileDBError( |
| 86 | "Could not view string; Error code: " + std::to_string(status)); |
| 87 | } |
| 88 | return {c, size}; |
| 89 | } |
| 90 | |
| 91 | private: |
| 92 | /** The C API string handle. Invariant: must not be null. */ |
| 93 | tiledb_string_t* string_; |
| 94 | }; |
| 95 | |
| 96 | /** |
| 97 | * Returns a C++ string with the handle's data. The handle is subsequently |
no outgoing calls
no test coverage detected