------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class GRAPH_EXC < $STR is
   -- The graph exception class. A single class is used for all library
   -- graph exceptions for simplicity and sanity.  It may make
   -- sense to split this class up at some future point
   -- The error states are denoted by the constants beginning with err_
   -- err should be set to one of these
   -- 
   -- Usage:
   --    raise #DIGRAPH_EXC{INT}(self,"foo",g,"bad graph").missing_edge_labels;
   --  
   --    protect
   --     ...
   --    when $STR then #OUT+exception.str; end;
   -- You can also check for more detailed information in the exception
   -- object. In general, you can compare the "err" flag to see which
   -- of the constants it is set to.
   --    switch exception.err
   --    when exception.err_missing_edge_labels then  -- do somethin
   --    when exception.err_missing_node_labels then ...
   --    else ... end;
   

   const err_missing_edge_labels: STR := "All edges not labelled";
   const err_missing_node_labels: STR := "All nodes not labelled";
   const err_not_specified: STR := "No error specified";
   
   readonly attr err: STR;
   -- Err should be set to one of the constant err_ strings
   
   readonly attr in_object: $OB; -- Object in which error occurs. 
   readonly attr routine_name: STR;
   readonly attr message: STR;
   readonly attr graph: $STR;
   
   create(inobj: $OB,rout: STR,g:$STR,msg: STR): SAME is
      res ::= new;
      res.in_object := inobj;
      res.routine_name := rout;
      res.message := msg;
      res.graph := g;
      res.err := err_not_specified;
      return res;
   end;
   
   missing_edge_labels: SAME is err:=err_missing_edge_labels; return self end;
   -- All edges were required to be labelled (possibly with weights) 
   -- but some labels were missing
   
   missing_node_labels: SAME is err:=err_missing_node_labels; return self end;
   -- All nodes were required to be labelled (possibly weighted) 
   -- but some were missing
   
   print(file: $OSTREAM) is
      file+ "\n**************************************************\n";
      file+ "Graph Exception in routine "+routine_name+"\n";
      file+"Error:"+err+"\n";
      file+"\n"+message+"\n";
      if ~void(graph) then file+graph.str;    end;
      file+"\n**************************************************\n";
   end;

   str: STR is 
      s::= #STR_STREAM;
      print(s);
      return s.str;
   end;
   
end;
-------------------------------------------------------------------
