1 /*****************************************************************************
2 * Inheritables.hpp Nodes inheritables properties
3 *****************************************************************************
4 * Copyright (C) 2016-2020 VideoLabs, VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #ifndef INHERITABLES_H
21 #define INHERITABLES_H
26 #include "../Time.hpp"
33 class SegmentTimeline
;
34 class SegmentTemplate
;
53 AvailabilityTimeOffset
,
54 AvailabilityTimeComplete
,
56 AbstractAttr(enum Type
);
57 virtual ~AbstractAttr();
58 AbstractAttr(const AbstractAttr
&) = delete;
59 AbstractAttr
& operator=(const AbstractAttr
&) = delete;
61 bool operator ==(const AbstractAttr
&t
) const { return type
== t
.getType(); }
62 bool operator !=(const AbstractAttr
&t
) const { return type
!= t
.getType(); }
63 virtual bool isValid() const { return true; }
64 void setParentNode(AttrsNode
*n
) { parentNode
= n
; }
68 AttrsNode
*parentNode
;
71 class AttrsNode
: public AbstractAttr
74 AttrsNode( Type
, AttrsNode
* = nullptr );
76 AttrsNode(const AttrsNode
&) = delete;
77 AttrsNode
& operator=(const AttrsNode
&) = delete;
78 void addAttribute( AbstractAttr
* );
79 void replaceAttribute( AbstractAttr
* );
80 AbstractAttr
* inheritAttribute(AbstractAttr::Type
);
81 AbstractAttr
* inheritAttribute(AbstractAttr::Type
) const;
83 uint64_t inheritStartNumber() const;
84 stime_t
inheritDuration() const;
85 Timescale
inheritTimescale() const;
86 vlc_tick_t
inheritAvailabilityTimeOffset() const;
87 bool inheritAvailabilityTimeComplete() const;
88 SegmentTimeline
* inheritSegmentTimeline() const;
89 SegmentTemplate
* inheritSegmentTemplate() const;
90 SegmentList
* inheritSegmentList() const;
91 SegmentBase
* inheritSegmentBase() const;
94 AttrsNode
* matchPath(std::list
<AbstractAttr::Type
>&);
95 AbstractAttr
* getAttribute(AbstractAttr::Type
,
96 std::list
<AbstractAttr::Type
>&);
97 AbstractAttr
* getAttribute(AbstractAttr::Type
);
98 AbstractAttr
* getAttribute(AbstractAttr::Type
) const;
99 std::list
<AbstractAttr
*> props
;
100 bool is_canonical_root
;
103 template<enum AbstractAttr::Type e
, typename T
>
104 class AttrWrapper
: public AbstractAttr
107 AttrWrapper(T v
) : AbstractAttr(e
) { value
= v
; }
108 virtual ~AttrWrapper() { condDeleteValue(value
); }
109 AttrWrapper(const AttrWrapper
&) = delete;
110 AttrWrapper
<e
, T
> & operator=(const AttrWrapper
<e
, T
> &) = delete;
111 operator const T
&() const { return value
; }
114 void condDeleteValue(const T
&) {}
115 void condDeleteValue(T
* &v
) { delete v
; }
119 using AvailabilityTimeOffsetAttr
= AttrWrapper
<AbstractAttr::Type::AvailabilityTimeOffset
, vlc_tick_t
>;
120 using AvailabilityTimeCompleteAttr
= AttrWrapper
<AbstractAttr::Type::AvailabilityTimeComplete
, bool>;
121 using StartnumberAttr
= AttrWrapper
<AbstractAttr::Type::StartNumber
, uint64_t>;
124 public AttrWrapper
<AbstractAttr::Type::Timescale
, Timescale
>
127 TimescaleAttr(Timescale v
) :
128 AttrWrapper
<AbstractAttr::Type::Timescale
, Timescale
>( v
) {}
129 virtual bool isValid() const { return value
.isValid(); }
133 public AttrWrapper
<AbstractAttr::Type::Duration
, stime_t
>
136 DurationAttr(stime_t v
) :
137 AttrWrapper
<AbstractAttr::Type::Duration
, stime_t
>( v
) {}
138 virtual bool isValid() const { return value
> 0; }
143 #endif // INHERITABLES_H