ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
Spinner.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for generating objects
3%> that can display the time spinner on the console.<br>
4%>
5%> \devnote
6%> The ``handle`` superclass is essential to allow
7%> object modification by the object methods.<br>
8%>
9%> \note
10%> See the documentation of the class constructor.<br>
11%>
12%> \note
13%> See below for information on the attributes (properties).<br>
14%>
15%> \note
16%> See below for information on the methods.<br>
17%>
18%> \final
19%>
20%> \author
21%> \JoshuaOsborne, May 21 2024, 5:39 AM, University of Texas at Arlington<br>
22%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
23%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
24classdef Spinner < pm.matlab.Handle
25
26 properties(Access = protected)
27 %>
28 %> ``tickmarks``
29 %>
30 %> The MATLAB ``char`` vector containing the set of
31 %> characters that represent the passage of time in the spinner.
32 %>
33 tickmarks = '|/-\';
34 end
35
36 properties(Hidden)
37 %>
38 %> ``tickCount``
39 %>
40 %> The MATLAB integer containing the length of ``tickmarks``.
41 %>
42 %> \warning
43 %> This is an internal ``Hidden`` class attribute
44 %> that is inaccessible to the end users.<br>
45 %>
46 tickCount = 4;
47 %>
48 %> ``format``
49 %>
50 %> The MATLAB ``char`` vector containing the spinner display format.
51 %>
52 %> \warning
53 %> This is an internal ``Hidden`` class attribute
54 %> that is inaccessible to the end users.<br>
55 %>
56 format = [repmat('\b', 1, 4 + 1), '%s'];
57 %>
58 %> ``clock``
59 %>
60 %> The scalar integer representing the index of the ``tickmarks`` attribute.
61 %>
62 %> \warning
63 %> This is an internal ``Hidden`` class attribute
64 %> that is inaccessible to the end users.<br>
65 %>
66 clock = 0;
67 end
68
69
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
72 methods(Access = public)
73
74 %> \brief
75 %> Return a scalar object of class [pm.timing.Spinner](@ref Spinner).<br>
76 %>
77 %> \details
78 %> This is the constructor of the class [pm.timing.Spinner](@ref Spinner).<br>
79 %>
80 %> \param[in] tickmarks : The input MATLAB ``char`` vector containing the set of
81 %> characters that represent the passage of time in the spinner.<br>
82 %> (**optional**, default = ``'|/-\'``)
83 %>
84 %> \return
85 %> ``self`` : The output scalar object of class [pm.timing.Spinner](@ref Spinner).<br>
86 %>
87 %> \interface{Spinner}
88 %> \code{.m}
89 %>
90 %> self = pm.timing.Spinner()
91 %> self = pm.timing.Spinner(tickmarks)
92 %>
93 %> \endcode
94 %>
95 %> \example{Spinner}
96 %> \include{lineno} example/timing/Spinner/main.m
97 %> \output{Spinner}
98 %> \include{lineno} example/timing/Spinner/main.out.m
99 %>
100 %> \final{Spinner}
101 %>
102 %> \author
103 %> \JoshuaOsborne, May 21 2024, 5:43 AM, University of Texas at Arlington<br>
104 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
105 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
106 function self = Spinner(tickmarks)
107 if nargin < 1
108 tickmarks = '|/-\';
109 end
110 self.tickmarks = tickmarks;
111 self.tickCount = length(self.tickmarks);
112 self.format = [repmat('\b', 1, self.tickCount + 3), '%s'];
113 self.clock = 0;
114 end
115
116 %> \brief
117 %> Rotate the tick mark of the spinner
118 %> and display the percentage value of the input fraction.<br>
119 %> This is a dynamic method of the class [pm.timing.Spinner](@ref Spinner).<br>
120 %>
121 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
122 %> \param[in] fraction : The input scalar MATLAB fractional real (``0 <= fraction <= 1``)
123 %> representing the fraction of work so far accomplished.<br>
124 %>
125 %> \interface{spin}
126 %> \code{.m}
127 %>
128 %> spinner = pm.timing.Spinner()
129 %> spinner.spin(fraction)
130 %>
131 %> \endcode
132 %>
133 %> \final{spin}
134 %>
135 %> \author
136 %> \JoshuaOsborne, May 21 2024, 5:45 AM, University of Texas at Arlington<br>
137 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
138 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
139 function spin(self, fraction)
140 if 0 < self.clock
141 if fraction < 1
142 self.clock = mod(self.clock, self.tickCount) + 1;
143 else
144 self.clock = 1;
145 end
146 fprintf(self.format, [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
147 else
148 self.clock = self.clock + 1;
149 fprintf('%s', [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
150 end
151 %if 1 <= fraction
152 % %fprintf('\b\b\b\b\b');
153 % fprintf('\n');
154 %end
155 end
156
157 end
158
159end
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...
Definition: Handle.m:24
This is the base class for generating objects that can display the time spinner on the console.
Definition: Spinner.m:25
Property format
Definition: Spinner.m:61
function spin(in self, in fraction)
Rotate the tick mark of the spinner and display the percentage value of the input fraction....
Property clock
Definition: Spinner.m:72
Property tickCount
Definition: Spinner.m:50
function Spinner(in tickmarks)
Return a scalar object of class pm.timing.Spinner.
Property tickmarks
Definition: Spinner.m:36