CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
file_serializer_manager.cpp
Go to the documentation of this file.
1
10#include <spdlog/spdlog.h>
11
13
15 std::unique_ptr<IFileSerializerWriter> writer,
16 std::unique_ptr<IFileSerializerReader> reader)
17 : m_writer(std::move(writer))
18 , m_reader(std::move(reader))
19{
20 if (!m_writer || !m_reader) {
21 spdlog::error("FileSerializerManager: Constructor received a null IFileSerializerWriter or IFileSerializerReader.");
22 throw std::invalid_argument("FileSerializerManager: Writer and Reader cannot be null.");
23 }
24 spdlog::debug("FileSerializerManager: Constructed with IFileSerializerWriter and IFileSerializerReader.");
25}
26
27bool FileSerializerManager::saveToFile(std::string_view source_image_path, std::span<const Operations::OperationDescriptor> operations) const
28{
29 if (source_image_path.empty()) {
30 spdlog::error("FileSerializerManager::saveToFile: Source image path is empty.");
31 return false;
32 }
33
34 if (operations.empty()) {
35 spdlog::info("FileSerializerManager::saveToFile: Operations list is empty. Saving empty list to XMP.");
36 // Saving an empty list is allowed (clearing XMP).
37 }
38
39 spdlog::debug("FileSerializerManager::saveToFile: Attempting to save {} operations for image: {}", operations.size(), source_image_path);
40
41 // Delegate the actual saving to the injected writer
42 // The Writer handles the conversion to XMP and the file I/O.
43 bool success = m_writer->saveToFile(source_image_path, operations);
44
45 if (success) {
46 spdlog::info("FileSerializerManager::saveToFile: Successfully saved {} operations to file for image: {}", operations.size(), source_image_path);
47 } else {
48 spdlog::error("FileSerializerManager::saveToFile: Failed to save operations to file for image: {}", source_image_path);
49 }
50
51 return success;
52}
53
54std::vector<Operations::OperationDescriptor> FileSerializerManager::loadFromFile(std::string_view source_image_path) const
55{
56 if (source_image_path.empty()) {
57 spdlog::error("FileSerializerManager::loadFromFile: Source image path is empty.");
58 return {}; // Return an empty vector
59 }
60
61 spdlog::debug("FileSerializerManager::loadFromFile: Attempting to load operations for image: {}", source_image_path);
62
63 // Delegate the actual loading to the injected reader
64 // The Reader handles the file I/O, XMP parsing, and conversion to OperationDescriptors.
65 std::vector<Operations::OperationDescriptor> operations = m_reader->loadFromFile(source_image_path);
66
67 if (operations.empty()) {
68 spdlog::info("FileSerializerManager::loadFromFile: No operations loaded from file for image: {} (file might not exist or be empty)", source_image_path);
69 } else {
70 spdlog::info("FileSerializerManager::loadFromFile: Successfully loaded {} operations from file for image: {}", operations.size(), source_image_path);
71 }
72
73 return operations;
74}
75
76} // namespace CaptureMoment::Core::Serializer
std::vector< Operations::OperationDescriptor > loadFromFile(std::string_view source_image_path) const
Loads a list of operations from a file associated with the source image path.
FileSerializerManager(std::unique_ptr< IFileSerializerWriter > writer, std::unique_ptr< IFileSerializerReader > reader)
Constructs a FileSerializerManager.
bool saveToFile(std::string_view source_image_path, std::span< const Operations::OperationDescriptor > operations) const
Saves the provided list of operations to a file associated with the source image path.
Declaration of FileSerializerManager class.
CaptureMoment — footer