• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

palfrey / tagpy / 12737601019

12 Jan 2025 10:23PM UTC coverage: 91.275% (-4.0%) from 95.238%
12737601019

push

github

web-flow
Merge pull request #32 from palfrey/upgrade-ubuntu-builds

Upgrade all the ubuntu builds to 24.04

680 of 745 relevant lines covered (91.28%)

45.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.25
/src/wrapper/common.hpp
1
// Copyright (c) 2006-2008 Andreas Kloeckner
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to
5
// deal in the Software without restriction, including without limitation the
6
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
// sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
// IN THE SOFTWARE.
20

21

22

23

24
#include <boost/python.hpp>
25
#include <boost/scoped_array.hpp>
26
#include <stdexcept>
27

28

29

30

31
using namespace boost::python;
32
using namespace TagLib;
33
using namespace std;
34

35

36

37
#define MF_OL(MF, MIN, MAX) \
38
  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MF##_overloads, MF, MIN, MAX);
39
#define DEF_SIMPLE_METHOD(NAME) \
40
  def(#NAME, &cl::NAME)
41
#define DEF_VIRTUAL_METHOD(NAME) \
42
  def(#NAME, pure_virtual(&cl::NAME))
43
#define DEF_OVERLOADED_METHOD(NAME, CAST) \
44
  def(#NAME, (CAST) &cl::NAME, NAME##_overloads())
45
#define ENUM_VALUE(NAME) \
46
  value(#NAME, scope::NAME)
47
#define ADD_RO_PROPERTY(NAME) \
48
  add_property(#NAME, &cl::NAME)
49

50
#define CHECK_VERSION(MAJOR, MINOR, PATCH) \
51
  (MAJOR << 16) + \
52
  (MINOR << 8) + \
53
  (PATCH << 0)
54

55
#define TAGLIB_HEX_VERSION CHECK_VERSION(TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION, TAGLIB_PATCH_VERSION)
56

57
#if CHECK_VERSION(1,9,0) < TAGLIB_HEX_VERSION
58
#warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59
#warning TagPy is meant to wrap TagLib 1.9 and above.
60
#warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61
#endif
62

63

64

65

66
namespace {
67
  template<typename Iterator>
68
  inline object make_list(Iterator first, Iterator last)
×
69
  {
70
    boost::python::list result;
×
71
    while (first != last)
×
72
      result.append(*first++);
×
73
    return result;
×
74
  }
×
75

76

77

78

79
  // -------------------------------------------------------------
80
  // Map
81
  // -------------------------------------------------------------
82
  template<typename Key, typename Value>
83
  Value &Map_getitem(Map<Key, Value> &m, const Key &k)
180✔
84
  {
85
    if (!m.contains(k))
180✔
86
    {
87
      PyErr_SetString( PyExc_KeyError, "key not in map");
×
88
      throw error_already_set();
×
89
    }
90
    return m[k];
180✔
91
  }
92

93
  template<typename Key, typename Value>
94
  void Map_setitem(Map<Key, Value> &m, const Key &k, const Value &v)
×
95
  {
96
    m[k] = v;
×
97
  }
×
98

99
  template<typename Key, typename Value>
100
  object Map_keys(Map<Key, Value> &m)
30✔
101
  {
102
    boost::python::list keys;
30✔
103

104
    typedef Map<Key, Value> map;
105
    typename map::Iterator first = m.begin(), last = m.end();
30✔
106
    while (first != last)
210✔
107
      keys.append((first++)->first);
180✔
108
    return keys;
30✔
109
  }
30✔
110

111
  template<typename Key, typename Value>
112
  void exposeMap(const char *name)
90✔
113
  {
114
    typedef Map<Key, Value> map;
115
    class_<map>(name)
90✔
116
      .def("__len__", &map::size)
90✔
117
      .def("size", &map::size)
90✔
118
      .def("clear", &map::clear, return_self<>())
90✔
119
      .def("isEmpty", &map::isEmpty)
180✔
120
      .def("__getitem__", Map_getitem<Key, Value>, return_internal_reference<>())
180✔
121
      .def("__setitem__", Map_setitem<Key, Value>)
90✔
122
      .def("__contains__", &map::contains)
90✔
123
      .def("keys", Map_keys<Key, Value>)
90✔
124
      ;
125
  }
90✔
126

127
  // -------------------------------------------------------------
128
  // List
129
  // -------------------------------------------------------------
130
  template<typename Value>
131
  Value &List_getitem(List<Value> &l, uint i)
×
132
  {
133
    if (i >= l.size())
×
134
    {
135
      PyErr_SetString( PyExc_IndexError, "index out of bounds");
×
136
      throw error_already_set();
×
137
    }
138
    return l[i];
×
139
  }
140

141
  template<typename Value>
142
  void List_setitem(List<Value> &l, uint i, Value v)
×
143
  {
144
    if (i >= l.size())
×
145
    {
146
      PyErr_SetString( PyExc_IndexError, "index out of bounds");
×
147
      throw error_already_set();
×
148
    }
149
    l[i] = v;
×
150
  }
×
151

152
  template<typename Value>
153
  void List_append(List<Value> &l, Value v)
30✔
154
  {
155
    l.append(v);
30✔
156
  }
30✔
157

158
  template<typename Value>
159
  void exposeList(const char *name)
60✔
160
  {
161
    typedef List<Value> list;
162
    class_<list>(name)
60✔
163
      .def("__len__", &list::size)
60✔
164
      .def("size", &list::size)
60✔
165
      .def("clear", &list::clear, return_self<>())
60✔
166
      .def("isEmpty", &list::isEmpty)
120✔
167
      .def("__getitem__", List_getitem<Value>, return_value_policy<return_by_value>())
120✔
168
      .def("__setitem__", List_setitem<Value>)
60✔
169
      .def("append", List_append<Value>)
60✔
170
      // MISSING: iterators, insert, find, contains, erase,
171
      // assignment, comparison
172
      ;
173
  }
60✔
174

175
  // -------------------------------------------------------------
176
  // PointerList
177
  // -------------------------------------------------------------
178
  template<typename Value>
179
  Value *&PointerList_getitem(List<Value *> &l, uint i)
1,380✔
180
  {
181
    if (i >= l.size())
1,380✔
182
    {
183
      PyErr_SetString( PyExc_IndexError, "index out of bounds");
230✔
184
      throw error_already_set();
230✔
185
    }
186
    return l[i];
1,150✔
187
  }
188

189
  template<typename Value>
190
  void PointerList_setitem(List<Value *> &l, uint i, auto_ptr<Value> v)
×
191
  {
192
    if (i >= l.size())
×
193
    {
194
      PyErr_SetString( PyExc_IndexError, "index out of bounds");
×
195
      throw error_already_set();
×
196
    }
197
    l[i] = v.release();
×
198
  }
×
199

200
  template<typename Value>
201
  void PointerList_append(List<Value *> &l, auto_ptr<Value> v)
×
202
  {
203
    l.append(v.release());
×
204
  }
×
205

206
  template<typename Value>
207
  void exposePointerList(const char *name)
60✔
208
  {
209
    typedef List<Value *> list;
210
    class_<list>(name)
60✔
211
      .def("__len__", &list::size)
60✔
212
      .def("size", &list::size)
60✔
213
      .def("clear", &list::clear, return_self<>())
60✔
214
      .def("isEmpty", &list::isEmpty)
120✔
215
      .def("__getitem__", PointerList_getitem<Value>, return_internal_reference<>())
120✔
216
      .def("__setitem__", PointerList_setitem<Value>)
60✔
217
      .def("append", PointerList_append<Value>)
60✔
218
      // MISSING: iterators, insert, find, contains, erase,
219
      // assignment, comparison
220
      ;
221
  }
60✔
222
}
223

224
template <class T>
225
struct TagWrap : T, wrapper<T>
226
{
227
    String title() const { return this->get_override("title")(); }
228
    String artist() const { return this->get_override("artist")(); }
229
    String album() const { return this->get_override("album")(); }
230
    String comment() const { return this->get_override("comment")(); }
231
    String genre() const { return this->get_override("genre")(); }
232
    unsigned int year() const { return this->get_override("year")(); }
233
    unsigned int track() const { return this->get_override("track")(); }
234
    void setTitle(const String &v) const { this->get_override("setTitle")(v); }
235
    void setArtist(const String &v) const { this->get_override("setArtist")(v); }
236
    void setAlbum(const String &v) const { this->get_override("setAlbum")(v); }
237
    void setComment(const String &v) const { this->get_override("setComment")(v); }
238
    void setGenre(const String &v) const { this->get_override("setGenre")(v); }
239
    void setYear(unsigned int i) const { this->get_override("setYear")(i); }
240
    void setTrack(unsigned int i) const { this->get_override("setTrack")(i); }
241
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc