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

📄 objecttype.3

📁 linux系统下的音频通信
💻 3
字号:
'\"'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) ObjectType.3 1.8 97/04/30 15:42:29'\" .so man.macros.TH Tcl_ObjType 3 8.0 Tcl "Tcl Library Procedures".BS.SH NAMETcl_RegisterObjType, Tcl_GetObjType, Tcl_AppendAllObjTypes, Tcl_ConvertToType  \- manipulate Tcl object types.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sp\fBTcl_RegisterObjType\fR(\fItypePtr\fR).spTcl_ObjType *\fBTcl_GetObjType\fR(\fItypeName\fR).spint\fBTcl_AppendAllObjTypes\fR(\fIinterp, objPtr\fR).spint\fBTcl_ConvertToType\fR(\fIinterp, objPtr, typePtr\fR).SH ARGUMENTS.AS Tcl_ObjType *typeName in.AP Tcl_ObjType *typePtr inPoints to the structure containing information about the Tcl object type.This storage must must live forever,typically by being statically allocated..AP char *typeName inThe name of a Tcl object type that \fBTcl_GetObjType\fR should look up..AP Tcl_Interp *interp inInterpreter to use for error reporting..AP Tcl_Obj *objPtr inFor \fBTcl_AppendAllObjTypes\fR, this points to the object onto whichit appends the name of each object type as a list element.For \fBTcl_ConvertToType\fR, this points to an object thatmust have been the result of a previous call to \fBTcl_NewObj\fR..BE.SH DESCRIPTION.PPThe procedures in this man page manage Tcl object types.The are used to register new object types,look up types,and force conversions from one type to another..PP\fBTcl_RegisterObjType\fR registers a new Tcl object typein the table of all object types supported by Tcl.The argument \fItypePtr\fR points to a Tcl_ObjType structure thatdescribes the new type by giving its nameand by supplying pointers to four proceduresthat implement the type.If the type table already containes a typewith the same name as in \fItypePtr\fR,it is replaced with the new type.The Tcl_ObjType structure is describedin the section \fBTHE TCL_OBJTYPE STRUCTURE\fR below..PP\fBTcl_GetObjType\fR returns a pointer to the Tcl_ObjTypewith name \fItypeName\fR.It returns NULL if no type with that name is registered..PP\fBTcl_AppendAllObjTypes\fR appends the name of each object typeas a list element onto the Tcl object referenced by \fIobjPtr\fR.The return value is \fBTCL_OK\fR unless there was an errorconverting \fIobjPtr\fR to a list object;in that case \fBTCL_ERROR\fR is returned..PP\fBTcl_ConvertToType\fR converts an object from one type to anotherif possible.It creates a new internal representation for \fIobjPtr\fRappropriate for the target type \fItypePtr\fRand sets its \fItypePtr\fR member to that type.Any internal representation for \fIobjPtr\fR's old type is freed.If an error occurs during conversion, it returns \fBTCL_ERROR\fRand leaves an error message in the result object for \fIinterp\fRunless \fIinterp\fR is NULL.Otherwise, it returns \fBTCL_OK\fR.Passing a NULL \fIinterp\fR allows this procedure to be usedas a test whether the conversion can be done (and in fact was done)..SH "THE TCL_OBJTYPE STRUCTURE".PPExtension writers can define new object types by defining fourprocedures,initializing a Tcl_ObjType structure to describe the type,and calling \fBTcl_RegisterObjType\fR.The \fBTcl_ObjType\fR structure is defined as follows:.CStypedef struct Tcl_ObjType {	char *\fIname\fR;	Tcl_FreeInternalRepProc *\fIfreeIntRepProc\fR;	Tcl_DupInternalRepProc *\fIdupIntRepProc\fR;	Tcl_UpdateStringProc *\fIupdateStringProc\fR;	Tcl_SetFromAnyProc *\fIsetFromAnyProc\fR;} Tcl_ObjType;.CE.PPThe \fIname\fR member describes the name of the type, e.g. \fBint\fR.Extension writers can look up an object type using its namewith the \fBTcl_GetObjType\fR procedure.The remaining four members are pointers to procedurescalled by the generic Tcl object code:.PPThe \fIsetFromAnyProc\fR member contains the address of a functioncalled to create a valid internal representationfrom an object's string representation..CStypedef int (Tcl_SetFromAnyProc) (Tcl_Interp *\fIinterp\fR, Tcl_Obj *\fIobjPtr\fR);.CEIf an internal representation can't be created from the string,it returns \fBTCL_ERROR\fR and puts a messagedescribing the error in the result object for \fIinterp\fRunless \fIinterp\fR is NULL.If \fIsetFromAnyProc\fR is successful,it stores the new internal representation,sets \fIobjPtr\fR's \fItypePtr\fR member to point to\fIsetFromAnyProc\fR's \fBTcl_ObjType\fR, and returns \fBTCL_OK\fR.Before setting the new internal representation,the \fIsetFromAnyProc\fR must free any internal representationof \fIobjPtr\fR's old type;it does this by calling the old type's \fIfreeIntRepProc\fRif it is not NULL.As an example, the \fIsetFromAnyProc\fR for the builtin Tcl integer typegets an up-to-date string representation for \fIobjPtr\fRby calling \fBTcl_GetStringFromObj\fR.It parses the string to obtain an integer and,if this succeeds,stores the integer in \fIobjPtr\fR's internal representationand sets \fIobjPtr\fR's \fItypePtr\fR member to point to the integer type'sTcl_ObjType structure..PPThe \fIupdateStringProc\fR member contains the address of a functioncalled to create a valid string representationfrom an object's internal representation..CStypedef void (Tcl_UpdateStringProc) (Tcl_Obj *\fIobjPtr\fR);.CE\fIobjPtr\fR's \fIbytes\fR member is always NULL when it is called.It must always set \fIbytes\fR non-NULL before returning.We require the string representation's byte arrayto have a null after the last byte, at offset \fIlength\fR;this allows string representations that do not contain null bytesto be treated as conventional null character-terminated C strings.Storage for the byte array must be allocated in the heap by \fBTcl_Alloc\fR.Note that \fIupdateStringProc\fRs must allocateenough storage for the string's bytes and the terminating null byte.The \fIupdateStringProc\fR for Tcl's builtin list type, for example,builds an array of strings for each element objectand then calls \fBTcl_Merge\fRto construct a string with proper Tcl list structure.It stores this string as the list object's string representation..PPThe \fIdupIntRepProc\fR member contains the address of a functioncalled to copy an internal representation from one object to another..CStypedef void (Tcl_DupInternalRepProc) (Tcl_Obj *\fIsrcPtr\fR, Tcl_Obj *\fIdupPtr\fR);.CE\fIdupPtr\fR's internal representation is made a copy of \fIsrcPtr\fR'sinternal representation.Before the call,\fIsrcPtr\fR's internal representation is valid and \fIdupPtr\fR's is not.\fIsrcPtr\fR's object type determines whatcopying its internal representation means.For example, the \fIdupIntRepProc\fR for the Tcl integer typesimply copies an integer.The builtin list type's \fIdupIntRepProc\fRallocates a new array that points at the original element objects;the elements are shared between the two lists(and their reference counts are incremented to reflect the new references)..PPThe \fIfreeIntRepProc\fR member contains the address of a functionthat is called when an object is freed..CStypedef void (Tcl_FreeInternalRepProc) (Tcl_Obj *\fIobjPtr\fR);.CEThe \fIfreeIntRepProc\fR function can deallocate the storagefor the object's internal representationand do other type-specific processing necessary when an object is freed.For example, Tcl list objects have an \fIinternalRep.otherValuePtr\fRthat points to an array of pointers to each element in the list.The list type's \fIfreeIntRepProc\fR decrementsthe reference count for each element object(since the list will no longer refer to those objects),then deallocates the storage for the array of pointers.The \fIfreeIntRepProc\fR member can be set to NULLto indicate that the internal representation does not require freeing..SH "SEE ALSO"Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount.SH KEYWORDSinternal representation, object, object type, string representation, type conversion

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -