Copy / Clone method for handle and hgsetget class

版本 1.0.0.0 (4.3 KB) 作者: Sebastian Hölz
Enable deep copying of child objects of classes handle or hgsetget
460.0 次下载
更新时间 2012/1/25

查看许可证

The handle or hgsetget classes miss a method to make deep copies of objects. The two classes "handleplus" and "hgsetgetplus" take care of this.

To use these classes, ...
- simply put them somewhere on your Matlab path.
- in classdef-files change instances of
"classdef MyClass < handle" (or hgsetget)
to
"classdef MyClass < handleplus" (or hgsetgetplus)

Suppose you have defined a "MyClass" as child of "handleplus". Deep copies are now created as follows:
>> OBJ = MyClass;
>> OBJ_new = OBJ.copy;

Some short notes:
- This implementation (hopefully) also handles deep copying of inherited private or protected properties (s. discussion "Clone Handle Object - using MATLAB OOP" -> link in acknowledgments).
- It handles properties, which contain handle-objects
- It does not handle cyclic references (s. mathforum.org/kb/message.jspa?messageID=7629086&tstart=0)

Please read the help for these files for more details and report any bugs.

Cheers

Sebastian

引用格式

Sebastian Hölz (2024). Copy / Clone method for handle and hgsetget class (https://www.mathworks.com/matlabcentral/fileexchange/34762-copy-clone-method-for-handle-and-hgsetget-class), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0