File: stackc.tcl

package info (click to toggle)
critcl 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,680 kB
  • sloc: ansic: 41,058; tcl: 12,090; sh: 7,230; pascal: 3,456; asm: 3,058; ada: 1,681; cpp: 1,001; cs: 879; makefile: 333; perl: 104; xml: 95; f90: 10
file content (93 lines) | stat: -rw-r--r-- 2,661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# stackc.tcl --
#
#       Implementation of a stack data structure for Tcl.
#       This code based on critcl v3.1, API compatible to the PTI [x].
#       [x] Pure Tcl Implementation.
#
# Demonstrates not just the stubs import and meta data declaration,
# but also the utility package for the creation of classes and objects
# in C, with both claaes and their instances represented as Tcl
# commands.
#
# Copyright (c) 2012,2022 Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require Tcl 8.6 9
package require critcl 3.2

critcl::buildrequirement {
    package require critcl::class ; # DSL, easy spec of Tcl class/object commands.
}

# # ## ### ##### ######## ############# #####################
## Administrivia

critcl::license {Andreas Kupries} {BSD licensed}

critcl::summary {Stack objects for Tcl.}

critcl::description {
    This package implements stack objects
    for Tcl. It uses the abstract data type
    provided by package 'cstack' for actual
    storage and operations.
}

critcl::subject stack
critcl::subject {data structure}
critcl::subject structure
critcl::subject {abstract data structure}
critcl::subject {generic data structure}

# # ## ### ##### ######## ############# #####################
## Configuration and implementation.

critcl::api import cstack 1

critcl::cheaders stackc/*.h ; # Method declarations and implementation,
critcl::csources stackc/*.c ; # outside of this main file.

critcl::class::define ::stackc {
    include m.h                  ; # Method function declarations.
    include cstack/cstackDecls.h ; # API of the generic CSTACK we are binding to.
    type    CSTACK

    constructor {
	instance = cstack_new (StackcFreeCell, 0);
    } {
	/* Set back reference from CSTACK instance to instance command */
	cstack_clientdata_set (instance, (ClientData) cmd);
    }

    destructor {
	/* Release the whole stack. */
	cstack_del (instance);
    }

    method clear   as stm_CLEAR
    method destroy as stm_DESTROY
    method peek    as stm_PEEK 0 0
    method peekr   as stm_PEEK 0 1
    method pop     as stm_PEEK 1 0
    method push    as stm_PUSH
    method rotate  as stm_ROTATE
    method size    as stm_SIZE
    method get     as stm_GET 0
    method getr    as stm_GET 1
    method trim    as stm_TRIM 1
    method trimv   as stm_TRIM 0

    support {
	static void
	StackcFreeCell (void* cell) {
	    /* Release the cell. */
	    Tcl_DecrRefCount ((Tcl_Obj*) cell);
	}
    }
}

# ### ### ### ######### ######### #########
## Ready
package provide stackc 1