OGLplus  (0.59.0) a C++ wrapper for rendering APIs

file_contents.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_FILE_CONTENTS_HPP
10 #define EAGINE_FILE_CONTENTS_HPP
11 
12 #include "branch_predict.hpp"
13 #include "config/basic.hpp"
14 #include "interface.hpp"
15 #include "protected_member.hpp"
16 #include "string_span.hpp"
17 #include "struct_memory_block.hpp"
18 #include <memory>
19 
20 namespace eagine {
21 
24 struct file_contents_intf : interface<file_contents_intf> {
25  virtual auto block() noexcept -> memory::const_block = 0;
26 };
27 
31 public:
33  file_contents() = default;
34 
37 
40  auto is_loaded() const noexcept -> bool {
41  return bool(_pimpl);
42  }
43 
46  explicit operator bool() const noexcept {
47  return is_loaded();
48  }
49 
52  auto block() const noexcept -> memory::const_block {
53  return bool(EAGINE_LIKELY(_pimpl)) ? _pimpl->block()
55  }
56 
60  operator memory::const_block() const noexcept {
61  return block();
62  }
63 
64 private:
65  std::shared_ptr<file_contents_intf> _pimpl{};
66 };
67 
70 template <typename T>
72  : protected_member<file_contents>
73  , public structured_memory_block<const T> {
74 public:
78  , structured_memory_block<const T>(get_the_member()) {}
79 
83  : protected_member<file_contents>(std::move(fc))
84  , structured_memory_block<const T>(get_the_member()) {}
85 };
86 
87 } // namespace eagine
88 
89 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
90 #include <eagine/file_contents.inl>
91 #endif
92 
93 #endif // EAGINE_FILE_CONTENTS_HPP
Class providing access to the contents of a file.
Definition: file_contents.hpp:30
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto block() const noexcept -> memory::const_block
Returns the block viewing the loaded file contents.
Definition: file_contents.hpp:52
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
Class loading a baked structured data from a file.
Definition: file_contents.hpp:71
structured_file_content(file_contents &&fc)
Construction from a file contents instance.
Definition: file_contents.hpp:82
auto is_loaded() const noexcept -> bool
Checks if the contents were loaded.
Definition: file_contents.hpp:40
Base template for abstract interfaces, implements common functionality.
Definition: interface.hpp:18
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
structured_file_content(string_view path)
Constructor that opens and loads contents of file at the given path.
Definition: file_contents.hpp:76
file_contents()=default
Default constructor.
Class holding a single tagged data member.
Definition: protected_member.hpp:20
Interface for file content getter implementations.
Definition: file_contents.hpp:24
auto get_the_member(type_identity< file_contents >=type_identity< file_contents >()) noexcept -> file_contents &
Returns a reference to the stored member.
Definition: protected_member.hpp:23

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).