Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0bb72b6

Browse files
committed
3.1.0
Clean up all `gcc` warnings of the source codes.
1 parent 6f355b9 commit 0bb72b6

File tree

10 files changed

+713
-475
lines changed

10 files changed

+713
-475
lines changed

‎CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
4. Fix a bug caused by the constructor `MpegServer()`.
1414

15-
5. Fix typos in docstrings.
15+
5. Clean up all `gcc` warnings of the source codes.
16+
17+
6. Fix typos in docstrings.
1618

1719
### V3.0.0 update report:
1820

‎MpegCoder/MpegBase.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "stdafx.h"
2+
#include "MpegBase.h"
3+
4+
// Global functions.
5+
const string cmpc::av_make_error_string2_cpp(int errnum) {
6+
char errbuf[AV_ERROR_MAX_STRING_SIZE];
7+
av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
8+
string strerrbuf = errbuf;
9+
return strerrbuf;
10+
}
11+
12+
const string cmpc::av_ts_make_string_cpp(int64_t ts) {
13+
char tsstrbuf[AV_TS_MAX_STRING_SIZE];
14+
av_ts_make_string(tsstrbuf, ts);
15+
string strtsstrbuf = tsstrbuf;
16+
return strtsstrbuf;
17+
}
18+
19+
const string cmpc::av_ts_make_time_string_cpp(int64_t ts, AVRational* tb) {
20+
char tsstrbuf[AV_TS_MAX_STRING_SIZE];
21+
av_ts_make_time_string(tsstrbuf, ts, tb);
22+
string strtsstrbuf = tsstrbuf;
23+
return strtsstrbuf;
24+
}
25+
26+
// CharList implementation.
27+
cmpc::CharList::CharList(void) : data() {
28+
}
29+
30+
cmpc::CharList::CharList(const std::vector<string>& args) : data() {
31+
set(args);
32+
}
33+
34+
cmpc::CharList::CharList(const std::vector<string>&& args) noexcept :
35+
data(args) {
36+
}
37+
38+
cmpc::CharList::~CharList(void) {
39+
clear();
40+
}
41+
42+
cmpc::CharList::CharList(const CharList& ref) : data() {
43+
set(ref.data);
44+
}
45+
46+
cmpc::CharList& cmpc::CharList::operator=(const CharList& ref) {
47+
if (this != &ref) {
48+
set(ref.data);
49+
}
50+
return *this;
51+
}
52+
53+
cmpc::CharList::CharList(CharList&& ref) noexcept :
54+
data(std::move(ref.data)) {
55+
}
56+
57+
cmpc::CharList& cmpc::CharList::operator=(CharList&& ref) noexcept {
58+
if (this != &ref) {
59+
set(std::move(ref.data));
60+
}
61+
return *this;
62+
}
63+
64+
cmpc::CharList& cmpc::CharList::operator=(const std::vector<string>& args) {
65+
set(args);
66+
return *this;
67+
}
68+
69+
cmpc::CharList& cmpc::CharList::operator=(std::vector<string>&& args) noexcept {
70+
set(args);
71+
return *this;
72+
}
73+
74+
void cmpc::CharList::set(const std::vector<string>& args) {
75+
data.clear();
76+
for (auto it = args.begin(); it != args.end(); ++it) {
77+
string new_str(*it);
78+
data.push_back(new_str);
79+
}
80+
}
81+
82+
void cmpc::CharList::set(std::vector<string>&& args) noexcept {
83+
data = args;
84+
}
85+
86+
void cmpc::CharList::clear() {
87+
data.clear();
88+
}
89+
90+
std::shared_ptr<const char*> cmpc::CharList::c_str() {
91+
std::shared_ptr<const char*> pointer(new const char* [data.size() + 1], std::default_delete<const char* []>());
92+
auto p_cur = pointer.get();
93+
for (auto it = data.begin(); it != data.end(); ++it) {
94+
*p_cur = it->c_str();
95+
p_cur++;
96+
}
97+
*p_cur = nullptr;
98+
return pointer;
99+
}
100+

‎MpegCoder/MpegBase.h

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
#include <cstdint>
2323
#include <iostream>
24-
//#include <memory>
2524
#include <string>
2625
#include <functional>
2726
#include <iomanip>
2827
#include <sstream>
2928
#include <fstream>
29+
#include <vector>
30+
#include <memory>
3031
#include <thread>
3132
#include <mutex>
3233
#include <Python.h>
@@ -56,30 +57,15 @@ namespace cmpc {
5657

5758
#ifdef __cplusplus
5859
namespace cmpc {
59-
static const string av_make_error_string2(int errnum) {
60-
char errbuf[AV_ERROR_MAX_STRING_SIZE];
61-
av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
62-
string strerrbuf = errbuf;
63-
return strerrbuf;
64-
}
60+
const string av_make_error_string2_cpp(int errnum);
6561
#undef av_err2str
66-
#define av_err2str(errnum) av_make_error_string2(errnum).c_str()
67-
static const string av_ts_make_string_cpp(int64_t ts) {
68-
char tsstrbuf[AV_TS_MAX_STRING_SIZE];
69-
av_ts_make_string(tsstrbuf, ts);
70-
string strtsstrbuf = tsstrbuf;
71-
return strtsstrbuf;
72-
}
62+
#define av_err2str(errnum) av_make_error_string2_cpp(errnum)
63+
const string av_ts_make_string_cpp(int64_t ts);
7364
#undef av_ts2str
74-
#define av_ts2str(ts) av_ts_make_string_cpp(ts).c_str()
75-
static const string av_ts_make_time_string_cpp(int64_t ts, AVRational* tb) {
76-
char tsstrbuf[AV_TS_MAX_STRING_SIZE];
77-
av_ts_make_time_string(tsstrbuf, ts, tb);
78-
string strtsstrbuf = tsstrbuf;
79-
return strtsstrbuf;
80-
}
65+
#define av_ts2str(ts) av_ts_make_string_cpp(ts)
66+
const string av_ts_make_time_string_cpp(int64_t ts, AVRational* tb);
8167
#undef av_ts2timestr
82-
#define av_ts2timestr(ts, tb) av_ts_make_time_string_cpp(ts, tb).c_str()
68+
#define av_ts2timestr(ts, tb) av_ts_make_time_string_cpp(ts, tb)
8369
}
8470
#endif // __cplusplus
8571

@@ -97,6 +83,27 @@ namespace cmpc {
9783

9884
struct SwsContext* sws_ctx;
9985
} OutputStream;
86+
87+
// A wrapper of the char *[]
88+
class CharList {
89+
public:
90+
CharList(void); // Constructor.
91+
CharList(const std::vector<string>& args); // Copy constructor (string ver).
92+
CharList(const std::vector<string>&& args) noexcept; // Move constructor (string ver).
93+
~CharList(void); // 3-5 law. Destructor.
94+
CharList(const CharList& ref); // Copy constructor.
95+
CharList& operator=(const CharList& ref); // Copy assignment operator.
96+
CharList(CharList&& ref) noexcept; // Move constructor.
97+
CharList& operator=(CharList&& ref) noexcept; // Move assignment operator.
98+
CharList& operator=(const std::vector<string>& args); // Copy assignment operator (string ver).
99+
CharList& operator=(std::vector<string>&& args) noexcept; // Move assignment operator (string ver).
100+
void set(const std::vector<string>& args); // Set strings as data.
101+
void set(std::vector<string>&& args) noexcept; // Set strings as data (move).
102+
void clear(); // clear all data.
103+
std::shared_ptr<const char*> c_str(); // Equivalent conversion for char **
104+
private:
105+
std::vector<string> data;
106+
};
100107
}
101108

102109
// compatibility with newer API

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /