ar-cpp
file.h
Go to the documentation of this file.
1 
8 #ifndef AR_FILE_H
9 #define AR_FILE_H
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 namespace ar {
16 
20 class File {
21 public:
22  virtual ~File() = 0;
23 
24  virtual std::string getName() const = 0;
25  virtual std::string getContent() = 0;
26  virtual void saveCopyTo(const std::string& directoryPath) = 0;
27  virtual void saveCopyTo(const std::string& directoryPath,
28  const std::string& name) = 0;
29 
30  static std::unique_ptr<File> fromContentWithName(
31  const std::string& content, const std::string& name);
32  static std::unique_ptr<File> fromFilesystem(const std::string& path);
33  static std::unique_ptr<File> fromFilesystemWithOtherName(
34  const std::string& path, const std::string& name);
35 
38  File(const File&) = delete;
39  File(File&&) = delete;
40  File& operator=(const File&) = delete;
41  File& operator=(File&&) = delete;
43 
44 protected:
45  File();
46 };
47 
51 class Files {
52 private:
54  using Container = std::vector<std::unique_ptr<File>>;
55 
56 public:
57  using size_type = Container::size_type;
58  using value_type = Container::value_type;
59  using reference = Container::reference;
60  using iterator = Container::iterator;
61 
62 public:
63  Files();
64  Files(Files&& other);
65  ~Files();
66 
69  reference front();
70  reference back();
72 
75  iterator begin() noexcept;
76  iterator end() noexcept;
78 
81  bool empty() const noexcept;
82  size_type size() const noexcept;
84 
87  void push_back(value_type file);
89 
90 private:
91  Container files;
92 };
93 
94 } // namespace ar
95 
96 #endif
static std::unique_ptr< File > fromContentWithName(const std::string &content, const std::string &name)
Returns a file containing the given content with the given name.
Definition: file.cpp:49
virtual ~File()=0
virtual std::string getName() const =0
Returns the name of the file.
Container::value_type value_type
Definition: file.h:58
virtual std::string getContent()=0
Returns the content of the file.
Base class and factory for files.
Definition: file.h:20
static std::unique_ptr< File > fromFilesystem(const std::string &path)
Returns a file from the given path.
Definition: file.cpp:61
Container::size_type size_type
Definition: file.h:57
The namespace of the library.
Definition: doxygen.h:8
virtual void saveCopyTo(const std::string &directoryPath)=0
Stores a copy of the file into the given directory.
Container::iterator iterator
Definition: file.h:60
Container::reference reference
Definition: file.h:59
static std::unique_ptr< File > fromFilesystemWithOtherName(const std::string &path, const std::string &name)
Returns a file from the given path, but with a custom name.
Definition: file.cpp:74
A vector-like container storing files.
Definition: file.h:51
File & operator=(const File &)=delete