zaaReloaded2/zaaReloaded2/Thesaurus/Units.cs

90 lines
2.7 KiB
C#
Executable File

/* UnitDictionary.cs
* part of zaaReloaded2
*
* Copyright 2015-2017 Daniel Kraus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace zaaReloaded2.Thesaurus
{
/// <summary>
/// Thesaurus that is used to convert Lauris units to canonical
/// zaaReloaded2 units.
/// </summary>
public class Units : ThesaurusBase
{
#region Singleton
private static readonly Units _default = new Units();
/// <summary>
/// Gets the default singleton instance of the Units thesaurus.
/// </summary>
/// <remarks>
/// http://csharpindepth.com/Articles/General/Singleton.aspx#cctor
/// </remarks>
public static Units Default { get { return _default; } }
static Units() { }
private Units() { }
#endregion
#region Public methods
/// <summary>
/// Translates a Lauris unit into a zaaReloaded2 canonical unit.
/// If there is no canonical unit, this function returns the
/// Lauris unit as-is.
/// </summary>
/// <param name="laurisUnit">Lauris unit to translate.</param>
/// <returns>Canonical unit, or Lauris unit if no canonical
/// unit was found.</returns>
public string TranslateLaurisUnit(string laurisUnit)
{
return LookUpValue(laurisUnit, 1, laurisUnit);
}
#endregion
#region Overrides
/// <summary>
/// Returns the resource stream for Defaults\parameters.txt.
/// </summary>
protected override System.IO.Stream GetDefaultStream()
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream(
"zaaReloaded2.Defaults.units.txt");
}
/// <summary>
/// Returns a path to a file parameters.txt in the addin directory
/// as provided by <see cref="ThisAddin.Subdir"/>.
/// </summary>
protected override string GetUserFileName()
{
return Path.Combine(ThisAddIn.Subdir, "units.txt");
}
#endregion
}
}