Skip to content

Commit c422f4f

Browse files
committed
Separate GetVersion impl, make Pythonic
1 parent c685571 commit c422f4f

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

include/OpenShotVersion.h.in

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,28 @@
4343
#define OPENSHOT_VERSION_SO @PROJECT_SO_VERSION@ /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link)
4444

4545
#include <sstream>
46-
using namespace std;
4746

4847
namespace openshot
4948
{
5049
/// This struct holds version number information. Use the GetVersion() method to access the current version of libopenshot.
5150
struct OpenShotVersion {
52-
int major; /// Major version number
53-
int minor; /// Minor version number
54-
int build; /// Build number
55-
int so; /// Shared Object Number (incremented when API or ABI changes)
51+
static const int Major = OPENSHOT_VERSION_MAJOR; /// Major version number
52+
static const int Minor = OPENSHOT_VERSION_MINOR; /// Minor version number
53+
static const int Build = OPENSHOT_VERSION_BUILD; /// Build number
54+
static const int So = OPENSHOT_VERSION_SO; /// Shared Object Number (incremented when API or ABI changes)
5655

5756
/// Get a string version of the version (i.e. "Major.Minor.Build")
58-
string ToString() {
59-
stringstream version_string;
60-
version_string << major << "." << minor << "." << build;
57+
inline static const std::string ToString() {
58+
std::stringstream version_string;
59+
version_string << Major << "." << Minor << "." << Build;
6160
return version_string.str();
6261
}
6362
};
6463

65-
/// Get the current version number of libopenshot (major, minor, and build number)
66-
static OpenShotVersion GetVersion() {
67-
OpenShotVersion version;
68-
69-
// Set version info
70-
version.major = OPENSHOT_VERSION_MAJOR;
71-
version.minor = OPENSHOT_VERSION_MINOR;
72-
version.build = OPENSHOT_VERSION_BUILD;
73-
version.so = OPENSHOT_VERSION_SO;
64+
static const openshot::OpenShotVersion Version;
7465

75-
return version;
76-
}
66+
/// Get the current version number of libopenshot (major, minor, and build number)
67+
openshot::OpenShotVersion GetVersion();
7768
}
78-
#endif
69+
70+
#endif // OPENSHOT_VERSION_H

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ SET ( OPENSHOT_SOURCE_FILES
249249
Frame.cpp
250250
FrameMapper.cpp
251251
KeyFrame.cpp
252+
OpenShotVersion.cpp
252253
ZmqLogger.cpp
253254
PlayerBase.cpp
254255
Point.cpp

src/OpenShotVersion.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @file
3+
* @brief Source file for GetVersion function
4+
* @author Jonathan Thomas <[email protected]>
5+
* @author FeRD (Frank Dana) <[email protected]>
6+
*
7+
* @ref License
8+
*/
9+
10+
/* LICENSE
11+
*
12+
* Copyright (c) 2008-2019 OpenShot Studios, LLC
13+
* <http://www.openshotstudios.com/>. This file is part of
14+
* OpenShot Library (libopenshot), an open-source project dedicated to
15+
* delivering high quality video editing and animation solutions to the
16+
* world. For more information visit <http://www.openshot.org/>.
17+
*
18+
* OpenShot Library (libopenshot) is free software: you can redistribute it
19+
* and/or modify it under the terms of the GNU Lesser General Public License
20+
* as published by the Free Software Foundation, either version 3 of the
21+
* License, or (at your option) any later version.
22+
*
23+
* OpenShot Library (libopenshot) is distributed in the hope that it will be
24+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
* GNU Lesser General Public License for more details.
27+
*
28+
* You should have received a copy of the GNU Lesser General Public License
29+
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30+
*/
31+
32+
#include "OpenShotVersion.h"
33+
34+
namespace openshot {
35+
OpenShotVersion GetVersion() {
36+
return openshot::Version;
37+
}
38+
}

src/bindings/python/openshot.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
}
121121
}
122122

123+
%extend openshot::OpenShotVersion {
124+
// Give the struct a string representation
125+
const std::string __str__() {
126+
return std::string(openshot::OpenShotVersion::ToString());
127+
}
128+
}
129+
123130
%include "OpenShotVersion.h"
124131
%include "../../../include/ReaderBase.h"
125132
%include "../../../include/WriterBase.h"

0 commit comments

Comments
 (0)