FData optimization

This commit is contained in:
Markus Gans 2020-09-18 22:40:51 +02:00
parent 5092244b81
commit ff2e29b246
4 changed files with 54 additions and 75 deletions

View File

@ -51,7 +51,7 @@ void doubleToItem ( FListBoxItem& item
, std::size_t index ) , std::size_t index )
{ {
typedef std::list<double> DblList; typedef std::list<double> DblList;
DblList& dbl_list = FListBoxHelper::getContainer<DblList>(container); DblList& dbl_list = flistboxhelper::getContainer<DblList>(container);
std::list<double>::iterator iter = dbl_list.begin(); std::list<double>::iterator iter = dbl_list.begin();
std::advance (iter, index); std::advance (iter, index);
item.setText (FString() << *iter); item.setText (FString() << *iter);

View File

@ -834,7 +834,7 @@ void FListBox::drawList()
const bool lineHasBrackets = hasBrackets(iter); const bool lineHasBrackets = hasBrackets(iter);
// Import data via lazy conversion // Import data via lazy conversion
lazyConvert (iter, int(y)); lazyConvert (iter, y);
// Set screen position and attributes // Set screen position and attributes
setLineAttributes ( int(y), isSelected(iter), lineHasBrackets setLineAttributes ( int(y), isSelected(iter), lineHasBrackets

View File

@ -51,13 +51,11 @@ namespace finalcut
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template <typename T> template <typename T>
struct FData; // Class forward declaration class FData; // Class forward declaration
struct FDataAccess class FDataAccess
{ {
public: public:
virtual ~FDataAccess();
template <typename T> template <typename T>
const T& get() const const T& get() const
{ {
@ -72,94 +70,75 @@ struct FDataAccess
} }
}; };
//----------------------------------------------------------------------
inline FDataAccess::~FDataAccess()
{ }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// struct FData // struct FData
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template <typename T> template <typename T>
struct FData : public FDataAccess class FData : public FDataAccess
{ {
explicit FData (T& v) // constructor public:
: value_ref{v} explicit FData (T& v) // constructor
{ } : value_ref{v}
{ }
explicit FData (T&& v) // constructor explicit FData (T&& v) // constructor
: value{v} : value{std::move(v)}
, value_ref{value} , value_ref{value}
{ } { }
~FData() // destructor T operator () () const
{ } {
return value_ref;
}
FData (const FData& d) // Copy constructor template <typename... Args>
: value{d.value} T operator () (Args... args) const
, value_ref{d.value_ref} {
{ } return value_ref(args...);
}
FData& operator = (const FData& d) // Copy assignment operator (=) explicit operator T () const
{ {
value = d.value; return value_ref;
value_ref = d.value_ref; }
return *this;
}
T operator () () const T& get()
{ {
return value_ref; return value_ref;
} }
template <typename... Args> void set (const T& v)
T operator () (Args... args) const {
{ value_ref = v;
return value_ref(args...); }
}
explicit operator T () const bool isInitializedCopy()
{ {
return value_ref; return bool(value);
} }
T& get() bool isInitializedReference()
{ {
return value_ref; return ! isInitializedCopy();
} }
void set (const T& v) FData& operator << (const T& v)
{ {
value_ref = v; value_ref = v;
} return *this;
}
bool isInitializedCopy() friend std::ostream& operator << (std::ostream &os, const FData& data)
{ {
return bool(value); os << data.value_ref;
} return os;
}
bool isInitializedReference()
{
return ! isInitializedCopy();
}
FData& operator << (const T& v)
{
value_ref = v;
return *this;
}
friend std::ostream& operator << (std::ostream &os, const FData& data)
{
os << data.value_ref;
return os;
}
private: private:
// Data members
T value{}; T value{};
public:
T& value_ref; T& value_ref;
}; };

View File

@ -371,7 +371,7 @@ class FListBox : public FWidget
// non-member function // non-member function
//---------------------------------------------------------------------- //----------------------------------------------------------------------
namespace FListBoxHelper namespace flistboxhelper
{ {
template <typename Container> template <typename Container>