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 %>
92 %> \endcode
93 %>
94 %> \example{Spinner}
95 %> \include{lineno} example/timing/Spinner/main.m
96 %> \output{Spinner}
97 %> \include{lineno} example/timing/Spinner/main.out.m
98 %>
99 %> \final{Spinner}
100 %>
101 %> \author
102 %> \JoshuaOsborne, May 21 2024, 5:43 AM, University of Texas at Arlington<br>
103 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
104 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
105 function self = Spinner()
106 self.tickmarks = '|/-\';
107 self.tickCount = length(self.tickmarks);
108 self.format = [repmat('\b', 1, self.tickCount + 3), '%s'];
109 self.clock = 0;
110 end
111
112 %> \brief
113 %> Rotate the tick mark of the spinner
114 %> and display the percentage value of the input fraction.<br>
115 %> This is a dynamic method of the class [pm.timing.Spinner](@ref Spinner).<br>
116 %>
117 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
118 %> \param[in] fraction : The input scalar MATLAB fractional real (``0 <= fraction <= 1``)
119 %> representing the fraction of work so far accomplished.<br>
120 %>
121 %> \interface{spin}
122 %> \code{.m}
123 %>
124 %> spinner = pm.timing.Spinner()
125 %> spinner.spin(fraction)
126 %>
127 %> \endcode
128 %>
129 %> \final{spin}
130 %>
131 %> \author
132 %> \JoshuaOsborne, May 21 2024, 5:45 AM, University of Texas at Arlington<br>
133 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
134 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
135 function spin(self, fraction)
136 if 0 < self.clock
137 if fraction < 1
138 self.clock = mod(self.clock, self.tickCount) + 1;
139 else
140 self.clock = 1;
141 end
142 fprintf(self.format, [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
143 else
144 self.clock = self.clock + 1;
145 fprintf('%s', [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
146 end
147 %if 1 <= fraction
148 % %fprintf('\b\b\b\b\b');
149 % fprintf('\n');
150 %end
151 end
152
153 end
154
155end
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()
Return a scalar object of class pm.timing.Spinner.
Property tickmarks
Definition: Spinner.m:36