aboutsummaryrefslogtreecommitdiff
path: root/cs-dotnet/src/gatsdictionary.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cs-dotnet/src/gatsdictionary.cs129
1 files changed, 129 insertions, 0 deletions
diff --git a/cs-dotnet/src/gatsdictionary.cs b/cs-dotnet/src/gatsdictionary.cs
index af7f72a..77d088c 100644
--- a/cs-dotnet/src/gatsdictionary.cs
+++ b/cs-dotnet/src/gatsdictionary.cs
@@ -13,6 +13,26 @@ using System.Collections.Generic;
13 13
14namespace Com.Xagasoft.Gats 14namespace Com.Xagasoft.Gats
15{ 15{
16 /// <summary>
17 /// Encapsulates a single dictionary of GatsObjects.
18 /// </summary>
19 /// <remarks>
20 /// All keys are strings, and are encoded UTF-8. At the moment it is
21 /// advisable to stick to 7-bit ASCII or LATIN-1 compatible strings for
22 /// interoperability. If you want full unicode for keys, be sure you
23 /// handle it correctly with all libraries.
24 ///
25 /// Values can be any valid GatsObject.
26 ///
27 /// Just like dictionaries in memory, order is not important and is
28 /// considered random in encoded GATS. This means that dictionary items
29 /// may be in a different order after writing them and reading them back
30 /// again. Do not rely on a specific order, if you need ordered data use
31 /// a GatsList.
32 ///
33 /// All standard dictionary interface methods are implemented, so you can
34 /// use a GatsDictionary just like the .NET standard Dictionary.
35 /// </remarks>
16 public class GatsDictionary : GatsObject, IDictionary<string, GatsObject> 36 public class GatsDictionary : GatsObject, IDictionary<string, GatsObject>
17// ICollection<KeyValuePair<string, GatsObject>>, 37// ICollection<KeyValuePair<string, GatsObject>>,
18// IEnumerable<KeyValuePair<string, GatsObject>> 38// IEnumerable<KeyValuePair<string, GatsObject>>
@@ -68,6 +88,115 @@ namespace Com.Xagasoft.Gats
68 } 88 }
69 89
70 // 90 //
91 // Extra helper functions for making life with GATS easier
92 //
93
94 /// <summary>
95 /// Helper function to add a new GatsString to the dictionary from a
96 /// byte array.
97 /// </summary>
98 /// <param name="key">The key to insert the new value with</param>
99 /// <param name="val">The byte array to be inserted as a string</param>
100 public void Add( string key, byte[] val )
101 {
102 Add( key, new GatsString( val ) );
103 }
104
105 /// <summary>
106 /// Helper function to add a new GatsString to the dictionary from a
107 /// string.
108 /// </summary>
109 /// <remarks>
110 /// The string is encoded UTF-8 by .NETs internal facilities.
111 /// </remarks>
112 /// <param name="key">The key to insert the new value with</param>
113 /// <param name="val">The string to be inserted as a string</param>
114 public void Add( string key, string val )
115 {
116 Add( key, new GatsString( val ) );
117 }
118
119 /// <summary>
120 /// Helper function to add a new GatsInteger to the dictionary.
121 /// </summary>
122 /// <remarks>
123 /// Implicit upcasting should allow all integer types (byte, short,
124 /// int, long), and automatic unboxing should allow all object variants
125 /// to be passed into this method without problem.
126 /// </remarks>
127 /// <param name="key">The key to insert the new value with</param>
128 /// <param name="val">The long to be inserted</param>
129 public void Add( string key, long val )
130 {
131 Add( key, new GatsInteger( val ) );
132 }
133
134 /// <summary>
135 /// Helper function to add a new GatsFloat to the dictionary.
136 /// </summary>
137 /// <remarks>
138 /// Implicit upcasting should allow floats and doubles to both be
139 /// accepted by this method. Please note that decimal types are not
140 /// strictly compatible, please see GatsFloat for more details.
141 /// </remarks>
142 /// <param name="key">The key to insert the new value with</param>
143 /// <param name="val">The double to be inserted</param>
144 public void Add( string key, double val )
145 {
146 Add( key, new GatsFloat( val ) );
147 }
148
149 /// <summary>
150 /// Helper function to add a new GatsBoolean to the dictionary.
151 /// </summary>
152 /// <param name="key">The key to insert the new value with</param>
153 /// <param name="val">The boolean value to be inserted</param>
154 public void Add( string key, bool val )
155 {
156 Add( key, new GatsBoolean( val ) );
157 }
158
159 /// <summary>
160 /// Helper function to add a new GatsNull to the dictionary.
161 /// </summary>
162 /// <param name="key">The key to insert the new null value with</param>
163 public void AddNull( string key )
164 {
165 Add( key, new GatsNull() );
166 }
167
168 /// <summary>
169 /// Helper function to add a new GatsDictionary to the dictionary.
170 /// </summary>
171 /// <remarks>
172 /// A new GatsDictionary is created, added to the dictionary, and
173 /// returned.
174 /// </remarks>
175 /// <param name="key">The key to insert the new value with</param>
176 /// <returns>A new, empty dictionary that is already added</returns>
177 public GatsDictionary AddDict( string key )
178 {
179 GatsDictionary dict = new GatsDictionary();
180 Add( key, dict );
181 return dict;
182 }
183
184 /// <summary>
185 /// Helper function to add a new GatsList to the dictionary.
186 /// </summary>
187 /// <remarks>
188 /// A new GatsList is created, added to the dictionary, and returned.
189 /// </remarks>
190 /// <param name="key">The key to insert the new value with</param>
191 /// <returns>A new, empty list that is already added</returns>
192 public GatsList AddList( string key )
193 {
194 GatsList list = new GatsList();
195 Add( key, list );
196 return list;
197 }
198
199 //
71 // List interface overrides under here. 200 // List interface overrides under here.
72 // 201 //
73 public void Add( string key, GatsObject obj ) 202 public void Add( string key, GatsObject obj )