File Coverage

t/cookbook/recipe08.xsi
Criterion Covered Total %
statement 2 31 6.4
branch 2 46 4.3
condition n/a
subroutine n/a
pod n/a
total 4 77 5.1


line stmt bran cond sub pod time code
1             MODE: INLINE
2             #include
3              
4             /* is able to hold only files in WAV-format */
5             struct WAVFile {
6             WAVFile(const char* name): name_{name} {}
7             const char* name() const noexcept { return name_; }
8             private:
9             const char* name_;
10             };
11              
12             /* is able to hold any files only in ogg, mp3 and aac formats */
13             struct MultimediaFile {
14             MultimediaFile(const char* name, const char* format): name_{name}, format_{format} {}
15             const char* name() const noexcept { return name_; }
16             const char* format() const noexcept { return format_; }
17             private:
18             const char* name_;
19             const char* format_;
20             };
21              
22             struct WAVPlayer {
23             WAVPlayer(double preferred_bitrate): preferred_bitrate_{preferred_bitrate} {}
24             ~WAVPlayer() { std::cout << "~WAVPlayer\n"; }
25             std::string play_wav(WAVFile* file) {
26             std::string result = "wav-player is playing ";
27             result += file->name();
28             result += " with bitrate ";
29             result += std::to_string(preferred_bitrate_);
30             return result;
31             }
32             double preferred_bitrate() const noexcept { return preferred_bitrate_; }
33             WAVPlayer* clone() const noexcept { return new WAVPlayer(preferred_bitrate_); }
34             private:
35             double preferred_bitrate_;
36             };
37              
38             struct MultimediaPlayer {
39             MultimediaPlayer(int quality): quality_{quality} {}
40             ~MultimediaPlayer() { std::cout << "~MultimediaPlayer\n"; }
41             std::string play_file(MultimediaFile* file) {
42             std::string result = "player is playing ";
43             result += file->name();
44             result += " (";
45             result += file->format();
46             result += ")";
47             result += " with quality ";
48             result += std::to_string(quality_);
49             return result;
50             }
51             int quality() const noexcept { return quality_; }
52             MultimediaPlayer* clone() const noexcept { return new MultimediaPlayer(quality_); }
53             private:
54             int quality_;
55             };
56              
57              
58             namespace xs {
59             template <>
60             struct Typemap : TypemapObject {
61             static std::string package () { return "MyTest::Cookbook::WAVFile"; }
62             };
63              
64             template <>
65             struct Typemap : TypemapObject {
66             static std::string package () { return "MyTest::Cookbook::MultimediaFile"; }
67             };
68              
69             template <>
70             struct Typemap : TypemapObject {
71             static std::string package () { return "MyTest::Cookbook::WAVPlayer"; }
72             };
73              
74             template <>
75             struct Typemap : TypemapObject {
76             static std::string package () { return "MyTest::Cookbook::MultimediaPlayer"; }
77             };
78             }
79              
80             MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::WAVFile
81             PROTOTYPES: DISABLE
82              
83 0           void WAVFile::name()
84              
85 0           WAVFile* WAVFile::new(const char* name)
86 0 0          
87 0 0         MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaFile
88             PROTOTYPES: DISABLE
89              
90 0           void MultimediaFile::name()
91              
92 0           void MultimediaFile::format()
93              
94 0           MultimediaFile* MultimediaFile::new(const char* name, const char* format)
95 0 0          
96 0 0         MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::WAVPlayer
97             PROTOTYPES: DISABLE
98              
99 0 0         std::string WAVPlayer::play_wav(WAVFile* file)
    0          
100              
101 0           double WAVPlayer::preferred_bitrate()
102              
103             WAVPlayer* WAVPlayer::clone() {
104 0           Object self{ST(0)};
105 0 0         PROTO = self.stash();
106 0 0         RETVAL = THIS->clone();
107 0           }
108              
109 0           WAVPlayer* WAVPlayer::new(double preferred_bitrate)
110 0 0          
111 0 0         MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaPlayer
112             PROTOTYPES: DISABLE
113              
114             MultimediaPlayer* MultimediaPlayer::new(double preferred_bitrate, int quality) {
115 0           (void)preferred_bitrate; // silence warning
116 0 0         PROTO = Stash::from_name(CLASS).call_next(cv, &ST(1), 1);
117             if (!PROTO.defined()) XSRETURN_UNDEF;
118 0 0         RETVAL = new MultimediaPlayer(quality);
    0          
    0          
119 0 0         }
120 0 0          
121 0 0         std::string MultimediaPlayer::play_file(MultimediaFile* file)
    0          
122              
123 0           int MultimediaPlayer::quality()
124              
125             MultimediaPlayer* MultimediaPlayer::clone() {
126 0           Object self{ST(0)};
127 0 0         PROTO = self.call_next(cv);
128 0 0         RETVAL = THIS->clone();
    0          
129 0           }
130              
131             BOOT {
132 68 50         auto stash = Stash(__PACKAGE__, GV_ADD);
133 34 50         stash.inherit("MyTest::Cookbook::WAVPlayer");
134             }