Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: experimental/visual_studio_plugin/src/SymbolDBViewer/DictionaryLoader.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #region
6
7 using System.Collections.Generic;
8 using System.ComponentModel;
9 using System.Linq;
10 using System.Windows.Forms;
11
12 #endregion
13
14 namespace SymbolDBViewer {
15 /// <summary>
16 /// A slightly modified BackgroundWorker which adds an ID field to help
17 /// us tell them apart later. As the name indicates, this worker is meant
18 /// to be used to load a table from the SymbolDatabase into the
19 /// SymbolDbTreeView_.
20 /// </summary>
21 public class DictionaryLoader<TEntryType> : BackgroundWorker {
22 /// <summary>
23 /// Simple Constructor. -1 is used here to indicate an uninitialized
24 /// ID.
25 /// </summary>
26 public DictionaryLoader() {
27 LoadPercentage = 0;
28 DictionaryName = "";
29 Content = null;
30 }
31
32 /// <summary>
33 /// Can't be read-only because of constraints that C# places on the
34 /// constructor signature.
35 /// </summary>
36 public int LoadPercentage { get; set; }
37
38 public string DictionaryName { get; set; }
39 public Dictionary<ulong, TEntryType> Content { get; set; }
40
41 public bool DoneLoading() {
42 return (LoadPercentage == 100);
43 }
44
45 /// <summary>
46 /// Creates a Tree to represent the entries from a Dictionary stored in
47 /// the SymbolDatabase.
48 /// </summary>
49 /// <param name = "sender">Used to report Progress.</param>
50 /// <param name = "e">Used to store and return the resulting Tree.</param>
51 public void PopulateTree(object sender, DoWorkEventArgs e) {
52 if (Content != null) {
53 var rootNode = new TreeNode(DictionaryName);
54 var nodes = rootNode.Nodes;
55 for (var i = 0; i < Content.Count; ++i) {
56 var entry = Content.ElementAt(i);
57 nodes.Add(GetTreeNode(entry.Key, entry.Value));
58
59 if (i % 100 == 0) {
60 LoadPercentage = (i * 100) / Content.Count;
61 ReportProgress(LoadPercentage);
62 }
63 }
64 LoadPercentage = 100;
65 e.Result = rootNode;
66 }
67 }
68
69 /// <summary>
70 /// Implements the TreeNode generator for EntryType. This function is
71 /// to be implemented by the child class.
72 /// </summary>
73 /// <param name = "die">The object which should be represented as a tree
74 /// node.</param>
75 /// <returns>A new TreeNode; an empty one if something went wrong.
76 /// </returns>
77 protected virtual TreeNode GetTreeNode(ulong key, TEntryType entry) {
78 return new TreeNode();
79 }
80
81
82 /// <summary>
83 /// Formats a single value of any type into a string.
84 /// </summary>
85 /// <typeparam name = "TArgType">The type.</typeparam>
86 /// <param name = "arg">The value.</param>
87 /// <returns>The string.</returns>
88 protected static string GetString<TArgType>(TArgType arg) {
89 return string.Format("{0}", arg);
90 }
91 }
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698