// /*----------------------------------------------------------------*\ // | Concrete Template : List_Retreat_2 // \*----------------------------------------------------------------*/ #ifndef CT_LIST_RETREAT_2 #define CT_LIST_RETREAT_2 1 ///--------------------------------------------------------------------- /// Global Context ----------------------------------------------------- ///--------------------------------------------------------------------- #include "AT/List/Retreat.h" ///--------------------------------------------------------------------- /// Interface ---------------------------------------------------------- ///--------------------------------------------------------------------- concrete_template < concrete_instance class Item, concrete_instance class Node, /*! implements abstract_instance Record < Item, Pointer_C , Pointer_C > !*/ concrete_instance class Rep = Representation < Pointer_C , Pointer_C , Pointer_C , Integer, Integer > > class List_Retreat_2 : implements abstract_instance List_Retreat , encapsulates concrete_instance Rep { private: rep_field_name (Rep, 0, Pointer_C , pre_start); rep_field_name (Rep, 1, Pointer_C , last_left); rep_field_name (Rep, 2, Pointer_C , post_finish); rep_field_name (Rep, 3, Integer, left_length); rep_field_name (Rep, 4, Integer, right_length); field_name (Node, 0, Item, data); field_name (Node, 1, Pointer_C , next); field_name (Node, 2, Pointer_C , previous); /*! convention self.pre_start /= NULL and self.last_left /= NULL and self.post_finish /= NULL and self.left_length >= 0 and self.right_length >= 0 and [self.pre_start points to the first node of a doubly- linked list containing (self.left_length + self.right_length + 2) Node nodes] and [self.last_left points to the (self.left_length + 1)-th node in the doubly-linked list of nodes] and [self.post_finish points to the last node in the doubly-linked list of nodes] and [for every node n in the doubly-linked list of nodes, except the one pointed to by self.pre_start, n.previous.next = n] and [for every node n in the doubly-linked list of nodes, except the one pointed to by self.post_finish, n.next.previous = n] correspondence (if self.left_length = 0 then self.left = empty_string else if self.left_length = 1 then self.left = else if self.left_length = 2 then self.left = * else [self.left = * * ... * ]) and (if self.right_length = 0 then self.right = empty_string else if self.right_length = 1 then self.right = else if self.right_length = 2 then self.right = * else [self.right = * * ... * ]) !*/ local_procedure_body Initialize () { //-------- for students to fill in -------- } local_procedure_body Finalize () { //-------- for students to fill in -------- } public: standard_concrete_operations (List_Retreat_2); procedure_body Add_Right ( consumes Item& x ) { //-------- for students to fill in -------- } procedure_body Remove_Right ( produces Item& x ) { //-------- for students to fill in -------- } function_body Item& operator [] ( preserves Accessor_Position& current ) { //-------- for students to fill in -------- } procedure_body Advance () { //-------- for students to fill in -------- } procedure_body Retreat () { //-------- for students to fill in -------- } procedure_body Move_To_Start () { //-------- for students to fill in -------- } procedure_body Move_To_Finish () { //-------- for students to fill in -------- } function_body Integer Left_Length () { //-------- for students to fill in -------- } function_body Integer Right_Length () { //-------- for students to fill in -------- } }; #endif // CT_LIST_RETREAT_2