Shaka Player Embedded
dom_string_list.cc
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 namespace shaka {
18 namespace js {
19 namespace dom {
20 
22 DOMStringList::DOMStringList(const std::vector<std::string>& copy)
23  : std::vector<std::string>(copy) {}
24 // \cond Doxygen_Skip
25 DOMStringList::~DOMStringList() {}
26 // \endcond Doxygen_Skip
27 
29  if (index >= size())
30  return nullopt;
31  return (*this)[index];
32 }
33 
34 bool DOMStringList::getter(size_t index, std::string* value) const {
35  if (index >= size())
36  return false;
37  *value = (*this)[index];
38  return true;
39 }
40 
41 bool DOMStringList::contains(const std::string& item) const {
42  return util::contains(*this, item);
43 }
44 
45 
47  AddIndexer(&DOMStringList::getter);
48 
49  AddGenericProperty<DOMStringList>("length", &DOMStringList::size);
50 
51  AddMemberFunction("item", &DOMStringList::item);
52  AddMemberFunction("contains", &DOMStringList::contains);
53 }
54 
55 } // namespace dom
56 } // namespace js
57 } // namespace shaka
bool contains(const std::vector< T > &vec, U &&elem)
Definition: utils.h:87
const nullopt_t nullopt
Definition: optional.cc:22
optional< std::string > item(uint32_t index) const
bool contains(const std::string &item) const
bool getter(size_t index, std::string *value) const