TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
PDGNode.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK;
22 
23 namespace TraceLab.Components.Types.Preprocessors.ExecutionTraces
24 {
28  [Serializable]
29  [WorkspaceType]
30  public class PDGNode
31  {
35  public string MethodName { get; private set; }
36 
37  //public string DocumentID { get; private set; }
38 
42  public IEnumerable<PDGEdge> OutgoingEdges
43  {
44  get
45  {
46  return Children.Values;
47  }
48  }
49 
50  private SerializableDictionary<string, PDGEdge> Children;
51 
52  private PDGNode() { }
53 
58  public PDGNode(string methodName)//, string documentID)
59  {
60  MethodName = methodName;
61  //DocumentID = documentID;
62  Children = new SerializableDictionary<string, PDGEdge>();
63  }
64 
69  public void AddChild(string childID)
70  {
71  if (Children.ContainsKey(childID))
72  {
73  Children[childID].Weight += 1;
74  }
75  else
76  {
77  PDGEdge edge = new PDGEdge(childID);
78  edge.Weight = 1;
79  Children.Add(childID, edge);
80  }
81  }
82 
88  public void SetEdgeWeight(string childID, double weight)
89  {
90  if (Children.ContainsKey(childID))
91  {
92  Children[childID].Weight = weight;
93  }
94  else
95  {
96  PDGEdge edge = new PDGEdge(childID);
97  edge.Weight = weight;
98  Children.Add(childID, edge);
99  }
100  }
101 
107  public PDGEdge GetEdge(string childID)
108  {
109  if (Children.ContainsKey(childID))
110  {
111  return Children[childID];
112  }
113  else
114  {
115  return null;
116  }
117  }
118 
123  public override string ToString()
124  {
125  return "PDGNode [MethodName=" + MethodName + ", outgoingEdges=(" + String.Join(",", OutgoingEdges) + ")]";
126  }
127  }
128 }