Пример #1
0
 public static GraphEdge parse(Graph graph, String line)
 {
     try
     {
         string[] items = line.Split(DELIMITER);
         return new GraphEdge(
                     graph.getPoint(Convert.ToInt32(items[0])),
                     graph.getPoint(Convert.ToInt32(items[1])),
                     Convert.ToDouble(items[2]));
     }
     catch (System.Exception e)
     {
         throw new GraphParseException("Edge parse error.", line, e);
     }
 }
Пример #2
0
        public static Graph load(String fileName)
        {
            Graph graph = new Graph();
            try
            {
                String directory = Path.GetDirectoryName(fileName);
                String baseFileName = Path.GetFileNameWithoutExtension(fileName);
                String pointsFileName = GraphElement.buildPath(directory, baseFileName, GraphPoint.EXTENSION);
                String edgesFileName = GraphElement.buildPath(directory, baseFileName, GraphEdge.EXTENSION);

                GraphElement.load(pointsFileName, graph, GraphPoint.parse);
                GraphElement.load(edgesFileName, graph, GraphEdge.parse);
            }
            catch (System.Exception e)
            {
                throw new BadFileFormatException("Unexpected error while parsing '" + fileName + "'.", e);
            }
            return graph;
        }
Пример #3
0
 public static GraphPoint parse(Graph graph, String line)
 {
     try
     {
         string[] items = line.Split(DELIMITER);
         return new GraphPoint(
                         Convert.ToInt32(items[0]),
                         items[1],
                         Convert.ToDouble(items[2]),
                         Convert.ToDouble(items[3]),
                         Convert.ToDouble(items[4]),
                         Convert.ToByte(items[5]),
                         Convert.ToByte(items[6]),
                         Convert.ToByte(items[7]));
     }
     catch (System.Exception e)
     {
         throw new GraphParseException("GraphPoint parse error.", line, e);
     }
 }
Пример #4
0
 public static void load(string fileName, Graph graph, GraphParser parser)
 {
     StreamReader reader = null;
     try
     {
         reader = new StreamReader(File.Open(fileName, FileMode.Open));
         String line = "";
         while ((line = reader.ReadLine()) != null)
         {
             graph.add(parser(graph, line));
         }
     }
     catch (System.Exception e)
     {
         throw new BadFileFormatException("Unexpected error while parsing '" + fileName + "'.", e);
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
     }
 }