// /*----------------------------------------------------------------*\ // | Concrete Template : Stack_Kernel_1 // \*----------------------------------------------------------------*/ #ifndef CT_STACK_KERNEL_1 #define CT_STACK_KERNEL_1 1 ///--------------------------------------------------------------------- /// Global Context ----------------------------------------------------- ///--------------------------------------------------------------------- #include "AT/Stack/Kernel.h" ///--------------------------------------------------------------------- /// Interface ---------------------------------------------------------- ///--------------------------------------------------------------------- concrete_template < concrete_instance class Item, concrete_instance class Node, /*! implements abstract_instance Record < Item, Pointer_C > !*/ concrete_instance class Rep = Representation < Pointer_C , Integer > > class Stack_Kernel_1 : implements abstract_instance Stack_Kernel , encapsulates concrete_instance Rep { private: rep_field_name (Rep, 0, Pointer_C , top); rep_field_name (Rep, 1, Integer, length); field_name (Node, 0, Item, data); field_name (Node, 1, Pointer_C , next); /*! convention self.length >= 0 and if self.length = 0 then (self.top = NULL) else ([self.top points to the first node of a singly linked list containing self.length Node nodes, and where the next field of the last node is NULL]) correspondence if self.length = 0 then self = empty_string else self = [data fields of the first self.length nodes in the singly linked list pointed to by self.top, concatenated together in the order in which they are linked together] !*/ local_procedure_body Initialize () { self[top] = NULL; } local_procedure_body Finalize () { //-------- for students to fill in -------- } public: standard_concrete_operations (Stack_Kernel_1); procedure_body Push ( consumes Item& x ) { //-------- for students to fill in -------- } procedure_body Pop ( produces Item& x ) { //-------- for students to fill in -------- } function_body Item& operator [] ( preserves Accessor_Position& current ) { object Pointer_C p = self[top]; return (*p)[data]; } function_body Integer Length () { //-------- for students to fill in -------- } }; #endif // CT_STACK_KERNEL_1