Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6c91f89

Browse files
author
Clement Champetier
committedJun 10, 2014
Option2D: refactoring
* Rename Option2D by OptionRatio. * Use std::pair<int, int> instead of custom struct Value2D.
1 parent 6d0bde8 commit 6c91f89

File tree

6 files changed

+50
-69
lines changed

6 files changed

+50
-69
lines changed
 

‎app/optionChecker/optionChecker.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <AvTranscoder/Options/OptionDouble.hpp>
66
#include <AvTranscoder/Options/OptionString.hpp>
77
#include <AvTranscoder/Options/OptionBoolean.hpp>
8-
#include <AvTranscoder/Options/Option2D.hpp>
8+
#include <AvTranscoder/Options/OpionRatio.hpp>
99
#include <AvTranscoder/Options/OptionGroup.hpp>
1010
#include <AvTranscoder/Options/OptionChoice.hpp>
1111
#include <AvTranscoder/Option.hpp>
@@ -14,6 +14,7 @@
1414
#include <string>
1515
#include <iostream>
1616
#include <iomanip>
17+
#include <utility> //pair
1718

1819
int optionChecker( const std::string& inputfilename )
1920
{
@@ -81,7 +82,7 @@ int optionChecker( const std::string& inputfilename )
8182
}
8283
case AV_OPT_TYPE_RATIONAL:
8384
{
84-
opt = new avtranscoder::Option2D( *avOption );
85+
opt = new avtranscoder::OpionRatio( *avOption );
8586
break;
8687
}
8788
case AV_OPT_TYPE_BINARY:
@@ -181,7 +182,7 @@ int optionChecker( const std::string& inputfilename )
181182
double valueDouble;
182183
std::string valueStr;
183184
bool valueBool;
184-
avtranscoder::Value2D value2D;
185+
std::pair<int, int> value2D;
185186

186187
if( option->getType() == "OptionInt" )
187188
{
@@ -195,10 +196,10 @@ int optionChecker( const std::string& inputfilename )
195196
{
196197
std::cout << "DefaultValue: " << option->getDefaultValue( valueDouble ) << std::endl;
197198
}
198-
else if( option->getType() == "Option2D" )
199+
else if( option->getType() == "OptionRatio" )
199200
{
200201
option->getDefaultValue( value2D );
201-
std::cout << "DefaultValue: " << value2D.num << ", " << value2D.dem << std::endl;
202+
std::cout << "DefaultValue: " << value2D.first << ", " << value2D.second << std::endl;
202203
}
203204
else if( option->getType() == "OptionString" )
204205
{

‎src/AvTranscoder/Option.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ bool Option::getDefaultValue( bool& value ) const
3333
throw std::runtime_error( "Wrong access to getDefaultValue (bool)." );
3434
}
3535

36-
Value2D& Option::getDefaultValue( Value2D& value ) const
36+
std::pair<int, int>& Option::getDefaultValue( std::pair<int, int>& value ) const
3737
{
38-
throw std::runtime_error( "Wrong access to getDefaultValue (Value2D)." );
38+
throw std::runtime_error( "Wrong access to getDefaultValue (std::pair<int, int>)." );
3939
}
4040

4141
}

‎src/AvTranscoder/Option.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ extern "C" {
1111
#include <vector>
1212
#include <bitset>
1313
#include <string>
14+
#include <utility> //pair
1415

1516
namespace avtranscoder
1617
{
1718

18-
class Value2D;
19-
2019
/**
2120
* @brief Abstract class to wrap AVOption.
2221
* Subclasses implement specific AVOption: int, boolean...
@@ -33,7 +32,7 @@ class Option
3332
virtual double getDefaultValue( double& value ) const;
3433
virtual std::string& getDefaultValue( std::string& value ) const;
3534
virtual bool getDefaultValue( bool& value ) const;
36-
virtual Value2D& getDefaultValue( Value2D& value ) const;
35+
virtual std::pair<int, int>& getDefaultValue( std::pair<int, int>& value ) const;
3736

3837
std::string& getName() { return m_name; }
3938
std::string& getHelp() { return m_help; }

‎src/AvTranscoder/Options/Option2D.cpp renamed to ‎src/AvTranscoder/Options/OpionRatio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "Option2D.hpp"
1+
#include "OpionRatio.hpp"
22

33

44
namespace avtranscoder
55
{
66

7-
Option2D::Option2D( const AVOption& avOption )
7+
OpionRatio::OpionRatio( const AVOption& avOption )
88
: Option( avOption )
99
, m_defaultValue( avOption.default_val.q.num, avOption.default_val.q.den )
1010
, m_minValue( avOption.min )
@@ -13,7 +13,7 @@ Option2D::Option2D( const AVOption& avOption )
1313

1414
}
1515

16-
Option2D::~Option2D()
16+
OpionRatio::~OpionRatio()
1717
{
1818

1919
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef _AV_TRANSCODER_OPTION_2D_HPP
2+
#define _AV_TRANSCODER_OPTION_2D_HPP
3+
4+
#include <AvTranscoder/Option.hpp>
5+
6+
extern "C" {
7+
#ifndef __STDC_CONSTANT_MACROS
8+
#define __STDC_CONSTANT_MACROS
9+
#endif
10+
#include <libavutil/opt.h>
11+
}
12+
13+
namespace avtranscoder
14+
{
15+
16+
/**
17+
* @brief Wrap of AVOption with a type of AV_OPT_TYPE_RATIONAL.
18+
*/
19+
class OpionRatio : public Option
20+
{
21+
public:
22+
OpionRatio( const AVOption& avOption );
23+
24+
~OpionRatio();
25+
26+
std::string getType() const { return "OptionRatio"; }
27+
std::pair<int, int>& getDefaultValue( std::pair<int, int>& defaultValue ) const { return defaultValue = m_defaultValue; }
28+
29+
private:
30+
std::pair<int, int> m_defaultValue;
31+
double m_minValue;
32+
double m_maxValue;
33+
};
34+
35+
}
36+
37+
#endif

‎src/AvTranscoder/Options/Option2D.hpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.