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

📄 node23.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.4 command Methods: Definition and Invocation</TITLE><META NAME="description" CONTENT="3.4.4 command Methods: Definition and Invocation"><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="previous" HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><LINK REL="up" HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html"><LINK REL="next" HREF="node24.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1480"  HREF="node24.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1474"  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="tex2html1470"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1476"  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="tex2html1478"  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="tex2html1481"  HREF="node24.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html">3.5 Class TclClass</A><B> Up:</B> <A NAME="tex2html1475"  HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1471"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html">3.4.3 Variable Tracing</A> &nbsp <B>  <A NAME="tex2html1477"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html1479"  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="SECTION02144000000000000000"></A><A NAME="sec:Commands"></A><BR>3.4.4 command Methods: Definition and Invocation</H2><P>For every TclObject that is created,  establishesthe instance procedure, []cmd,as a hook to executing methods through the compiled shadow object.The procedure []cmd invokes the method []commandof the shadow object automatically, passing the arguments to []cmdas an argument vector to the []command method.<P>The user can invoke the []cmd method in one of two ways:by explicitly invoking the procedure, specifying the desiredoperation as the first argument, orimplicitly, as if there were an instance procedure of the same name as thedesired operation.Most simulation scripts will use the latter form, hence, we willdescribe that mode of invocation first.<P>Consider the that the distance computation in SRM is done bythe compiled object; however, it is often used by the interpreted object.It is usually invoked as:<PRE>        \$srmObject distance? \tup{agentAddress}</PRE>If there is no instance procedure called <TT>distance?</TT>,the interpreter will invoke the instance procedure[]unknown, defined in the base class TclObject.The unknown procedure then invokes<PRE>        \$srmObject cmd distance? \tup{agentAddress}</PRE>to execute the operation through the compiled object's[]command procedure.<P>Ofcourse, the user could explicitly invoke the operation directly.One reason for this might be to overload the operation by usingan instance procedure of the same name.For example,<PRE>        Agent/SRM/Adaptive instproc distance? addr {                \$self instvar distanceCache_                if ![info exists distanceCache_(\$addr)] {                        set distanceCache_(\$addr) [{\bfseries{}\$self cmd distance? \$addr}]                }                set distanceCache_(\$addr)        }</PRE><P>We now illustrate how the []command method using[]ASRMAgent::command as an example.<PRE>        int ASRMAgent::command(int argc, const char*const*argv) {                Tcl&amp; tcl = Tcl::instance();                if (argc == 3) {                        if (strcmp(argv[1], "distance?") == 0) {                                int sender = atoi(argv[2]);                                SRMinfo* sp = get_state(sender);                                tcl.tesultf("%f", sp-\&gt;distance_);                                return TCL_OK;                        }                }                return (SRMAgent::command(argc, argv));        }</PRE>We can make the following observations from this piece of code:<UL><LI>The function is called with two arguments:<P>The first argument (<TT>argc</TT>) indicates  the number of arguments specified in the command line to the interpreter.<P>The command line arguments vector (<TT>argv</TT>) consists of<P>-- <TT>argv[0]</TT> contains the name of the method, ``<TT>cmd</TT>''.<P>-- <TT>argv[1]</TT> specifies the desired operation.<P>-- If the user specified any arguments, then they are placed in  <TT>argv[2...(argc - 1)]</TT>.<P>The arguments are passed as strings;  they must be converted to the appropriate data type.</LI><LI>If the operation is successfully matched,  the match should return the result of the operation  using methods described earlierSectionsec:Result.</LI><LI>[]command itself must return either <TT>TCL_OK</TT> or <TT>TCL_ERROR</TT>  to indicate success or failure as its return code.</LI><LI>If the operation is not matched in this method, it must  invoke its parent's command method, and return the corresponding result.<P>This permits the user to concieve of operations as having the same  inheritance properties as instance procedures or compiled methods.<P>In the event that this <TT>command</TT> method   is defined for a class with multiple inheritance,  the programmer has the liberty to choose one of two implementations:<P>1) Either they can invoke one of the parent's <TT>command</TT> method,  and return the result of that invocation, or<P>2) They can each of the parent's <TT>command</TT> methods in some sequence,  and return the result of the first invocation that is successful.  If none of them are successful, then they should return an error.</LI></UL>In our document, we call operations executed through the []command <I>instproc-like</I>s.This reflects the usage of these operations as if they wereOTcl instance procedures of an object,but can be very subtly different in their realisation and usage.<P><HR><!--Navigation Panel--><A NAME="tex2html1480"  HREF="node24.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1474"  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="tex2html1470"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1476"  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="tex2html1478"  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="tex2html1481"  HREF="node24.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html">3.5 Class TclClass</A><B> Up:</B> <A NAME="tex2html1475"  HREF="node15.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node15.html">3.4 Class TclObject</A><B> Previous:</B> <A NAME="tex2html1471"  HREF="node22.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node22.html">3.4.3 Variable Tracing</A> &nbsp <B>  <A NAME="tex2html1477"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html1479"  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 + -