ZealOS/docs/Demo/ClassMeta.CC.html
TomAwezome 1b75d91002 Fix Mount AHCI Port selection.
Add arg to SATARep to specify drive types to show.
Add checks in AHCIPortInit to verify port signatures, add helper method to get signatures from port.
2021-08-02 16:40:05 -04:00

113 lines
9.7 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.13">
<style type="text/css">
body {background-color:#fef1f0;}
.cF0{color:#000000;background-color:#fef1f0;}
.cF1{color:#0148a4;background-color:#fef1f0;}
.cF2{color:#3b7901;background-color:#fef1f0;}
.cF3{color:#057c7e;background-color:#fef1f0;}
.cF4{color:#bb2020;background-color:#fef1f0;}
.cF5{color:#9e42ae;background-color:#fef1f0;}
.cF6{color:#b57901;background-color:#fef1f0;}
.cF7{color:#b2b6af;background-color:#fef1f0;}
.cF8{color:#555753;background-color:#fef1f0;}
.cF9{color:#678fbb;background-color:#fef1f0;}
.cFA{color:#82bc49;background-color:#fef1f0;}
.cFB{color:#0097a2;background-color:#fef1f0;}
.cFC{color:#e26a6a;background-color:#fef1f0;}
.cFD{color:#c671bc;background-color:#fef1f0;}
.cFE{color:#c7ab00;background-color:#fef1f0;}
.cFF{color:#fef1f0;background-color:#fef1f0;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF2>/*Demonstrates class meta data.</span><span class=cF0>
<a name="l2"></a></span><span class=cF2>Basically, we make use of the compiler's</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>data about a class. We can add to the</span><span class=cF0>
<a name="l4"></a></span><span class=cF2>compilers data arbitrary items, either string or</span><span class=cF0>
<a name="l5"></a></span><span class=cF2>or int or F64 (if you typecast).</span><span class=cF0>
<a name="l6"></a>
<a name="l7"></a></span><span class=cF2>This stuff is not high performance.</span><span class=cF0>
<a name="l8"></a></span><span class=cF2>Don't get carried away -- it might be slow.</span><span class=cF0>
<a name="l9"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l10"></a>
<a name="l11"></a></span><span class=cF1>U0</span><span class=cF0> RankOut(</span><span class=cF9>I64</span><span class=cF0> i)
<a name="l12"></a>{
<a name="l13"></a> </span><span class=cF6>&quot; %z&quot;</span><span class=cF0>, i, </span><span class=cF6>&quot;Cadet\0Ensign\0Captain\0Admiral\0President\0&quot;</span><span class=cF0>;
<a name="l14"></a>}
<a name="l15"></a>
<a name="l16"></a></span><span class=cF1>class</span><span class=cF0> Test1Struct
<a name="l17"></a>{
<a name="l18"></a> </span><span class=cF9>I64</span><span class=cF0> age print_str </span><span class=cF6>&quot;%2d&quot;</span><span class=cF0> default_val </span><span class=cFE>38</span><span class=cF0>;
<a name="l19"></a> </span><span class=cF9>I64</span><span class=cF0> color default_val </span><span class=cF3>RED</span><span class=cF0>; </span><span class=cF2>//Accepts expressions</span><span class=cF0>
<a name="l20"></a> </span><span class=cF9>I64</span><span class=cF0> rank print_str </span><span class=cF6>&quot;%1d&quot;</span><span class=cF0> default_val </span><span class=cFE>6</span><span class=cF0>/</span><span class=cFE>2</span><span class=cF0> output_fun &amp;RankOut;
<a name="l21"></a>};
<a name="l22"></a>
<a name="l23"></a></span><span class=cF1>class</span><span class=cF0> Test2Struct
<a name="l24"></a>{
<a name="l25"></a> </span><span class=cF9>I64</span><span class=cF0> age print_str </span><span class=cF6>&quot;%2d&quot;</span><span class=cF0> default_val </span><span class=cFE>38</span><span class=cF0> percentile </span><span class=cFE>54</span><span class=cF0>.</span><span class=cFE>20</span><span class=cF0>;
<a name="l26"></a> </span><span class=cF9>I64</span><span class=cF0> rank print_str </span><span class=cF6>&quot;%1d&quot;</span><span class=cF0> default_val </span><span class=cFE>5</span><span class=cF0>;
<a name="l27"></a> </span><span class=cF9>I64</span><span class=cF0> serial_num print_str </span><span class=cF6>&quot;%6d&quot;</span><span class=cF0> default_val </span><span class=cFE>123456</span><span class=cF0>;
<a name="l28"></a>};
<a name="l29"></a>
<a name="l30"></a></span><span class=cF1>U0</span><span class=cF0> DumpStruct(</span><span class=cF1>U8</span><span class=cF0> *_d, </span><span class=cF1>U8</span><span class=cF0> *class_name=</span><span class=cF1>lastclass</span><span class=cF0>)
<a name="l31"></a>{</span><span class=cF2>//lastclass is keyword.</span><span class=cF0> </span><span class=cF2>See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/LastClass.CC.html#l1"><span class=cF4>::/Demo/LastClass.CC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l32"></a> </span><span class=cF9>CHashClass</span><span class=cF0> *tmpc = </span><span class=cF5>HashFind</span><span class=cF0>(class_name, </span><span class=cF5>Fs</span><span class=cF0>-&gt;hash_table, </span><span class=cF3>HTT_CLASS</span><span class=cF0>);
<a name="l33"></a> </span><span class=cF1>U8</span><span class=cF0> *print_str;
<a name="l34"></a> </span><span class=cF9>I64</span><span class=cF0> *q, default_val;
<a name="l35"></a> </span><span class=cF1>U0</span><span class=cF0> (*fp_output_fun)(</span><span class=cF9>I64</span><span class=cF0> i);
<a name="l36"></a> </span><span class=cF1>F64</span><span class=cF0> percentile;
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpc)
<a name="l38"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l39"></a> </span><span class=cF9>CMemberList</span><span class=cF0> *ml;
<a name="l40"></a>
<a name="l41"></a> ml = tmpc-&gt;member_list_and_root;
<a name="l42"></a> </span><span class=cF1>while</span><span class=cF0> (ml)
<a name="l43"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l44"></a> </span><span class=cF6>&quot;%s:&quot;</span><span class=cF0>, ml-&gt;str;
<a name="l45"></a>
<a name="l46"></a> </span><span class=cF2>//All our items are I64's.</span><span class=cF0> </span><span class=cF2>If you want, you can check</span><span class=cF0>
<a name="l47"></a> </span><span class=cF2>//the data type of the member var. See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Debug.CC.html#l216"><span class=cF4>ClassRep</span></a><span class=cF2>().</span><span class=cF0>
<a name="l48"></a> q = _d + ml-&gt;</span><span class=cF1>offset</span><span class=cF0>;
<a name="l49"></a>
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (print_str = </span><span class=cF5>MemberMetaData</span><span class=cF7>(</span><span class=cF6>&quot;print_str&quot;</span><span class=cF0>, ml</span><span class=cF7>)</span><span class=cF0>)
<a name="l51"></a> </span><span class=cF6>&quot;&quot;</span><span class=cF0> print_str, *q;
<a name="l52"></a>
<a name="l53"></a> </span><span class=cF2>//This is slightly ambiguous -- if no meta is present it will return zero.</span><span class=cF0>
<a name="l54"></a> </span><span class=cF1>if</span><span class=cF0> (default_val = </span><span class=cF5>MemberMetaData</span><span class=cF7>(</span><span class=cF6>&quot;default_val&quot;</span><span class=cF0>, ml</span><span class=cF7>)</span><span class=cF0>)
<a name="l55"></a> </span><span class=cF6>&quot; default:%d&quot;</span><span class=cF0>, default_val;
<a name="l56"></a>
<a name="l57"></a> </span><span class=cF2>//This corrects for the ambiguity, allowing zero percentile.</span><span class=cF0>
<a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>MemberMetaFind</span><span class=cF7>(</span><span class=cF6>&quot;percentile&quot;</span><span class=cF0>, ml</span><span class=cF7>)</span><span class=cF0>)
<a name="l59"></a> {</span><span class=cF2>//check if it exists</span><span class=cF0>
<a name="l60"></a> </span><span class=cF2>//We could use the </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l928"><span class=cF4>CMemberListMeta</span></a><span class=cF2> structure returned by</span><span class=cF0>
<a name="l61"></a> </span><span class=cF2>//</span><a href="https://zeal-operating-system.github.io/ZealOS/Compiler/LexLib.CC.html#l64"><span class=cF4>MemberMetaFind</span></a><span class=cF2>() and save a search.</span><span class=cF0>
<a name="l62"></a> percentile = </span><span class=cF5>MemberMetaData</span><span class=cF0>(</span><span class=cF6>&quot;percentile&quot;</span><span class=cF0>, ml)(</span><span class=cF1>F64</span><span class=cF0>);
<a name="l63"></a> </span><span class=cF6>&quot; percentile: %5.2f&quot;</span><span class=cF0>, percentile;
<a name="l64"></a> }
<a name="l65"></a>
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (fp_output_fun = </span><span class=cF5>MemberMetaData</span><span class=cF7>(</span><span class=cF6>&quot;output_fun&quot;</span><span class=cF0>, ml</span><span class=cF7>)</span><span class=cF0>)
<a name="l67"></a> (*fp_output_fun)(*q);
<a name="l68"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l69"></a> ml = ml-&gt;next;
<a name="l70"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l71"></a>}
<a name="l72"></a>
<a name="l73"></a>Test1Struct t1;
<a name="l74"></a>t1.age = </span><span class=cFE>44</span><span class=cF0>;
<a name="l75"></a>t1.rank = </span><span class=cFE>3</span><span class=cF0>;
<a name="l76"></a>
<a name="l77"></a>DumpStruct(&amp;t1);
<a name="l78"></a>
<a name="l79"></a>Test2Struct t2;
<a name="l80"></a>t2.age = </span><span class=cFE>22</span><span class=cF0>;
<a name="l81"></a>t2.rank = </span><span class=cFE>2</span><span class=cF0>;
<a name="l82"></a>t2.serial_num = </span><span class=cFE>55555</span><span class=cF0>;
<a name="l83"></a>
<a name="l84"></a>DumpStruct(&amp;t2);
</span></pre></body>
</html>