| 1 |
<!DOCTYPE html><html><head> |
| 2 |
<meta charset="UTF-8"> |
| 3 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 4 |
<title>critcl::enum - 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_enum.man' by tcllib/doctools with format 'html' |
| 97 |
--> |
| 98 |
<!-- Copyright &copy; 2011-2024 Andreas Kupries |
| 99 |
--> |
| 100 |
<!-- critcl::enum.n |
| 101 |
--> |
| 102 |
<body><hr> [ |
| 103 |
<a href="../toc.html">Table Of Contents</a> |
| 104 |
| <a href="../index.html">Keyword Index</a> |
| 105 |
] <hr> |
| 106 |
<div class="doctools"> |
| 107 |
<h1 class="doctools_title">critcl::enum(n) 1.2 doc "C Runtime In Tcl (CriTcl)"</h1> |
| 108 |
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2> |
| 109 |
<p>critcl::enum - CriTcl - Wrap Support - String/Integer mapping</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::enum <span class="opt">?1.2?</span></b></li> |
| 131 |
</ul> |
| 132 |
<ul class="doctools_syntax"> |
| 133 |
<li><a href="#1"><b class="cmd">::critcl::enum::def</b> <i class="arg">name</i> <i class="arg">definition</i> <span class="opt">?<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::enum</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_literals.html">critcl::literals</a></b>.</p> |
| 144 |
<p>It is an extended form of string pool which not only converts |
| 145 |
integer values into Tcl-level strings, but also handles the reverse |
| 146 |
direction, converting from strings to the associated integer values.</p> |
| 147 |
<p>It essentially provides a bi-directional mapping between a C |
| 148 |
enumeration type and a set of strings, one per enumeration value. |
| 149 |
<em>Note</em> that the C enumeration in question is created by the |
| 150 |
definition. It is not possible to use the symbols of an existing |
| 151 |
enumeration type.</p> |
| 152 |
<p>This package was written to make the declaration and management |
| 153 |
of such mappings easy. It uses a string pool for one of the directions, |
| 154 |
using its ability to return shared literals and conserve memory.</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::enum::def</b> <i class="arg">name</i> <i class="arg">definition</i> <span class="opt">?<i class="arg">mode</i>?</span></a></dt> |
| 163 |
<dd><p>This command defines two C functions for the conversion between |
| 164 |
C values and Tcl_Obj'ects, with named derived from <i class="arg">name</i>.</p> |
| 165 |
<p>The <i class="arg">definition</i> dictionary provides the mapping from the |
| 166 |
specified C-level symbolic names to the strings themselves.</p> |
| 167 |
<p>The <i class="arg">mode</i>-list configures the output somewhat. |
| 168 |
The two allowed modes are <b class="const">+list</b> and <b class="const">tcl</b>. |
| 169 |
All modes can be used together. |
| 170 |
The default mode is <b class="const">tcl</b>. |
| 171 |
Using mode <b class="const">+list</b> implies <b class="const">tcl</b> as well.</p> |
| 172 |
<p>For mode <b class="const">tcl</b> the new function has two arguments, a |
| 173 |
<b class="type">Tcl_Interp*</b> pointer refering to the interpreter holding the |
| 174 |
string pool, and a code of type "<i class="arg">name</i>_pool_names" (see below), |
| 175 |
the symbolic name of the string to return. The result of the function |
| 176 |
is a <b class="type">Tcl_Obj*</b> pointer to the requested string constant.</p> |
| 177 |
<p>For mode <b class="const">+list</b> all of <b class="const">tcl</b> applies, plus an |
| 178 |
additional function is generated which takes three arguments, in |
| 179 |
order: a <b class="type">Tcl_Interp*</b> pointer refering to the interpreter |
| 180 |
holding the string pool, an <b class="type">int</b> holding the size of the last |
| 181 |
argument, and an array of type "<i class="arg">name</i>_pool_names" holding the |
| 182 |
codes (see below), the symbolic names of the strings to return. The |
| 183 |
result of the function is a <b class="type">Tcl_Obj*</b> pointer to a Tcl list |
| 184 |
holding the requested string constants.</p> |
| 185 |
<p>The underlying string pool is automatically initialized on |
| 186 |
first access, and finalized on interpreter destruction.</p> |
| 187 |
<p>The package generates multiple things (declarations and |
| 188 |
definitions) with names derived from <i class="arg">name</i>, which has to be a |
| 189 |
proper C identifier.</p> |
| 190 |
<dl class="doctools_definitions"> |
| 191 |
<dt><i class="arg">name</i>_pool_names</dt> |
| 192 |
<dd><p>The C enumeration type containing the specified symbolic names.</p></dd> |
| 193 |
<dt><i class="arg">name</i>_ToObj</dt> |
| 194 |
<dd><p>The function converting from integer value to Tcl string. |
| 195 |
Its signature is</p> |
| 196 |
<pre class="doctools_example"> |
| 197 |
Tcl_Obj* <i class="arg">name</i>_ToObj (Tcl_Interp* interp, <i class="arg">name</i>_names literal); |
| 198 |
</pre> |
| 199 |
</dd> |
| 200 |
<dt><i class="arg">name</i>_ToObjList</dt> |
| 201 |
<dd><p>The mode <b class="const">+list</b> function converting from integer array to Tcl |
| 202 |
list of strings. |
| 203 |
Its signature is</p> |
| 204 |
<pre class="doctools_example"> |
| 205 |
Tcl_Obj* <i class="arg">name</i>_ToObjList (Tcl_Interp* interp, int c, <i class="arg">name</i>_names* literal); |
| 206 |
</pre> |
| 207 |
</dd> |
| 208 |
<dt><i class="arg">name</i>_GetFromObj</dt> |
| 209 |
<dd><p>The function converting from Tcl string to integer value. |
| 210 |
Its signature is</p> |
| 211 |
<pre class="doctools_example"> |
| 212 |
int <i class="arg">name</i>_GetFromObj (Tcl_Interp* interp, Tcl_Obj* obj, int flags, int* literal); |
| 213 |
</pre> |
| 214 |
<p>The <i class="arg">flags</i> are like for <b class="function">Tcl_GetIndexFromObj</b>.</p></dd> |
| 215 |
<dt><i class="arg">name</i>.h</dt> |
| 216 |
<dd><p>A header file containing the declarations for the converter functions, |
| 217 |
for use by other parts of the system, if necessary.</p> |
| 218 |
<p>The generated file is stored in a place where it will not |
| 219 |
interfere with the overall system outside of the package, yet also be |
| 220 |
available for easy inclusion by package files (<b class="cmd">csources</b>).</p></dd> |
| 221 |
<dt><i class="arg">name</i></dt> |
| 222 |
<dd><p>At the level of critcl itself the command registers a new result-type |
| 223 |
for <b class="cmd">critcl::cproc</b>, which takes an integer result from the function |
| 224 |
and converts it to the equivalent string in the pool for the script.</p></dd> |
| 225 |
<dt><i class="arg">name</i></dt> |
| 226 |
<dd><p>At the level of critcl itself the command registers a new argument-type |
| 227 |
for <b class="cmd">critcl::cproc</b>, which takes a Tcl string and converts it to the |
| 228 |
equivalent integer for delivery to the function.</p></dd> |
| 229 |
</dl></dd> |
| 230 |
</dl> |
| 231 |
</div> |
| 232 |
<div id="section3" class="doctools_section"><h2><a name="section3">Example</a></h2> |
| 233 |
<p>The example shown below is the specification for a set of actions, methods, |
| 234 |
and the like, a function may take as argument.</p> |
| 235 |
<pre class="doctools_example"> |
| 236 |
package require Tcl 8.6 |
| 237 |
package require critcl 3.2 |
| 238 |
critcl::buildrequirement { |
| 239 |
package require critcl::enum |
| 240 |
} |
| 241 |
critcl::enum::def action { |
| 242 |
w_create "create" |
| 243 |
w_directory "directory" |
| 244 |
w_events "events" |
| 245 |
w_file "file" |
| 246 |
w_handler "handler" |
| 247 |
w_remove "remove" |
| 248 |
} |
| 249 |
# Declarations: action.h |
| 250 |
# Type: action_names |
| 251 |
# Accessor: Tcl_Obj* action_ToObj (Tcl_Interp* interp, int literal); |
| 252 |
# Accessor: int action_GetFromObj (Tcl_Interp* interp, Tcl_Obj* o, int flags, int* literal); |
| 253 |
# ResultType: action |
| 254 |
# ArgType: action |
| 255 |
</pre> |
| 256 |
</div> |
| 257 |
<div id="section4" class="doctools_section"><h2><a name="section4">Authors</a></h2> |
| 258 |
<p>Andreas Kupries</p> |
| 259 |
</div> |
| 260 |
<div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2> |
| 261 |
<p>This document, and the package it describes, will undoubtedly contain |
| 262 |
bugs and other problems. |
| 263 |
Please report such at <a href="https://github.com/andreas-kupries/critcl">https://github.com/andreas-kupries/critcl</a>. |
| 264 |
Please also report any ideas for enhancements you may have for either |
| 265 |
package and/or documentation.</p> |
| 266 |
</div> |
| 267 |
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2> |
| 268 |
<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#code_generator">code generator</a>, <a href="../index.html#compile_run">compile & run</a>, <a href="../index.html#compiler">compiler</a>, <a href="../index.html#conversion">conversion</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#generate_package">generate package</a>, <a href="../index.html#int_to_string_mapping">int to string mapping</a>, <a href="../index.html#linker">linker</a>, <a href="../index.html#literal_pool">literal pool</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>, <a href="../index.html#string_pool">string pool</a>, <a href="../index.html#string_to_int_mapping">string to int mapping</a></p> |
| 269 |
</div> |
| 270 |
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2> |
| 271 |
<p>Glueing/Embedded C code</p> |
| 272 |
</div> |
| 273 |
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2> |
| 274 |
<p>Copyright © 2011-2024 Andreas Kupries</p> |
| 275 |
</div> |
| 276 |
</div></body></html> |