You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fraction: New ctors accept STL container args
This commit is contained in:
@@ -127,6 +127,8 @@
|
||||
|
||||
/* Instantiate the required template specializations */
|
||||
%template() std::map<std::string, int>;
|
||||
%template() std::pair<int, int>;
|
||||
%template() std::vector<int>;
|
||||
|
||||
/* Make openshot.Fraction more Pythonic */
|
||||
%extend openshot::Fraction {
|
||||
|
||||
@@ -29,13 +29,23 @@
|
||||
*/
|
||||
|
||||
#include "Fraction.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace openshot;
|
||||
|
||||
// Constructor
|
||||
Fraction::Fraction() :
|
||||
num(1), den(1) {
|
||||
}
|
||||
// Delegating constructors
|
||||
Fraction::Fraction() : Fraction::Fraction(1, 1) {};
|
||||
|
||||
Fraction::Fraction(std::pair<int, int> pair)
|
||||
: Fraction::Fraction(pair.first, pair.second) {};
|
||||
|
||||
Fraction::Fraction(std::map<std::string, int> mapping)
|
||||
: Fraction::Fraction(mapping["num"], mapping["den"]) {};
|
||||
|
||||
Fraction::Fraction(std::vector<int> vector)
|
||||
: Fraction::Fraction(vector[0], vector[1]) {};
|
||||
|
||||
// Full constructor
|
||||
Fraction::Fraction(int num, int den) :
|
||||
num(num), den(den) {
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
#ifndef OPENSHOT_FRACTION_H
|
||||
#define OPENSHOT_FRACTION_H
|
||||
|
||||
#include <cmath>
|
||||
#include <string> // for std::string
|
||||
#include <utility> // for std::pair
|
||||
#include <map> // for std::map
|
||||
#include <vector> // for std::vector
|
||||
|
||||
namespace openshot {
|
||||
|
||||
@@ -49,9 +52,19 @@ namespace openshot {
|
||||
|
||||
/// Default Constructor
|
||||
Fraction();
|
||||
|
||||
/// Constructor with numerator and denominator
|
||||
Fraction(int num, int den);
|
||||
|
||||
/// Constructor that accepts a (num, den) pair
|
||||
Fraction(std::pair<int, int> pair);
|
||||
|
||||
/// Constructor that takes a vector of length 2 (containing {num, den})
|
||||
Fraction(std::vector<int> vector);
|
||||
|
||||
/// Constructor that takes a key-value mapping (keys: 'num'. 'den')
|
||||
Fraction(std::map<std::string, int> mapping);
|
||||
|
||||
/// Calculate the greatest common denominator
|
||||
int GreatestCommonDenominator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user