1Tcl_Class(3)                TclOO Library Functions               Tcl_Class(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_ClassGetMetadata,   Tcl_ClassSetMetadata,   Tcl_CopyObjectInstance,
9       Tcl_GetClassAsObject,    Tcl_GetObjectAsClass,    Tcl_GetObjectCommand,
10       Tcl_GetObjectFromObj,     Tcl_GetObjectName,    Tcl_GetObjectNamespace,
11       Tcl_NewObjectInstance,    Tcl_ObjectDeleted,     Tcl_ObjectGetMetadata,
12       Tcl_ObjectGetMethodNameMapper,   Tcl_ObjectSetMetadata,  Tcl_ObjectSet‐
13       MethodNameMapper - manipulate objects and classes
14

SYNOPSIS

16       #include <tclOO.h>
17
18       Tcl_Object
19       Tcl_GetObjectFromObj(interp, objPtr)
20
21       Tcl_Object
22       Tcl_GetClassAsObject(class)
23
24       Tcl_Class
25       Tcl_GetObjectAsClass(object)
26
27       Tcl_Obj *
28       Tcl_GetObjectName(interp, object)
29
30       Tcl_Command
31       Tcl_GetObjectCommand(object)
32
33       Tcl_Namespace *
34       Tcl_GetObjectNamespace(object)
35
36       Tcl_Object
37       Tcl_NewObjectInstance(interp, class, name, nsName, objc, objv, skip)
38
39       Tcl_Object
40       Tcl_CopyObjectInstance(interp, object, name, nsName)
41
42       int
43       Tcl_ObjectDeleted(object)
44
45       ClientData
46       Tcl_ObjectGetMetadata(object, metaTypePtr)
47
48       Tcl_ObjectSetMetadata(object, metaTypePtr, metadata)
49
50       ClientData
51       Tcl_ClassGetMetadata(class, metaTypePtr)
52
53       Tcl_ClassSetMetadata(class, metaTypePtr, metadata)
54
55       Tcl_ObjectMapMethodNameProc
56       Tcl_ObjectGetMethodNameMapper(object)
57
58       Tcl_ObjectSetMethodNameMapper(object, methodNameMapper)
59

ARGUMENTS

61       Tcl_Interp *interp (in/out)       Interpreter providing the context for
62                                         looking up or creating an object, and
63                                         into whose result error messages will
64                                         be written on failure.
65
66       Tcl_Obj *objPtr (in)              The name of the object to look up.
67
68       Tcl_Object object (in)            Reference  to  the  object to operate
69                                         upon.
70
71       Tcl_Class class (in)              Reference to  the  class  to  operate
72                                         upon.
73
74       const char *name (in)             The  name of the object to create, or
75                                         NULL if a new unused name  is  to  be
76                                         automatically selected.
77
78       const char *nsName (in)           The  name  of the namespace to create
79                                         for the object's private use, or NULL
80                                         if  a  new unused name is to be auto‐
81                                         matically  selected.  The   namespace
82                                         must not already exist.
83
84       int objc (in)                     The  number  of  elements in the objv
85                                         array.
86
87       Tcl_Obj *const *objv (in)         The arguments to the command to  cre‐
88                                         ate the instance of the class.
89
90       int skip (in)                     The  number of arguments at the start
91                                         of the argument array, objv, that are
92                                         not arguments to any constructors.
93
94       Tcl_ObjectMetadataType *metaTypePtr (in)
95                                         The  type  of metadata being set with
96                                         Tcl_ClassSetMetadata   or   retrieved
97                                         with Tcl_ClassGetMetadata.
98
99       ClientData metadata (in)          An  item of metadata to attach to the
100                                         class, or NULL to remove the metadata
101                                         associated    with    a    particular
102                                         metaTypePtr.
103
104       Tcl_ObjectMapMethodNameProc methodNameMapper (in)
105                                         A pointer to a function  to  call  to
106                                         adjust  the  mapping  of  objects and
107                                         method names to  implementations,  or
108                                         NULL   when   no   such   mapping  is
109                                         required.
110______________________________________________________________________________
111

DESCRIPTION

113       Objects are typed entities that have a set  of  operations  ("methods")
114       associated with them. Classes are objects that can manufacture objects.
115       Each class can be viewed as an object itself; the object  view  can  be
116       retrieved  using  Tcl_GetClassAsObject  which always returns the object
117       when applied to a non-destroyed class, and an object can be viewed as a
118       class  with  the  aid of the Tcl_GetObjectAsClass (which either returns
119       the class, or NULL if the object is not a  class).  An  object  may  be
120       looked up using the Tcl_GetObjectFromObj function, which either returns
121       an object or NULL (with an error message in the interpreter result)  if
122       the  object cannot be found. The correct way to look up a class by name
123       is to look up the object with that name, and then to use  Tcl_GetObjec‐
124       tAsClass.
125
126       Every  object has its own command and namespace associated with it. The
127       command may be retrieved using the Tcl_GetObjectCommand  function,  the
128       name  of the object (and hence the name of the command) with Tcl_GetOb‐
129       jectName, and the namespace may be retrieved using  the  Tcl_GetObject‐
130       Namespace  function.  Note  that  the  Tcl_Obj  reference  returned  by
131       Tcl_GetObjectName is a shared reference.
132
133       Instances of classes are  created  using  Tcl_NewObjectInstance,  which
134       creates  an  object  from  any class (and which is internally called by
135       both the create and new methods  of  the  oo::class  class).  It  takes
136       parameters that optionally give the name of the object and namespace to
137       create, and which describe the arguments to pass to  the  class's  con‐
138       structor  (if  any). The result of the function will be either a refer‐
139       ence to the newly created object, or NULL if the creation failed  (when
140       an  error message will be left in the interpreter result). In addition,
141       objects may be copied by using Tcl_CopyObjectInstance which  creates  a
142       copy of an object without running any constructors.
143

OBJECT AND CLASS METADATA

145       Every  object  and  every  class may have arbitrary amounts of metadata
146       attached to it, which the object or class attaches no meaning to beyond
147       what is described in a Tcl_ObjectMetadataType structure instance. Meta‐
148       data to be attached is described by the type of the metadata (given  in
149       the  metaTypePtr argument) and an arbitrary pointer (the metadata argu‐
150       ment) that are given to Tcl_ObjectSetMetadata and Tcl_ClassSetMetadata,
151       and  a  particular  piece  of  metadata can be retrieved given its type
152       using Tcl_ObjectGetMetadata and Tcl_ClassGetMetadata. If  the  metadata
153       parameter  to  either  Tcl_ObjectSetMetadata or Tcl_ClassSetMetadata is
154       NULL, the metadata is removed if it was attached, and  the  results  of
155       Tcl_ObjectGetMetadata  and  Tcl_ClassGetMetadata  are NULL if the given
156       type of metadata was not attached. It is not an  error  to  request  or
157       remove a piece of metadata that was not attached.
158
159   TCL_OBJECTMETADATATYPE STRUCTURE
160       The contents of the Tcl_ObjectMetadataType structure are as follows:
161
162              typedef const struct {
163                  int version;
164                  const char *name;
165                  Tcl_ObjectMetadataDeleteProc *deleteProc;
166                  Tcl_CloneProc *cloneProc;
167              } Tcl_ObjectMetadataType;
168
169       The  version  field  allows  for future expansion of the structure, and
170       should always be declared equal to TCL_OO_METADATA_VERSION_CURRENT. The
171       name field provides a human-readable name for the type, and is reserved
172       for debugging.
173
174       The  deleteProc  field  gives  a  function  of   type   Tcl_ObjectMeta‐
175       dataDeleteProc  that  is used to delete a particular piece of metadata,
176       and is called when the attached metadata is replaced  or  removed;  the
177       field must not be NULL.
178
179       The  cloneProc  field  gives a function that is used to copy a piece of
180       metadata (used when a copy of an object is  created  using  Tcl_CopyOb‐
181       jectInstance); if NULL, the metadata will be just directly copied.
182
183   TCL_OBJECTMETADATADELETEPROC FUNCTION SIGNATURE
184       Functions  matching  this signature are used to delete metadata associ‐
185       ated with a class or object.
186
187              typedef void Tcl_ObjectMetadataDeleteProc(
188                      ClientData metadata);
189
190       The metadata argument gives the address of the metadata to be deleted.
191
192   TCL_CLONEPROC FUNCTION SIGNATURE
193       Functions matching this signature are used to create copies of metadata
194       associated with a class or object.
195
196              typedef int Tcl_CloneProc(
197                      Tcl_Interp *interp,
198                      ClientData srcMetadata,
199                      ClientData *dstMetadataPtr);
200
201       The  interp  argument  gives a place to write an error message when the
202       attempt to clone the object is to fail, in which case the clone  proce‐
203       dure  must  also  return  TCL_ERROR; it should return TCL_OK otherwise.
204       The srcMetadata argument gives  the  address  of  the  metadata  to  be
205       cloned,  and  the  cloned  metadata should be written into the variable
206       pointed to by dstMetadataPtr; a NULL should be written if the  metadata
207       is  to  not be cloned but the overall object copy operation is still to
208       succeed.
209

OBJECT METHOD NAME MAPPING

211       It is possible to control, on a  per-object  basis,  what  methods  are
212       invoked  when  a particular method is invoked. Normally this is done by
213       looking up the method name in the object and then in the class  hierar‐
214       chy,  but  fine  control  of exactly what the value used to perform the
215       look up is afforded through the ability to set  a  method  name  mapper
216       callback via Tcl_ObjectSetMethodNameMapper (and its introspection coun‐
217       terpart, Tcl_ObjectGetMethodNameMapper, which returns the current  map‐
218       per). The current mapper (if any) is invoked immediately before looking
219       up what chain of method implementations is to be used.
220
221   TCL_OBJECTMAPMETHODNAMEPROC FUNCTION SIGNATURE
222       The Tcl_ObjectMapMethodNameProc callback is defined as follows:
223
224              typedef int Tcl_ObjectMapMethodNameProc(
225                      Tcl_Interp *interp,
226                      Tcl_Object object,
227                      Tcl_Class *startClsPtr,
228                      Tcl_Obj *methodNameObj);
229
230       If the result is TCL_OK, the remapping is assumed to have been done. If
231       the result is TCL_ERROR, an error message will have been left in interp
232       and the method call will fail. If the result is TCL_BREAK, the standard
233       method  name  lookup  rules  will be used; the behavior of other result
234       codes is currently undefined. The object parameter says which object is
235       being  processed.  The  startClsPtr parameter points to a variable that
236       contains the first class to provide a definition in the method chain to
237       process,  or  NULL  if the whole chain is to be processed (the argument
238       itself is never NULL); this variable may be updated  by  the  callback.
239       The  methodNameObj  parameter  gives  an unshared object containing the
240       name of the method being invoked, as provided by the user; this  object
241       may be updated by the callback.
242

SEE ALSO

244       Method(3), oo::class(n), oo::copy(n), oo::define(n), oo::object(n)
245

KEYWORDS

247       class, constructor, object
248
249
250
251TclOO                                 0.1                         Tcl_Class(3)
Impressum