Skip to content
Snippets Groups Projects
Commit cf79e6d2 authored by Davide Mor's avatar Davide Mor
Browse files

[Registry] Added File backed backend

parent fde561c1
Branches
No related tags found
No related merge requests found
...@@ -135,6 +135,7 @@ set(BOARDCORE_SRC ...@@ -135,6 +135,7 @@ set(BOARDCORE_SRC
${BOARDCORE_PATH}/src/shared/utils/TestUtils/TestHelper.cpp ${BOARDCORE_PATH}/src/shared/utils/TestUtils/TestHelper.cpp
${BOARDCORE_PATH}/src/shared/utils/Registry/RegistryFrontend.cpp ${BOARDCORE_PATH}/src/shared/utils/Registry/RegistryFrontend.cpp
${BOARDCORE_PATH}/src/shared/utils/Registry/RegistrySerializer.cpp ${BOARDCORE_PATH}/src/shared/utils/Registry/RegistrySerializer.cpp
${BOARDCORE_PATH}/src/shared/utils/Registry/Backend/FileBackend.cpp
) )
# Creates the Skyward::Boardcore::${BOARD_NAME} library # Creates the Skyward::Boardcore::${BOARD_NAME} library
......
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Author: Davide Mor
*
* 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.
*/
#include "FileBackend.h"
#include <fstream>
#include <vector>
namespace Boardcore
{
bool FileBackend::start() { return true; }
bool FileBackend::load(std::vector<uint8_t>& buf)
{
std::ifstream is(path, std::ifstream::ate | std::ifstream::binary);
if (!is.good())
return false;
size_t size = is.tellg();
is.seekg(0);
buf.resize(size);
is.read(reinterpret_cast<char*>(buf.data()), size);
return is.good();
}
bool FileBackend::save(std::vector<uint8_t>& buf)
{
std::ofstream os(path, std::ifstream::binary);
if (!os.good())
return false;
os.write(reinterpret_cast<char*>(buf.data()), buf.size());
return os.good();
}
} // namespace Boardcore
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Author: Davide Mor
*
* 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 <utils/Registry/RegistryBackend.h>
#include <string>
namespace Boardcore
{
class FileBackend : public RegistryBackend
{
public:
explicit FileBackend(std::string path) : path{std::move(path)} {}
[[nodiscard]] bool start() override;
bool load(std::vector<uint8_t>& buf) override;
bool save(std::vector<uint8_t>& buf) override;
private:
std::string path;
};
} // namespace Boardcore
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment