⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node21.html

📁 相关搜索: ns2仿真结果分析 all-awk ns2 ns2 无限网络中awk文件 ... [2.tcl.rar] - 在ns2平台上实现对AODV协议的模拟
💻 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.2 Variable Bindings</TITLE><META NAME="description" CONTENT="3.4.2 Variable Bindings"><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="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><LINK REL="previous" HREF="node18.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node18.html"><LINK REL="up" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html"><LINK REL="next" HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1454"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1448"  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="tex2html1442"  HREF="node20.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node20.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1450"  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="tex2html1452"  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="tex2html1455"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html">3.4.3 Variable Tracing</A><B> Up:</B> <A NAME="tex2html1449"  HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1443"  HREF="node20.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node20.html">3.4.1.0.2 Deletion of TclObjects</A> &nbsp <B>  <A NAME="tex2html1451"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html1453"  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="SECTION02142000000000000000"></A><A NAME="sec:VarBinds"></A><BR>3.4.2 Variable Bindings</H2><P>In most cases,access to compiled member variables is restricted to compiled code,and access to interpreted member variables is likewiseconfined to access via interpreted code;however, it is possible to establish bi-directional bindingssuch that both the interpreted member variableand the compiled member variable access the same data, and changing the value of either variablechanges the value of the corresponding paired variable to same value.<P>The binding is established by the compiled constructorwhen that object is instantiated;it is automatically accessible by the interpreted object as an instance variable. supports five different data types: reals, bandwidth valued variables, time valued variables, integers, and booleans.The syntax of how these values can be specified in OTcl is differentfor each variable type.<UL><LI>Real and Integer valued variables are specified in the ``normal'' form.        For example,        <PRE>        \$object set realvar 1.2e3        \$object set intvar  12</PRE></LI><LI>Bandwidth is specified as a real value, optionally  suffixed by a `k' or `K' to mean kilo-quantities, or `m' or `M' to  mean mega-quantities.  A final optional suffix of `B' indicates that the quantity expressed  is in Bytes per second.  The default is bandwidth expressed in bits per second.        For example, all of the following are equivalent:        <PRE>        \$object set bwvar 1.5m        \$object set bwvar 1.5mb        \$object set bwvar 1500k        \$object set bwvar 1500kb        \$object set bwvar .1875MB        \$object set bwvar 187.5kB        \\$object set bwvar 1.5e6</PRE><P></LI><LI>Time is specified as a real value, optionally suffixed by a  `m' to express time in milli-seconds, `n' to express time in  nano-seconds, or `p' to express time in pico-seconds.  The default is time expressed in seconds.        For example, all of the following are equivalent:        <PRE>        \$object set timevar 1500m        \$object set timevar 1.5        \$object set timevar 1.5e9n        \$object set timevar 1500e9p</PRE>  Note that we can also safely add a  to reflect the time unit of seconds.   will ignore anything other than a valid real number specification,  or a trailing `m', `n', or `p'.<P></LI><LI>Booleans can be expressed either as an integer, or as `T' or `t'  for true.  Subsequent characters after the first letter are ignored.  If the value is neither an integer, nor a true value,  then it is assumed to be false.        For example,        <PRE>        \\$object set boolvar t           # set to true;        \\$object set boolvar true        \\$object set boolvar 1   # or any non-zero value;        \\$object set boolvar false       # set to false;        \\$object set boolvar junk                \\$object set boolvar 0</PRE><P></LI></UL><P>The following example shows the constructor for the ASRMAgent<A NAME="tex2html7"  HREF="footnode.html#foot463" tppabs="http://www.isi.edu/nsnam/ns/doc/footnode.html#foot463"><SUP>3.3</SUP></A>.<PRE>        ASRMAgent::ASRMAgent() {                bind("pdistance_", &amp;pdistance_);      /* real variable /                bind("requestor_", &amp;requestor_);      /* integer variable /                bind_time("lastSent_", &amp;lastSessSent_); /* time variable /                bind_bw("ctrlLimit_", &amp;ctrlBWLimit_); /* bandwidth variable /                bind_bool("running_", &amp;running_);     /* boolean variable /        }</PRE>Note that all of the functions above take two arguments,the name of an OTcl variable,and the address of the corresponding compiled member variablethat is linked.While it is often the case that these bindings are establishedby the constructor of the object, it need not always be done in this manner.We will discuss such alternate methodswhen we describe the class InstVarSectionsec:InstVarin detail later.<P>Each of the variables that is bound is automatically initialisedwith default values when the object is created.The default values are specified as interpreted class variables.This initialisation is done by the routing []init-instvar,invoked by methods in the class Instvar,described laterSectionsec:InstVar.[]init-instvar checks the class of the interpreted object,and all of the parent class of that object, to find the firstclass in which the variable is defined.It uses the value of the variable in that class to initialise the object.Most of the bind initialisation values are defined intcl/lib/ns-default.tcl.<P>For example, if the following class variables are defined for the ASRMAgent:<PRE>        Agent/SRM/Adaptive set pdistance_ 15.0        Agent/SRM set pdistance_ 10.0        Agent/SRM set lastSent_ 8.345m        Agent set ctrlLimit_    1.44M        Agent/SRM/Adaptive set running_ f</PRE>Therefore, every new Agent/SRM/Adaptive object will have<TT>pdistance_</TT> set to 15.0;<TT>lastSent_</TT> is set to 8.345mfrom the setting of the class variable of the parent class;<TT>ctrlLimit_</TT> is set to 1.44Musing the class variable of the parent class twice removed;<TT>running</TT> is set to false;the instance variable <TT>pdistance_</TT> is not initialised,because no class variableexists in any of the class hierarchy of the interpreted object.In such instance, []init-instvar will invoke []warn-instvar, to print out a warning about such a variable.The user can selectively override this procedurein their simulation scripts, to elide this warning.<P>Note that the actual bindingis done by instantiating objects in the class InstVar.Each object in the class InstVar binds one compiled member variable to one interpreted member variable.A TclObject stores a list of InstVar objects correspondingto each of its member variable that is bound in this fashion.The head of this list is stored in its member variable<TT>instvar_</TT> of the TclObject.<P>One last point to consider is that will guarantee that the actual valuesof the variable, both in the interpreted object and the compiled object,will be identical at all times.However, if there are methods and other variablesof the compiled object that track the value of this variable,they must be explicitly invoked or changed whenever thevalue of this variable is changed.This usually requires additional primitives that the user should invoke.One way of providing such primitives in  is throughthe []command method described in the next section.<P><HR><!--Navigation Panel--><A NAME="tex2html1454"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1448"  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="tex2html1442"  HREF="node20.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node20.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1450"  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="tex2html1452"  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="tex2html1455"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html">3.4.3 Variable Tracing</A><B> Up:</B> <A NAME="tex2html1449"  HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1443"  HREF="node20.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node20.html">3.4.1.0.2 Deletion of TclObjects</A> &nbsp <B>  <A NAME="tex2html1451"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html1453"  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 + -