MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
PropertyTree.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace MyCaffe.common
8{
12 public class PropertyTree
13 {
14 Dictionary<string, List<Property>> m_rgValues = new Dictionary<string, List<Property>>();
15 Dictionary<string, List<PropertyTree>> m_rgChildren = new Dictionary<string, List<PropertyTree>>();
16
20 public PropertyTree()
21 {
22 }
23
29 public void Put(string str, string strVal)
30 {
31 if (!m_rgValues.ContainsKey(str))
32 m_rgValues.Add(str, new List<Property>());
33
34 m_rgValues[str].Add(new Property(strVal));
35 }
36
42 public void Put(string str, double dfVal)
43 {
44 if (!m_rgValues.ContainsKey(str))
45 m_rgValues.Add(str, new List<Property>());
46
47 m_rgValues[str].Add(new Property(dfVal));
48 }
49
55 public void AddChild(string str, PropertyTree pt)
56 {
57 if (!m_rgChildren.ContainsKey(str))
58 m_rgChildren.Add(str, new List<PropertyTree>());
59
60 m_rgChildren[str].Add(pt);
61 }
62
68 public Property Get(string strName)
69 {
70 if (!m_rgValues.ContainsKey(strName))
71 throw new Exception("No value key with name '" + strName + "' found!");
72
73 return m_rgValues[strName][0];
74 }
75
81 public List<Property> GetChildren(string strName)
82 {
83 if (!m_rgValues.ContainsKey(strName))
84 throw new Exception("No value key with name '" + strName + "' found!");
85
86 return m_rgValues[strName];
87 }
88
92 public void Clear()
93 {
94 m_rgValues = new Dictionary<string, List<Property>>();
95 m_rgChildren = new Dictionary<string, List<PropertyTree>>();
96 }
97
101 public List<PropertyTree> Children
102 {
103 get
104 {
105 List<PropertyTree> rgChildren = new List<PropertyTree>();
106
107 foreach (KeyValuePair<string, List<PropertyTree>> kv in m_rgChildren)
108 {
109 rgChildren.AddRange(kv.Value);
110 }
111
112 return rgChildren;
113 }
114 }
115
123 public string ToJson()
124 {
125#warning PropertyTree.ToJson NOT completed.
126 return "";
127 }
128 }
129
133 public class Property
134 {
135 string m_strVal;
136 double? m_dfVal;
137
143 public Property(string strVal, double? dfVal = null)
144 {
145 m_strVal = strVal;
146 m_dfVal = dfVal;
147 }
148
154 public Property(double dfVal, string strVal = null)
155 {
156 m_dfVal = dfVal;
157 m_strVal = strVal;
158 }
159
163 public string Value
164 {
165 get { return m_strVal; }
166 }
167
171 public double? Numeric
172 {
173 get { return m_dfVal; }
174 }
175 }
176}
The Property class stores both a numeric and text value.
Property(string strVal, double? dfVal=null)
The constructor.
double? Numeric
Returns the numeric value.
string Value
Returns the text value.
Property(double dfVal, string strVal=null)
The constructor.
The PropertyTree class implements a simple property tree similar to the ptree in Boost.
Definition: PropertyTree.cs:13
void Clear()
Clear all nodes and values from the tree.
Definition: PropertyTree.cs:92
List< PropertyTree > Children
Returns a list of all child property trees within the tree.
void Put(string str, string strVal)
Add a new property string value.
Definition: PropertyTree.cs:29
void AddChild(string str, PropertyTree pt)
Add a new child to the Property tree.
Definition: PropertyTree.cs:55
string ToJson()
Converts the property tree to a Json representation.
void Put(string str, double dfVal)
Add a new property numeric value.
Definition: PropertyTree.cs:42
Property Get(string strName)
Retrieves a property at the current level of the tree.
Definition: PropertyTree.cs:68
PropertyTree()
The constructor.
Definition: PropertyTree.cs:20
List< Property > GetChildren(string strName)
Retrieves all properties with the given key at the current level of the tree.
Definition: PropertyTree.cs:81
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8