| 1 |
|
| MODE: INLINE |
| 2 |
|
| #include <iostream> |
| 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<WAVFile*> : TypemapObject<WAVFile*, WAVFile*, ObjectTypePtr, ObjectStorageMG> { |
| 61 |
|
| static std::string package () { return "MyTest::Cookbook::WAVFile"; } |
| 62 |
|
| }; |
| 63 |
|
| |
| 64 |
|
| template <> |
| 65 |
|
| struct Typemap<MultimediaFile*> : TypemapObject<MultimediaFile*, MultimediaFile*, ObjectTypePtr, ObjectStorageMG> { |
| 66 |
|
| static std::string package () { return "MyTest::Cookbook::MultimediaFile"; } |
| 67 |
|
| }; |
| 68 |
|
| |
| 69 |
|
| template <> |
| 70 |
|
| struct Typemap<WAVPlayer*> : TypemapObject<WAVPlayer*, WAVPlayer*, ObjectTypePtr, ObjectStorageMG> { |
| 71 |
|
| static std::string package () { return "MyTest::Cookbook::WAVPlayer"; } |
| 72 |
|
| }; |
| 73 |
|
| |
| 74 |
|
| template <> |
| 75 |
|
| struct Typemap<MultimediaPlayer*> : TypemapObject<MultimediaPlayer*, MultimediaPlayer*, ObjectTypePtr, ObjectStorageMG> { |
| 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 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 87 |
0 |
▶ | MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaFile |
Branch: 2 branches
| Branch | True | False | Total |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaFile |
0 |
0 |
0 |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaFile |
0 |
0 |
0 |
|
| 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 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 96 |
0 |
▶ | MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::WAVPlayer |
Branch: 2 branches
| Branch | True | False | Total |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::WAVPlayer |
0 |
0 |
0 |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::WAVPlayer |
0 |
0 |
0 |
|
| 97 |
|
| PROTOTYPES: DISABLE |
| 98 |
|
| |
| 99 |
0 |
▶ | std::string WAVPlayer::play_wav(WAVFile* file) |
Branch: 1 branch
| Branch | True | False | Total |
| std::string WAVPlayer::play_wav(WAVFile* file) |
0 |
0 |
0 |
|
| 100 |
|
| |
| 101 |
0 |
| double WAVPlayer::preferred_bitrate() |
| 102 |
|
| |
| 103 |
|
| WAVPlayer* WAVPlayer::clone() { |
| 104 |
0 |
| Object self{ST(0)}; |
| 105 |
0 |
▶ | PROTO = self.stash(); |
Branch: 1 branch
| Branch | True | False | Total |
| PROTO = self.stash(); |
0 |
0 |
0 |
|
| 106 |
0 |
▶ | RETVAL = THIS->clone(); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = THIS->clone(); |
0 |
0 |
0 |
|
| 107 |
0 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
|
| 108 |
|
| |
| 109 |
0 |
| WAVPlayer* WAVPlayer::new(double preferred_bitrate) |
| 110 |
0 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 111 |
0 |
▶ | MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaPlayer |
Branch: 2 branches
| Branch | True | False | Total |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaPlayer |
0 |
0 |
0 |
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::MultimediaPlayer |
0 |
0 |
0 |
|
| 112 |
|
| PROTOTYPES: DISABLE |
| 113 |
|
| |
| 114 |
|
| MultimediaPlayer* MultimediaPlayer::new(double preferred_bitrate, int quality) { |
| 115 |
0 |
| (void)preferred_bitrate; // silence warning |
| 116 |
0 |
▶ | PROTO = Stash::from_name(CLASS).call_next(cv, &ST(1), 1); |
Branch: 1 branch
| Branch | True | False | Total |
| PROTO = Stash::from_name(CLASS).call_next(cv, &ST(1), 1); |
0 |
0 |
0 |
|
| 117 |
|
| if (!PROTO.defined()) XSRETURN_UNDEF; |
| 118 |
0 |
▶ | RETVAL = new MultimediaPlayer(quality); |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = new MultimediaPlayer(quality); |
0 |
0 |
0 |
| RETVAL = new MultimediaPlayer(quality); |
0 |
0 |
0 |
| RETVAL = new MultimediaPlayer(quality); |
0 |
0 |
0 |
|
| 119 |
0 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
| } |
0 |
0 |
0 |
|
| 120 |
0 |
▶ | |
Branch: 2 branches
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
0 |
0 |
0 |
|
| 121 |
0 |
▶ | std::string MultimediaPlayer::play_file(MultimediaFile* file) |
Branch: 1 branch
| Branch | True | False | Total |
| std::string MultimediaPlayer::play_file(MultimediaFile* file) |
0 |
0 |
0 |
|
| 122 |
|
| |
| 123 |
0 |
| int MultimediaPlayer::quality() |
| 124 |
|
| |
| 125 |
|
| MultimediaPlayer* MultimediaPlayer::clone() { |
| 126 |
0 |
| Object self{ST(0)}; |
| 127 |
0 |
▶ | PROTO = self.call_next(cv); |
Branch: 1 branch
| Branch | True | False | Total |
| PROTO = self.call_next(cv); |
0 |
0 |
0 |
|
| 128 |
0 |
▶ | RETVAL = THIS->clone(); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = THIS->clone(); |
0 |
0 |
0 |
| RETVAL = THIS->clone(); |
0 |
0 |
0 |
|
| 129 |
0 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
|
| 130 |
|
| |
| 131 |
|
| BOOT { |
| 132 |
35 |
▶ | auto stash = Stash(__PACKAGE__, GV_ADD); |
Branch: 1 branch
| Branch | True | False | Total |
| auto stash = Stash(__PACKAGE__, GV_ADD); |
35 |
0 |
35 |
|
| 133 |
35 |
▶ | stash.inherit("MyTest::Cookbook::WAVPlayer"); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.inherit("MyTest::Cookbook::WAVPlayer"); |
35 |
0 |
35 |
|
| 134 |
35 |
| } |