SDFormat Editor
Loading...
Searching...
No Matches
file_operations.h
1/*
2* sdformat-editor
3* Copyright 2025 sdformat-editor
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*
17* Developer: Zaid Duraid, Ean Wheeler, Evan Vokey
18*/
19
20#ifndef FILE_OPERATIONS_HH_
21#define FILE_OPERATIONS_HH_
22
23#include <string>
24#include <iostream>
25#include <array>
26#include <fstream>
27
30{
31
34 // NOTE: Singleton Implementation based on Mayers Singleton for C++11 and beyond
35 // See https://www.modernescpp.com/index.php/thread-safe-initialization-of-a-singleton/
37 public: static FileOperations& GetSoleInstance();
38
42 public: std::string OpenFileDialog();
43
47 public: std::string OpenDirectoryDialog();
48
54 public: bool WriteFile(const std::string& file_path, const std::string& contents);
55
60 public: bool WriteFile(const std::string& contents);
61
65 public: void SetActiveFilePath(const std::string& file_path);
66
69 private: FileOperations() = default;
70
73 private: ~FileOperations() = default;
74
78 private: FileOperations& operator = (const FileOperations&) = delete;
79
83 private: FileOperations(const FileOperations&) = delete;
84
85 private: std::string active_file_path;
86};
87
88#endif
Singleton class to handle file operations.
Definition file_operations.h:30
FileOperations()=default
Prevent access to the constructor of this class.
std::string OpenFileDialog()
Opens a dialog for the user to open a file on their filesystem.
Definition file_operations.cpp:29
FileOperations & operator=(const FileOperations &)=delete
Prevent the assignment of one instance of FileOperations to another, ensuring there can only be one i...
static FileOperations & GetSoleInstance()
The only method by which a FileOperations instance can be returned.
Definition file_operations.cpp:22
bool WriteFile(const std::string &file_path, const std::string &contents)
writes a string to a file
Definition file_operations.cpp:89
std::string OpenDirectoryDialog()
Opens a dialog for the user to open a directory on their filesystem.
Definition file_operations.cpp:53
void SetActiveFilePath(const std::string &file_path)
Sets the active file path.
Definition file_operations.cpp:79
FileOperations(const FileOperations &)=delete
Delete the copy constructor of FileOperations, preventing copies of the reference the the sole instan...
~FileOperations()=default
Prevent access to the destructor of this class.