//
// Copyright (c) 2008-2011, Kenneth Bell
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DiscUtils.Ntfs
{
using System;
///
/// Fully-qualified reference to an attribute.
///
internal class AttributeReference : IComparable, IEquatable
{
private FileRecordReference _fileReference;
private ushort _attributeId;
///
/// Initializes a new instance of the AttributeReference class.
///
/// The file containing the attribute.
/// The identity of the attribute within the file record.
public AttributeReference(FileRecordReference fileReference, ushort attributeId)
{
_fileReference = fileReference;
_attributeId = attributeId;
}
///
/// Gets the file containing the attribute.
///
public FileRecordReference File
{
get { return _fileReference; }
}
///
/// Gets the identity of the attribute within the file record.
///
public ushort AttributeId
{
get { return _attributeId; }
}
///
/// The reference as a string.
///
/// String representing the attribute.
public override string ToString()
{
return _fileReference.ToString() + ".attr[" + _attributeId + "]";
}
#region IComparable Members
///
/// Compares this attribute reference to another.
///
/// The attribute reference to compare against.
/// Zero if references are identical.
public int CompareTo(AttributeReference other)
{
int refDiff = _fileReference.CompareTo(other._fileReference);
if (refDiff != 0)
{
return refDiff;
}
return _attributeId.CompareTo(other._attributeId);
}
#endregion
#region IEquatable Members
///
/// Indicates if two references are equivalent.
///
/// The attribute reference to compare.
/// true if the references are equivalent.
public bool Equals(AttributeReference other)
{
return CompareTo(other) == 0;
}
#endregion
///
/// Indicates if this reference is equivalent to another object.
///
/// The object to compare.
/// true if obj is an equivalent attribute reference.
public override bool Equals(object obj)
{
AttributeReference objAsAttrRef = obj as AttributeReference;
if (objAsAttrRef == null)
{
return false;
}
return Equals(objAsAttrRef);
}
///
/// Gets the hash code for this reference.
///
/// The hash code.
public override int GetHashCode()
{
return _fileReference.GetHashCode() ^ _attributeId.GetHashCode();
}
}
}