1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
33 using System.Collections;
36 /// SettingsGroup is the base class representing a group
37 /// of user or system settings. A pimpl idiom is used
38 /// to provide implementation-independence.
40 public class SettingsGroup : IDisposable
42 #region Instance Variables
44 /// The name of this group of settings
49 /// If not null, the storage implementation holding the group settings.
51 private SettingsStorage storageImpl;
54 /// If not null, the settings group that contains this one.
56 private SettingsGroup parentSettings;
60 #region Construction and Disposal
63 /// Construct a settings group based on a storage implementation.
65 /// <param name="name">Name of the group</param>
66 /// <param name="storageImpl">Storage for the group settings</param>
67 public SettingsGroup( string name, SettingsStorage storageImpl )
70 this.storageImpl = storageImpl;
74 /// Construct a settings group based on a parent group that contains it.
76 /// <param name="name">Name of the group</param>
77 /// <param name="parentSettings">Containing group</param>
78 public SettingsGroup( string name, SettingsGroup parentSettings )
81 this.parentSettings = parentSettings;
82 this.storageImpl = parentSettings.Storage.MakeChildStorage( name );
86 /// Dispose of this group by disposing of it's storage implementation
90 if ( storageImpl != null )
92 storageImpl.Dispose();
102 /// The name of the group
110 /// The storage used for the group settings
112 public SettingsStorage Storage
114 get { return storageImpl; }
118 /// The number of settings in this group
120 public int SettingsCount
122 get { return storageImpl.SettingsCount; }
130 /// Clear all settings and subgroups in this group
132 public virtual void Clear()
138 /// Load the value of one of the group's settings
140 /// <param name="settingName">Name of setting to load</param>
141 /// <returns>Value of the setting or null</returns>
142 public object LoadSetting( string settingName )
144 return storageImpl.LoadSetting( settingName );
148 /// Load the value of one of the group's integer settings
149 /// in a type-safe manner.
151 /// <param name="settingName">Name of setting to load</param>
152 /// <returns>Value of the setting or null</returns>
153 public int LoadIntSetting( string settingName )
155 return storageImpl.LoadIntSetting( settingName );
159 /// Load the value of one of the group's string settings
160 /// in a type-safe manner.
162 /// <param name="settingName">Name of setting to load</param>
163 /// <returns>Value of the setting or null</returns>
164 public string LoadStringSetting( string settingName )
166 return storageImpl.LoadStringSetting( settingName );
170 /// Load the value of one of the group's settings or return a default value
172 /// <param name="settingName">Name of setting to load</param>
173 /// <param name="defaultValue">Value to return if the seeting is not present</param>
174 /// <returns>Value of the setting or the default</returns>
175 public object LoadSetting( string settingName, object defaultValue )
177 return storageImpl.LoadSetting( settingName, defaultValue );
181 /// Load the value of one of the group's integer settings
182 /// in a type-safe manner or return a default value
184 /// <param name="settingName">Name of setting to load</param>
185 /// <param name="defaultValue">Value to return if the seeting is not present</param>
186 /// <returns>Value of the setting or the default</returns>
187 public int LoadIntSetting( string settingName, int defaultValue )
189 return storageImpl.LoadIntSetting( settingName, defaultValue );
193 /// Load the value of one of the group's string settings
194 /// in a type-safe manner or return a default value
196 /// <param name="settingName">Name of setting to load</param>
197 /// <param name="defaultValue">Value to return if the seeting is not present</param>
198 /// <returns>Value of the setting or the default</returns>
199 public string LoadStringSetting( string settingName, string defaultValue )
201 return storageImpl.LoadStringSetting( settingName, defaultValue );
205 /// Remove a setting from the group
207 /// <param name="settingName">Name of the setting to remove</param>
208 public void RemoveSetting( string settingName )
210 storageImpl.RemoveSetting( settingName );
214 /// Save the value of one of the group's settings
216 /// <param name="settingName">Name of the setting to save</param>
217 /// <param name="settingValue">Value to be saved</param>
218 public void SaveSetting( string settingName, object settingValue )
220 storageImpl.SaveSetting( settingName, settingValue );
224 /// Save the value of one of the group's integer settings
225 /// in a type-safe manner.
227 /// <param name="settingName">Name of the setting to save</param>
228 /// <param name="settingValue">Value to be saved</param>
229 public void SaveIntSetting( string settingName, int settingValue )
231 storageImpl.SaveSetting( settingName, settingValue );
235 /// Save the value of one of the group's string settings
236 /// in a type-safe manner.
238 /// <param name="settingName">Name of the setting to save</param>
239 /// <param name="settingValue">Value to be saved</param>
240 public void SaveStringSetting( string settingName, string settingValue )
242 storageImpl.SaveSetting( settingName, settingValue );