Debian Codegraph @

embedded/www/files/critcl_emap.html

raw
1 <!DOCTYPE html><html><head>
2 <meta charset="UTF-8">
3 <meta name="viewport" content="width=device-width, initial-scale=1">
4 <title>critcl::emap - C Runtime In Tcl (CriTcl)</title>
5 <style type="text/css"><!--
6 HTML {
7 background: #FFFFFF;
8 color: black;
9 }
10 BODY {
11 background: #FFFFFF;
12 color: black;
13 }
14 DIV.doctools {
15 margin-left: 10%;
16 margin-right: 10%;
17 }
18 DIV.doctools H1,DIV.doctools H2 {
19 margin-left: -5%;
20 }
21 H1, H2, H3, H4 {
22 margin-top: 1em;
23 font-family: sans-serif;
24 font-size: large;
25 color: #005A9C;
26 background: transparent;
27 text-align: left;
28 }
29 H1.doctools_title {
30 text-align: center;
31 }
32 UL,OL {
33 margin-right: 0em;
34 margin-top: 3pt;
35 margin-bottom: 3pt;
36 }
37 UL LI {
38 list-style: disc;
39 }
40 OL LI {
41 list-style: decimal;
42 }
43 DT {
44 padding-top: 1ex;
45 }
46 UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
47 font: normal 12pt/14pt sans-serif;
48 list-style: none;
49 }
50 LI.doctools_section, LI.doctools_subsection {
51 list-style: none;
52 margin-left: 0em;
53 text-indent: 0em;
54 padding: 0em;
55 }
56 PRE {
57 display: block;
58 font-family: monospace;
59 white-space: pre;
60 margin: 0%;
61 padding-top: 0.5ex;
62 padding-bottom: 0.5ex;
63 padding-left: 1ex;
64 padding-right: 1ex;
65 width: 100%;
66 }
67 PRE.doctools_example {
68 color: black;
69 background: #f5dcb3;
70 border: 1px solid black;
71 }
72 UL.doctools_requirements LI, UL.doctools_syntax LI {
73 list-style: none;
74 margin-left: 0em;
75 text-indent: 0em;
76 padding: 0em;
77 }
78 DIV.doctools_synopsis {
79 color: black;
80 background: #80ffff;
81 border: 1px solid black;
82 font-family: serif;
83 margin-top: 1em;
84 margin-bottom: 1em;
85 }
86 UL.doctools_syntax {
87 margin-top: 1em;
88 border-top: 1px solid black;
89 }
90 UL.doctools_requirements {
91 margin-bottom: 1em;
92 border-bottom: 1px solid black;
93 }
94 --></style>
95 </head>
96 <!-- Generated from file 'critcl_emap.man' by tcllib/doctools with format 'html'
97 -->
98 <!-- Copyright &amp;copy; 2011-2024 Andreas Kupries
99 -->
100 <!-- critcl::emap.n
101 -->
102 <body><hr> [
103 <a href="../toc.html">Table Of Contents</a>
104 &#124; <a href="../index.html">Keyword Index</a>
105 ] <hr>
106 <div class="doctools">
107 <h1 class="doctools_title">critcl::emap(n) 1.3 doc &quot;C Runtime In Tcl (CriTcl)&quot;</h1>
108 <div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
109 <p>critcl::emap - CriTcl - Wrap Support - Enum en- and decoding</p>
110 </div>
111 <div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
112 <ul class="doctools_toc">
113 <li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
114 <li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
115 <li class="doctools_section"><a href="#section1">Description</a></li>
116 <li class="doctools_section"><a href="#section2">API</a></li>
117 <li class="doctools_section"><a href="#section3">Example</a></li>
118 <li class="doctools_section"><a href="#section4">Authors</a></li>
119 <li class="doctools_section"><a href="#section5">Bugs, Ideas, Feedback</a></li>
120 <li class="doctools_section"><a href="#keywords">Keywords</a></li>
121 <li class="doctools_section"><a href="#category">Category</a></li>
122 <li class="doctools_section"><a href="#copyright">Copyright</a></li>
123 </ul>
124 </div>
125 <div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
126 <div class="doctools_synopsis">
127 <ul class="doctools_requirements">
128 <li>package require <b class="pkgname">Tcl 8.6</b></li>
129 <li>package require <b class="pkgname">critcl <span class="opt">?3.2?</span></b></li>
130 <li>package require <b class="pkgname">critcl::emap <span class="opt">?1.3?</span></b></li>
131 </ul>
132 <ul class="doctools_syntax">
133 <li><a href="#1"><b class="cmd">::critcl::emap::def</b> <i class="arg">name</i> <i class="arg">definition</i> <span class="opt">?<b class="option">-nocase</b>?</span> <span class="opt">?<b class="option">-mode</b> <i class="arg">mode</i>?</span></a></li>
134 </ul>
135 </div>
136 </div>
137 <div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
138 <p>Be welcome to the <i class="term">C Runtime In Tcl</i> (short: <i class="term"><a href="critcl.html">CriTcl</a></i>), a system for embedding and using C
139 code from within <a href="http://core.tcl-lang.org/tcl">Tcl</a> scripts.</p>
140 <p>This document is the reference manpage for the
141 <b class="package">critcl::emap</b> package. This package provides convenience
142 commands for advanced functionality built on top of both critcl core
143 and package <b class="package"><a href="critcl_iassoc.html">critcl::iassoc</a></b>.</p>
144 <p>C level libraries often use enumerations or integer values to encode
145 information, like the state of a system. Tcl bindings to such libraries now
146 have the task of converting a Tcl representation, i.e. a string into such
147 state, and back.
148 <em>Note</em> here that the C-level information has to be something which
149 already exists. The package does <em>not</em> create these values. This is
150 in contrast to the package <b class="package"><a href="critcl_enum.html">critcl::enum</a></b> which creates an
151 enumeration based on the specified symbolic names.</p>
152 <p>This package was written to make the declaration and management
153 of such enumerations and their associated conversions functions easy,
154 hiding all attendant complexity from the user.</p>
155 <p>Its intended audience are mainly developers wishing to write
156 Tcl packages with embedded C code.</p>
157 <p>This package resides in the Core Package Layer of CriTcl.</p>
158 <p><img alt="arch_core" src="../image/arch_core.png"></p>
159 </div>
160 <div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2>
161 <dl class="doctools_definitions">
162 <dt><a name="1"><b class="cmd">::critcl::emap::def</b> <i class="arg">name</i> <i class="arg">definition</i> <span class="opt">?<b class="option">-nocase</b>?</span> <span class="opt">?<b class="option">-mode</b> <i class="arg">mode</i>?</span></a></dt>
163 <dd><p>This command defines C functions for the conversion of the <i class="arg">name</i>d
164 state code into a Tcl string, and vice versa.
165 The underlying mapping tables are automatically initialized on first
166 access (if not fully constant), and finalized on interpreter
167 destruction.</p>
168 <p>The <i class="arg">definition</i> dictionary provides the mapping from the
169 Tcl-level symbolic names of the state to their C expressions (often
170 the name of the macro specifying the actual value).
171 <em>Note</em> here that the C-level information has to be something which
172 already exists. The package does <em>not</em> create these values. This is
173 in contrast to the package <b class="package"><a href="critcl_enum.html">critcl::enum</a></b> which creates an
174 enumeration based on the specified symbolic names.</p>
175 <p>Further note that multiple strings can be mapped to the same C
176 expression. When converting to Tcl the first string for the mapping is
177 returned. An important thing to know: If all C expressions are
178 recognizable as integer numbers and their covered range is not too
179 large (at most 50) the package will generate code using direct and
180 fast mapping tables instead of using a linear search.</p>
181 <p>If the option <b class="option">-nocase</b> is specified then the encoder
182 will match strings case-insensitively, and the decoder will always
183 return a lower-case string, regardless of the string's case in the
184 <i class="arg">definition</i>.</p>
185 <p>If the option <b class="option">-mode</b> is specified its contents will
186 interpreted as a list of access modes to support. The two allowed
187 modes are <b class="const">c</b> and <b class="const">tcl</b>. Both modes can be used
188 together. The default mode is <b class="const">tcl</b>.</p>
189 <p>The package generates multiple things (declarations and
190 definitions) with names derived from <i class="arg">name</i>, which has to be a
191 proper C identifier. Some of the things are generated conditional on
192 the chosen <i class="arg">mode</i>s.</p>
193 <dl class="doctools_definitions">
194 <dt><i class="arg">name</i>_encode</dt>
195 <dd><p>The <b class="const">tcl</b>-mode function for encoding a Tcl string into the
196 equivalent state code.
197 Its signature is</p>
198 <pre class="doctools_example">
199 int <i class="arg">name</i>_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result);
200 </pre>
201 <p>The return value of the function is a Tcl error code,
202 i.e. <b class="const">TCL_OK</b>, <b class="const">TCL_ERROR</b>, etc.</p></dd>
203 <dt><i class="arg">name</i>_encode_cstr</dt>
204 <dd><p>The <b class="const">c</b>-mode function for encoding a C string into the
205 equivalent state code.
206 Its signature is</p>
207 <pre class="doctools_example">
208 int <i class="arg">name</i>_encode_cstr (const char* state);
209 </pre>
210 <p>The return value of the function is the encoded state, or -1 if
211 the argument is not a vlaid state.</p></dd>
212 <dt><i class="arg">name</i>_decode</dt>
213 <dd><p>The <b class="const">tcl</b>-mode function for decoding a state code into the
214 equivalent Tcl string.
215 Its signature is</p>
216 <pre class="doctools_example">
217 Tcl_Obj* <i class="arg">name</i>_decode (Tcl_Interp* interp, int state);
218 </pre>
219 </dd>
220 <dt><i class="arg">name</i>_decode_cstr</dt>
221 <dd><p>The <b class="const">c</b>-mode function for decoding a state code into the
222 equivalent C string.
223 Its signature is</p>
224 <pre class="doctools_example">
225 const char* <i class="arg">name</i>_decode_cstr (int state);
226 </pre>
227 <p>The return value of the function is the C string for the state,
228 or <b class="const">NULL</b> if the <i class="arg">state</i> argument does not contain a valid
229 state value.</p></dd>
230 <dt><i class="arg">name</i>.h</dt>
231 <dd><p>A header file containing the declarations for the conversion
232 functions, for use by other parts of the system, if necessary.</p>
233 <p>The generated file is stored in a place where it will not
234 interfere with the overall system outside of the package, yet also be
235 available for easy inclusion by package files (<b class="cmd">csources</b>).</p></dd>
236 <dt><i class="arg">name</i></dt>
237 <dd><p>For mode <b class="const">tcl</b> the command registers a new argument-type for
238 <b class="cmd">critcl::cproc</b> with critcl, encapsulating the encoder function.</p></dd>
239 <dt><i class="arg">name</i></dt>
240 <dd><p>For mode <b class="const">tcl</b> the command registers a new result-type for
241 <b class="cmd">critcl::cproc</b> with critcl, encapsulating the decoder function.</p></dd>
242 </dl></dd>
243 </dl>
244 </div>
245 <div id="section3" class="doctools_section"><h2><a name="section3">Example</a></h2>
246 <p>The example shown below is the specification for the possible modes of
247 entry (normal, no feedback, stars) used by the Tcl binding to the
248 linenoise library.</p>
249 <pre class="doctools_example">
250 package require Tcl 8.6
251 package require critcl 3.2
252 critcl::buildrequirement {
253 package require critcl::emap
254 }
255 critcl::emap::def hiddenmode {
256 no 0 n 0 off 0 false 0 0 0
257 all 1 yes 1 y 1 on 1 true 1 1 1
258 stars 2
259 } -nocase
260 # Declarations: hiddenmode.h
261 # Encoder: int hiddenmode_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result);
262 # Decoder: Tcl_Obj* hiddenmode_decode (Tcl_Interp* interp, int state);
263 # ResultType: hiddenmode
264 # ArgumentType: hiddenmode
265 </pre>
266 </div>
267 <div id="section4" class="doctools_section"><h2><a name="section4">Authors</a></h2>
268 <p>Andreas Kupries</p>
269 </div>
270 <div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2>
271 <p>This document, and the package it describes, will undoubtedly contain
272 bugs and other problems.
273 Please report such at <a href="https://github.com/andreas-kupries/critcl">https://github.com/andreas-kupries/critcl</a>.
274 Please also report any ideas for enhancements you may have for either
275 package and/or documentation.</p>
276 </div>
277 <div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
278 <p><a href="../index.html#c_code">C code</a>, <a href="../index.html#embedded_c_code">Embedded C Code</a>, <a href="../index.html#tcl_interp_association">Tcl Interp Association</a>, <a href="../index.html#bitmask">bitmask</a>, <a href="../index.html#bitset">bitset</a>, <a href="../index.html#code_generator">code generator</a>, <a href="../index.html#compile_run">compile &amp; run</a>, <a href="../index.html#compiler">compiler</a>, <a href="../index.html#dynamic_code_generation">dynamic code generation</a>, <a href="../index.html#dynamic_compilation">dynamic compilation</a>, <a href="../index.html#flags">flags</a>, <a href="../index.html#generate_package">generate package</a>, <a href="../index.html#linker">linker</a>, <a href="../index.html#on_demand_compilation">on demand compilation</a>, <a href="../index.html#on_the_fly_compilation">on-the-fly compilation</a>, <a href="../index.html#singleton">singleton</a></p>
279 </div>
280 <div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
281 <p>Glueing/Embedded C code</p>
282 </div>
283 <div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
284 <p>Copyright &copy; 2011-2024 Andreas Kupries</p>
285 </div>
286 </div></body></html>