Skip to content

Commit f4740ef

Browse files
danieldresser-iejohnhaddon
authored andcommitted
TypedData : Add move constructors
1 parent 9d2d8eb commit f4740ef

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Improvements
1010
- Improved performance when reading materials from instanced prims.
1111
- Added loading of `UsdGeomCube` prims (as MeshPrimitives).
1212
- SceneInterface : Added `_copy` argument to Python bindings for `readAttribute()`, `readTransform()` and `readObject()`. Pass `_copy = False` to receive the original constant result directly instead of a mutable copy. Use with care (typically only for debugging and testing)!
13+
- TypedData : Added move constructors.
1314

1415
Fixes
1516
-----

include/IECore/GeometricTypedData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class IECORE_EXPORT GeometricTypedData : public TypedData<T>
8383
GeometricTypedData();
8484
GeometricTypedData( const ValueType &data );
8585
GeometricTypedData( const ValueType &data, GeometricData::Interpretation interpretation );
86+
GeometricTypedData( ValueType &&data );
87+
GeometricTypedData( ValueType &&data, GeometricData::Interpretation interpretation );
8688

8789
IECORE_RUNTIMETYPED_DECLARETEMPLATE( GeometricTypedData<T>, TypedData<T> );
8890

include/IECore/GeometricTypedData.inl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ GeometricTypedData<T>::GeometricTypedData( const ValueType &data, GeometricData:
5959
{
6060
}
6161

62+
template<class T>
63+
GeometricTypedData<T>::GeometricTypedData( ValueType &&data )
64+
: TypedData<T>( std::move( data ) ), m_interpretation( GeometricData::None )
65+
{
66+
}
67+
68+
template<class T>
69+
GeometricTypedData<T>::GeometricTypedData( ValueType &&data, GeometricData::Interpretation interpretation )
70+
: TypedData<T>( std::move( data ) ), m_interpretation( interpretation )
71+
{
72+
}
73+
6274
template<class T>
6375
GeometricTypedData<T>::~GeometricTypedData()
6476
{

include/IECore/TypedData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class IECORE_EXPORT TypedData : public Data
7171
TypedData();
7272
/// Constructor based on the stored data type.
7373
TypedData(const T &data);
74+
/// Move constructor, to allow efficient construction if the caller
75+
/// uses std::move or calls an in-place constructor for the stored type
76+
TypedData(T &&data);
7477

7578
IECORE_RUNTIMETYPED_DECLARETEMPLATE( TypedData<T>, Data );
7679

include/IECore/TypedData.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ TypedData<T>::TypedData(const T &data) : m_data ( data )
9696
{
9797
}
9898

99+
template<class T>
100+
TypedData<T>::TypedData(T &&data) : m_data ( std::move( data ) )
101+
{
102+
}
103+
99104
template<class T>
100105
TypedData<T>::~TypedData()
101106
{

include/IECore/TypedDataInternals.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class IECORE_EXPORT SimpleDataHolder
5656
{
5757
}
5858

59+
SimpleDataHolder( T &&data )
60+
: m_data( std::move( data ) )
61+
{
62+
}
63+
5964
const T &readable() const
6065
{
6166
return m_data;
@@ -98,6 +103,11 @@ class IECORE_EXPORT SharedDataHolder
98103
{
99104
}
100105

106+
SharedDataHolder( T &&data )
107+
: m_data( new Shareable( std::move( data ) ) )
108+
{
109+
}
110+
101111
const T &readable() const
102112
{
103113
assert( m_data );
@@ -162,6 +172,7 @@ class IECORE_EXPORT SharedDataHolder
162172

163173
Shareable() : data(), hashValid( false ) {}
164174
Shareable( const T &initData ) : data( initData ), hashValid( false ) {}
175+
Shareable( T &&initData ) : data( std::move( initData ) ), hashValid( false ) {}
165176

166177
T data;
167178
MurmurHash hash;

0 commit comments

Comments
 (0)