📄 node22.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by: Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>3.4.3 Variable Tracing</TITLE><META NAME="description" CONTENT="3.4.3 Variable Tracing"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html"><LINK REL="previous" HREF="node21.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node21.html"><LINK REL="up" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html"><LINK REL="next" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1468" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1462" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1456" HREF="node21.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node21.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1464" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1466" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1469" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html">3.4.4 command Methods: Definition</A><B> Up:</B> <A NAME="tex2html1463" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1457" HREF="node21.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node21.html">3.4.2 Variable Bindings</A>   <B> <A NAME="tex2html1465" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1467" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H2><A NAME="SECTION02143000000000000000"></A><A NAME="sec:VarTrace"></A><BR>3.4.3 Variable Tracing</H2><P>In addition to variable bindings, TclObject also supports tracing ofboth C++ and Tcl instance variables. A traced variable can be createdand configured either in C++ or Tcl. To establish variable tracing atthe Tcl level, the variable must be visible in Tcl, which means that itmust be a bounded C++/Tcl or a pure Tcl instance variable. In addition,the object that owns the traced variable is also required to establishtracing using the Tcl <TT>trace</TT> method of TclObject. The firstargument to the <TT>trace</TT> method must be the name of the variable.The optional second argument specifies the trace object that isresponsible for tracing that variable. If the trace object is notspecified, the object that own the variable is responsible for tracingit.<P>For a TclObject to trace variables, it must extend the C++<TT>trace</TT> method that is virtually defined in TclObject. The Traceclass implements a simple <TT>trace</TT> method, thereby, it can act as ageneric tracer for variables.<P><PRE>class Trace : public Connector { ... virtual void trace(TracedVar*);};</PRE><P>Below is a simple example for setting up variable tracing in Tcl:<P><PRE> # $tcp tracing its own variable cwnd_ $tcp trace cwnd_ # the variable ssthresh_ of $tcp is traced by a generic $tracer set tracer [new Trace/Var] $tcp trace ssthresh_ $tracer</PRE><P>For a C++ variable to be traceable, it must belong to a class thatderives from TracedVar. The virtual base class TracedVar keeps track ofthe variable's name, owner, and tracer. Classes that derives fromTracedVar must implement the virtual method <TT>value</TT>, that takes acharacter buffer as an argument and writes the value of the variableinto that buffer.<P><PRE>class TracedVar { ... virtual char* value(char* buf) = 0;protected: TracedVar(const char* name); const char* name_; // name of the variable TclObject* owner_; // the object that owns this variable TclObject* tracer_; // callback when the variable is changed ...};</PRE><P>The TclCL library exports two classes of TracedVar: <TT>TracedInt</TT> and<TT>TracedDouble</TT>. These classes can be used in place of the basictype int and double respectively. Both TracedInt and TracedDoubleoverload all the operators that can change the value of the variablesuch as assignment, increment, and decrement. These overloadedoperators use the <TT>assign</TT> method to assign the new value to thevariable and call the tracer if the new value is different from the oldone. TracedInt and TracedDouble also implement their <TT>value</TT>methods that output the value of the variable into string. The widthand precision of the output can be pre-specified.<P><HR><!--Navigation Panel--><A NAME="tex2html1468" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1462" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1456" HREF="node21.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node21.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1464" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1466" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1469" HREF="node23.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node23.html">3.4.4 command Methods: Definition</A><B> Up:</B> <A NAME="tex2html1463" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1457" HREF="node21.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node21.html">3.4.2 Variable Bindings</A>   <B> <A NAME="tex2html1465" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1467" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -