home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / client_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  3.8 KB  |  159 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CLIENT_LIST
  17.    --   
  18.    -- To store a list of clients class like : {FOO,BAR}
  19.    -- 
  20.    
  21. inherit GLOBALS;
  22.  
  23. creation {EIFFEL_PARSER,CLIENT_LIST}
  24.    make, omitted
  25.  
  26. creation {CLIENT_LIST}
  27.    merge
  28.  
  29. feature {NONE}
  30.    
  31.    start_position: POSITION;
  32.      -- Of the the opening bracket when list is really written.
  33.    
  34. feature {CLIENT_LIST}
  35.    
  36.    list: CLASS_NAME_LIST;
  37.    
  38. feature {NONE}
  39.    
  40.    make(sp: like start_position; l: ARRAY[CLASS_NAME]) is
  41.      -- When the client list is really written.
  42.      -- 
  43.      -- Note : {NONE} has the same meaning as {}.
  44.       require
  45.      sp /= Void;
  46.      l /= Void implies not l.empty
  47.       do
  48.      start_position := sp;
  49.      if l /= Void then
  50.         !!list.make(l);
  51.      end;
  52.       ensure      
  53.      start_position = sp;
  54.       end;
  55.    
  56.    omitted is
  57.      -- When the client list is omitted. 
  58.      --
  59.      -- Note : it has the same meaning as {ANY}.
  60.       do
  61.       end;
  62.    
  63.    merge(sp: like start_position; l1, l2: like list) is
  64.       require
  65.      sp /= Void
  66.       do
  67.      start_position := sp;
  68.      !!list.merge(l1,l2);
  69.       end;
  70.  
  71. feature 
  72.    
  73.    is_omitted: BOOLEAN is
  74.       do
  75.      Result := start_position = Void;
  76.       end;
  77.    
  78.    pretty_print is
  79.       do
  80.      if is_omitted then
  81.         if fmt.zen_mode then
  82.         else           
  83.            fmt.put_string("{ANY}");
  84.         end
  85.      else 
  86.         if list = Void then
  87.            if fmt.zen_mode then
  88.           fmt.put_string("{}");
  89.            else
  90.           fmt.put_string("{NONE}");
  91.            end;
  92.         else
  93.            fmt.put_character('{');
  94.            fmt.set_indent_level(2);
  95.            list.pretty_print;
  96.            fmt.put_character('}');
  97.         end;
  98.      end;
  99.       end;
  100.  
  101.    gives_permission_to(cn: CLASS_NAME): BOOLEAN is
  102.      -- True if the client list give permission to `cn'.
  103.      -- When false, `eh' is preloaded with beginning of 
  104.      -- error message.
  105.       require
  106.      cn /= Void
  107.       do
  108.      if is_omitted then
  109.         Result := true;    
  110.         -- Because it is as : {ANY}.
  111.      elseif list = Void then
  112.         -- Because it is as : {NONE}.
  113.      else
  114.         Result := list.gives_permission_to(cn);
  115.      end;
  116.      if not Result then
  117.         eh.add_position(start_position);
  118.         eh.append(cn.to_string); 
  119.         eh.append(" is not allowed to use feature.");
  120.      end;
  121.       end;
  122.    
  123. feature {PARENT_LIST}
  124.  
  125.    append(other: like Current): like Current is
  126.       require
  127.      other /= Void
  128.       do
  129.      if (Current = other or else 
  130.          is_omitted or else 
  131.          gives_permission_to_any)
  132.       then
  133.         Result := Current;
  134.      elseif (other.is_omitted or else
  135.          other.gives_permission_to_any)
  136.       then
  137.         Result := other;
  138.      else
  139.         !!Result.merge(start_position,list,other.list);
  140.      end;
  141.       end;
  142.  
  143. feature
  144.  
  145.    gives_permission_to_any: BOOLEAN is
  146.       do
  147.      if is_omitted then
  148.         Result := true;    
  149.         -- Because it is as : {ANY}.
  150.      elseif list = Void then
  151.         -- Because it is as : {NONE}.
  152.      else
  153.         Result := list.gives_permission_to_any;
  154.      end;
  155.       end;
  156.  
  157. end -- CLIENT_LIST
  158.  
  159.