View source with formatted comments or as raw
   1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
   2
   3    Author:        Jan Wielemaker and Anjo Anjewierden
   4    E-mail:        jan@swi.psy.uva.nl
   5    WWW:           http://www.swi.psy.uva.nl/projects/xpce/
   6    Copyright (c)  1999-2011, University of Amsterdam
   7    All rights reserved.
   8
   9    Redistribution and use in source and binary forms, with or without
  10    modification, are permitted provided that the following conditions
  11    are met:
  12
  13    1. Redistributions of source code must retain the above copyright
  14       notice, this list of conditions and the following disclaimer.
  15
  16    2. Redistributions in binary form must reproduce the above copyright
  17       notice, this list of conditions and the following disclaimer in
  18       the documentation and/or other materials provided with the
  19       distribution.
  20
  21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32    POSSIBILITY OF SUCH DAMAGE.
  33*/
  34
  35:- module(pce_hyper, []).
  36:- use_module(library(pce)).
  37
  38/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  39This library defines some typical  dependency   relations  based on XPCE
  40hyper objects. Hyper objects relate two objects and are triggered by the
  41object-management layer if one of the connected object is destroyed.
  42
  43The partof_hyper will destroy  the  related   `part'  if  the `whole' is
  44destroyed, while th mutual_dependency_hyper  destroys   the  other side,
  45regardless of which of the two is destroyed initially.
  46
  47Example:
  48
  49        new(_, partof_hyper(Frame, Dialog))
  50
  51makes sure the Dialog is destroyed if the Frame disappears.
  52- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  53
  54
  55                 /*******************************
  56                 *     WHOLE-PART RELATION      *
  57                 *******************************/
  58
  59:- pce_begin_class(partof_hyper, hyper,
  60                   "<-to is a part of <-from").
  61
  62unlink_from(H) :->
  63    "->destroy the <-to part"::
  64    get(H, to, Part),
  65    (   object(Part),
  66        send(Part, has_send_method, destroy)
  67    ->  send(Part, destroy)
  68    ;   free(Part)
  69    ),
  70    free(H).
  71
  72:- pce_end_class(partof_hyper).
  73
  74
  75                 /*******************************
  76                 *  MUTUALLY DEPENDANT OBJECTS  *
  77                 *******************************/
  78
  79:- pce_begin_class(mutual_dependency_hyper, hyper,
  80                   "<-to and <-from depend on each other").
  81
  82unlink_from(H) :->
  83    "->destroy the <-to part"::
  84    get(H, to, Dependant),
  85    (   object(Dependant),
  86        send(Dependant, has_send_method, destroy)
  87    ->  send(Dependant, destroy)
  88    ;   free(Dependant)
  89    ),
  90    free(H).
  91
  92unlink_to(H) :->
  93    "->destroy the <-from part"::
  94    get(H, from, Dependant),
  95    (   object(Dependant),
  96        send(Dependant, has_send_method, destroy)
  97    ->  send(Dependant, destroy)
  98    ;   free(Dependant)
  99    ),
 100    free(H).
 101
 102:- pce_end_class(mutual_dependency_hyper).