www.gusucode.com > ros 工具箱 matlab源码程序 > ros/+robotics/+ros/+msg/+internal/+gen/CacheGenerator.m
classdef CacheGenerator < robotics.ros.msg.internal.gen.PrimitiveGenerator %This class is for internal use only. It may be removed in the future. %CacheGenerator Generate the cache property % Copyright 2014 The MathWorks, Inc. properties (SetAccess = private) %Properties - The names of all cached properties % This is a cell array of strings Properties = {} end methods function obj = CacheGenerator(className, compNames) %CacheGenerator Constructor obj@robotics.ros.msg.internal.gen.PrimitiveGenerator(className); % Generate valid names from the input for i = 1:length(compNames) obj.Properties{end+1} = obj.makeValidName(compNames{i}); end end function addCode(obj, classGenerator) %addCode Add code for cache property if isempty(obj.Properties) return; end % Add the cache property propDef = classGenerator.addProperty('Cache'); propDef.Attributes = {'Access = protected'}; propDef.H1Line = 'The cache for fast data access'; value = ['''' obj.Properties{1} ''', []']; for i = 2:length(obj.Properties) value = [value, ', ''', obj.Properties{i} ''', []']; %#ok<AGROW> end propDef.InitValue = ['struct(', value, ')']; % Add a method for resetting the cache resetMethod = sigutils.internal.emission.MatlabMethodGenerator('resetCache'); resetMethod.AlignEndOfLineComments = false; resetMethod.H1Line = 'Resets any cached properties'; resetMethod.Attributes = {'Access = protected'}; resetMethod.InputArgs = {'obj'}; resetMethod.RCSRevisionAndDate = false; resetMethod.TimeStampInHeader = false; for i = 1:length(obj.Properties) resetMethod.addCode(['obj.Cache.' obj.Properties{i} ' = [];']); end classGenerator.addMethod( resetMethod ); end end end