libebml_ng
ebmlDocument.h
Go to the documentation of this file.
1 #ifndef EBML_NG_DOCUMENT_H
2 #define EBML_NG_DOCUMENT_H
3 
4 #include <shared_mutex>
5 #include <mutex>
6 
7 #include "ptrs.h"
8 
9 namespace ebml {
10  class ebmlDocument : public std::enable_shared_from_this<ebmlDocument> {
11  private:
12  const ebmlSchema* _schema;
13  ioBase_sp _file;
14  ebmlElement_sp _head;
15  ebmlElement_sp _root;
16  mutable std::shared_mutex _lock;
17  size_t _blksize = 0;
18 
19  protected:
20  ebmlDocument(const ebmlSchema*);
21  ebmlDocument(const ebmlSchema*, const ioBase_sp&);
23 
24  // TODO: Implement (passing a validation check)
25  void setHead(const ebmlElement_sp&) {};
26  void setHead(ebmlElement_sp&&);
27 
28  void setRoot(const ebmlElement_sp&) {};
29  void setRoot(ebmlElement_sp&&);
30 
31  public:
32  ioBase& file();
33  size_t blksize() const;
34  const ebmlElement_sp& root() const;
35 
36  template<typename T>
37  ebml::ptr<T> root() const {
38  return ebml_dynamic_pointer_cast<T>(this->_root);
39  }
40 
41  const ebmlElement_sp& head() const;
42  const ebmlSchema* schema() const;
43  std::unique_lock<std::shared_mutex> wlock() const;
44  std::shared_lock<std::shared_mutex> rlock() const;
45  std::shared_mutex& mutex() const;
46 
47  friend class ebmlSchema;
48  };
49 }
50 
51 #endif
std::shared_mutex & mutex() const
Definition: ebmlDocument.cpp:63
ebml_shared_ptr< T > ebml_dynamic_pointer_cast(const ebml_shared_ptr< U > &)
Definition: ptrs.h:676
ebml::ptr< T > root() const
Definition: ebmlDocument.h:37
const ebmlElement_sp & root() const
Definition: ebmlDocument.cpp:44
void setRoot(const ebmlElement_sp &)
Definition: ebmlDocument.h:28
const ebmlElement_sp & head() const
Definition: ebmlDocument.cpp:48
Definition: basictypes.h:40
A drop-in replacement for std::shared_ptr tailored for EBML objects.
Definition: ptrs.h:27
Definition: ebmlSchema.h:32
std::shared_lock< std::shared_mutex > rlock() const
Definition: ebmlDocument.cpp:59
Definition: ebmlDocument.h:10
void setHead(const ebmlElement_sp &)
Definition: ebmlDocument.h:25
std::unique_lock< std::shared_mutex > wlock() const
Definition: ebmlDocument.cpp:55
ebmlDocument(const ebmlSchema *)
Definition: ebmlDocument.cpp:8
size_t blksize() const
Definition: ebmlDocument.cpp:40
Base class for file-like IO operations.
Definition: io.h:22
ioBase & file()
Definition: ebmlDocument.cpp:32
const ebmlSchema * schema() const
Definition: ebmlDocument.cpp:51