libebml_ng
childSlot_t.h
Go to the documentation of this file.
1 #ifndef EBML_NG_MASTERELEMENT_CHILDSLOT_H
2 #define EBML_NG_MASTERELEMENT_CHILDSLOT_H
3 
4 #include "../../forwards.h"
5 #include "../../ptrs.h"
6 #include "../../struct/datetime.h"
7 #include "../../ebmlDataElement.h"
8 
9 namespace ebml {
10  class childTypeSpec_t;
11 
21  template<typename T=ebmlElement>
22  class childSlot_t {
23  private:
24  ebmlMasterElement* _parent;
25  const childTypeSpec_t * _spec;
26  // ebmlElement_sp* _childslot;
27  ebml::ptr<T>* _childslot;
28  T* _raw_ptr = nullptr;
29  bool _allownull = true;
30 
31  public:
32  childSlot_t(ebmlMasterElement* parent, const childTypeSpec_t &, ebml::ptr<T>& childslot, bool allownull=true);
35 
36  template<typename U>
37  std::enable_if_t<std::is_base_of<ebmlElement, T>::value && std::is_base_of<T, U>::value && !std::is_same<T, U>::value, childSlot_t<T>&>
38  operator=(const ebml::ptr<U>& item);
39 
40  template<typename U>
41  std::enable_if_t<std::is_base_of<ebmlElement, T>::value && std::is_base_of<T, U>::value && !std::is_same<T, U>::value, childSlot_t<T>&>
42  operator=(ebml::ptr<U>&& item);
43 
44  bool operator==(const std::nullptr_t&);
45  bool operator==(const ebml::ptr<T>& item);
46  bool operator==(const ebml::ptr<const T>& item);
47 
48  template<typename U>
49  std::enable_if_t<std::is_base_of<ebmlElement, T>::value && std::is_base_of<T, U>::value && !std::is_same<T, U>::value, bool&>
50  operator==(const ebml::ptr<U>& item);
51 
52  bool operator==(const childSlot_t<T>& item);
53  operator ebml::ptr<T>() const;
54  T* operator->() const;
55  const ebml::ptr<T>& get() const;
56  operator T&() const;
57 
58  template<typename U>
59  inline U& as() const;
60  };
61 
62  template<>
64  private:
65  ebmlMasterElement* _parent;
66  const childTypeSpec_t * _spec;
67  ebmlElement_sp* _childslot;
68  bool _allownull = true;
69  ebmlElement* _raw_ptr;
70 
71  public:
72  childSlot_t(ebmlMasterElement* parent, const childTypeSpec_t &, ebmlElement_sp& childslot, bool allownull=true);
76 
77  bool operator==(const ebmlElement_sp& item);
78  bool operator==(const c_ebmlElement_sp& item);
79  bool operator==(const childSlot_t<ebmlElement>& item);
80  operator ebmlElement&() const;
81 
82  // Mirror methods
83  const ebmlElementType & cls() const;
84  ebmlID_t ebmlID() const;
85 
86  template<typename T>
87  inline T& as();
88 
91 
92  template<typename T>
93  inline ebml::ptr<T> sp();
94 
95  template<typename T>
96  inline ebml::ptr<T> sp() const;
97 
100 
101  template<typename T>
102  inline ebml::wptr<T> wp();
103 
104  template<typename T>
105  inline ebml::wptr<T> wp() const;
106 
107  bool parent_is_const() const; // Member function that specifies if pointer is to a const parent or non-const parent.
108  ebml::ptr<ebmlMasterElement> parent() const; // Returns pointer to non-const parent. Throws ebmlException if parent_is_const() returns true.
109  ebml::ptr<const ebmlMasterElement> c_parent() const; // Returns pointer to const parent.
110  ebmlElement_sp root() const;
111  c_ebmlElement_sp c_root() const;
112  bool hasParent() const;
113  unsigned char headSize() const;
114  unsigned char headSize(size_t) const; // May be deprecated
115  unsigned char sizeWidth() const;
116  unsigned char sizeWidth(size_t) const; // May be deprecated
117  size_t outerSize() const;
118  size_t outerSize(size_t) const; // May be deprecated
119  size_t dataSize() const;
120  off_t offsetInParent() const;
121  off_t offsetInFile() const;
122  off_t dataOffsetInParent() const;
123  off_t dataOffsetInFile() const;
124  std::string encode() const;
125  size_t encode(char*) const;
126  size_t encode(const ioBase_sp&) const;
127  size_t encode(const ioBase_sp&, off_t) const;
128  size_t encode(ioBase*) const;
129  size_t encode(ioBase*, off_t) const;
130  size_t encode(char*, size_t) const;
131  ebml::ptr<ebmlElement> clone() const;
132  std::wstring minirepr() const;
133  std::wstring repr() const;
134  };
135 
136  // template<typename T>
137  // T& data(const childSlot_t<ebmlElement>& elem);
138 
139  extern template class childSlot_t<ebmlElement>;
140  extern template class childSlot_t<ebmlMasterElement>;
142  extern template class childSlot_t<ebmlDataElement<long long>>;
143  extern template class childSlot_t<ebmlDataElement<double>>;
144  extern template class childSlot_t<ebmlDataElement<std::string>>;
145  extern template class childSlot_t<ebmlDataElement<std::wstring>>;
146  extern template class childSlot_t<ebmlDataElement<timepoint_t>>;
147 }
148 #endif
Abstract base class for EBML Element Type objects.
Definition: ebmlElementType.h:106
U & as() const
Abstract base class for EBML master element instances.This class provides the functionality to manage...
Definition: ebmlMasterElement.h:19
childSlot_t(ebmlMasterElement *parent, const childTypeSpec_t &, ebml::ptr< T > &childslot, bool allownull=true)
A drop-in replacement for std::weak_ptr tailored for EBML objects.
Definition: ptrs.h:30
Definition: basictypes.h:40
A drop-in replacement for std::shared_ptr tailored for EBML objects.
Definition: ptrs.h:27
Definition: childSlot_t.h:63
std::wstring repr(const std::string &str)
Definition: repr.cpp:36
bool operator==(const std::nullptr_t &)
uint64_t ebmlID_t
Definition: ebmlID_t.h:7
T * operator->() const
Abstract base class for EBML Element instances.
Definition: ebmlElement.h:79
Specifies accepted child element types within a parent element.
Definition: childTypeSpec.h:76
Base class for file-like IO operations.
Definition: io.h:22
childSlot_t< T > & operator=(const ebml::ptr< T > &item)
A templated helper class managing a child slot within an EBML master element.
Definition: childSlot_t.h:22