@@ -231,25 +231,41 @@ void StructMeta::copyFrom( const Struct * src, Struct * dest )
231
231
if ( unlikely ( src == dest ) )
232
232
return ;
233
233
234
+ const StructMeta * meta = dest -> meta ();
234
235
if ( dest -> meta () != src -> meta () &&
235
236
!StructMeta::isDerivedType ( src -> meta (), dest -> meta () ) )
237
+ {
238
+ if ( StructMeta::isDerivedType ( dest -> meta (), src -> meta () ) )
239
+ meta = src -> meta ();
240
+ else
241
+ {
236
242
CSP_THROW ( TypeError, " Attempting to copy from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
237
- << " '. copy_from may only be used to copy from same type or derived types" );
243
+ << " '. copy_from may only be used to copy from struct with a common base type" );
244
+ }
245
+ }
238
246
239
- dest -> meta () -> copyFromImpl ( src, dest, false );
247
+ meta -> copyFromImpl ( src, dest, false );
240
248
}
241
249
242
250
void StructMeta::deepcopyFrom ( const Struct * src, Struct * dest )
243
251
{
244
252
if ( unlikely ( src == dest ) )
245
253
return ;
246
254
255
+ const StructMeta * meta = dest -> meta ();
247
256
if ( dest -> meta () != src -> meta () &&
248
257
!StructMeta::isDerivedType ( src -> meta (), dest -> meta () ) )
258
+ {
259
+ if ( StructMeta::isDerivedType ( dest -> meta (), src -> meta () ) )
260
+ meta = src -> meta ();
261
+ else
262
+ {
249
263
CSP_THROW ( TypeError, " Attempting to deepcopy from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
250
- << " '. deepcopy_from may only be used to copy from same type or derived types" );
251
-
252
- dest -> meta () -> copyFromImpl ( src, dest, true );
264
+ << " '. deepcopy_from may only be used to copy from struct with a common base type" );
265
+ }
266
+ }
267
+
268
+ meta -> copyFromImpl ( src, dest, true );
253
269
}
254
270
255
271
void StructMeta::copyFromImpl ( const Struct * src, Struct * dest, bool deepcopy ) const
@@ -291,12 +307,21 @@ void StructMeta::updateFrom( const Struct * src, Struct * dest )
291
307
if ( unlikely ( src == dest ) )
292
308
return ;
293
309
310
+ const StructMeta * meta = dest -> meta ();
311
+
294
312
if ( dest -> meta () != src -> meta () &&
295
313
!StructMeta::isDerivedType ( src -> meta (), dest -> meta () ) )
314
+ {
315
+ if ( StructMeta::isDerivedType ( dest -> meta (), src -> meta () ) )
316
+ meta = src -> meta ();
317
+ else
318
+ {
296
319
CSP_THROW ( TypeError, " Attempting to update from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
297
- << " '. update_from may only be used to update from same type or derived types" );
320
+ << " '. update_from may only be used to update from struct with a common base type" );
321
+ }
322
+ }
298
323
299
- dest -> meta () -> updateFromImpl ( src, dest );
324
+ meta -> updateFromImpl ( src, dest );
300
325
}
301
326
302
327
void StructMeta::updateFromImpl ( const Struct * src, Struct * dest ) const
0 commit comments