[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interfacing Otcl with C++ classes



>>> From: Ramesh Neelamani <[email protected]>
>>> Date: Tue, 11 Nov 1997 01:35:12 CST

Amit,

Hmmm...I just went back and looked at the documentation, 
and it looks like this chapter needs more work...

>  The way to create the new TclObject is to derive from the TclClass. What 
>  is unclear to me is that how is the new TclObject recognised within ns.

The TclObject is the root of the interpreted and compiled
hierarchies.  Therefore, in C++, you define a class that is
derived from TclObject, or is derived from some class that is
itself derived from TclObject.  NsObject is derived from
TclObject, and therefore will work quite nicely.  It is, in fact,
preferable that objects in ns are derived from NsObject.  Another
object that you could derive from is Agent, also derived from
NsObject, and hence, TclObject.

The TclClass definitions provide the hooks that bind this
compiled class to an equivalent one in OTcl, called an
interpreted class.  You can define instance procedures in this
interpreted class.  Then you have the following:

>  I have read in the ns documentation that if I add a new .tcl file to be
>  sourced in ~ns/tcl/lib/ns-lib.tcl it will automatically get sourced by ns 
>  at startup.

So that finally, when the simulation user creates an object, that
object will be able to access all of the methods in this
interpreted class; the user can also access methods in the
compiled class through the special C++ method in the compiled
class called the command() method.

>  However I yet do not understand how I can "bind" the relevant .tcl file 
>  to the new class which I have created in a .cc file.

The TclClass definitions, and the static object you define for it
provide the relevant "bind"ing glue.  I thought this part of the
documentation (my opinion only) on the class TclClass was adequate.
If you find it is not so, please send me some mail about where
clarifications might have helped you, and I will update it for
the benefit of others,


Kannan

--
[email protected]
http://www.isi.edu/~kannan