Download HDL Coder User`s Guide

Transcript
28
Define New System Objects
Load System Object
This example shows how to load and save a System object.
Load System Object and Child Object
Define a loadObjectImpl method to load a previously saved System object. Within
this method, use the matlab.System.loadObject to load the child System object,
load protected and private properties, load the state if the object is locked, and use
loadObjectImpl from the base class to load public properties.
methods (Access = protected)
function loadObjectImpl(obj,s,wasLocked)
obj.child = matlab.System.loadObject(s.child);
obj.protectedprop = s.protectedprop;
obj.pdependentprop = s.pdependentprop;
if wasLocked
obj.state = s.state;
end
loadObjectImpl@matlab.System(obj,s,wasLocked);
end
end
Complete Class Definition Files with Save and Load
The Counter class definition file sets up an object with a count property. This counter is
used in the MySaveLoader class definition file to count the number of child objects.
classdef Counter < matlab.System
properties(DiscreteState)
Count
end
methods (Access=protected)
function setupImpl(obj, ~)
obj.Count = 0;
end
function y = stepImpl(obj, u)
if u > 0
obj.Count = obj.Count + 1;
end
y = obj.Count;
28-38