use of C++23 code
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
50
components/storage/include/storage/storage.h
Normal file
50
components/storage/include/storage/storage.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2026 by Peter Siegmund (mars3142)
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "storage/storage_error.h"
|
||||
|
||||
#include <expected>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace storage {
|
||||
|
||||
class Storage {
|
||||
public:
|
||||
/**
|
||||
* Liest eine Datei von einem Pfad.
|
||||
* @param path Der Dateipfad.
|
||||
* @return Ein expected mit den Dateidaten oder einem StorageError.
|
||||
*/
|
||||
[[nodiscard]] std::expected<std::vector<uint8_t>, StorageError> readFile(
|
||||
const std::string &path) const;
|
||||
|
||||
/**
|
||||
* Schreibt Daten in eine Datei.
|
||||
* @param path Der Dateipfad.
|
||||
* @param data Die zu schreibenden Daten.
|
||||
* @return Ein expected<void> oder einem StorageError.
|
||||
*/
|
||||
[[nodiscard]] std::expected<void, StorageError> writeFile(
|
||||
const std::string &path,
|
||||
const std::vector<uint8_t> &data) const;
|
||||
};
|
||||
|
||||
} // namespace storage
|
||||
29
components/storage/include/storage/storage_error.h
Normal file
29
components/storage/include/storage/storage_error.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2026 by Peter Siegmund (mars3142)
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace storage {
|
||||
|
||||
enum class StorageError {
|
||||
FileNotFound,
|
||||
ReadError,
|
||||
WriteError,
|
||||
};
|
||||
|
||||
} // namespace storage
|
||||
Reference in New Issue
Block a user