#region License
// Copyright (c) 2013, ClearCanvas Inc.
// All rights reserved.
// http://www.clearcanvas.ca
//
// This file is part of the ClearCanvas RIS/PACS open source project.
//
// The ClearCanvas RIS/PACS open source project is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// The ClearCanvas RIS/PACS open source project is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the ClearCanvas RIS/PACS open source project.  If not, see
// <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using ClearCanvas.Dicom.IO;
namespace ClearCanvas.Dicom
{
    /// <summary>
    /// Class encapsulating a DICOM Value Representation.
    /// </summary>
    public class DicomVr
    {
        private delegate DicomAttribute CreateAttribute(DicomTag tag, ByteBuffer bb);
        #region Private Members
        private readonly String _name;
        private readonly bool _isText = false;
        private readonly bool _specificCharSet = false;
        private readonly bool _isMultiValue = false;
        private readonly uint _maxLength = 0;
        private readonly bool _is16BitLength = false;
        private readonly char _padChar = ' ';
        private readonly int _unitSize = 1;
        private readonly CreateAttribute _createDelegate;
        private static readonly IDictionary<String,DicomVr> _vrs = new Dictionary<String,DicomVr>();
        #endregion
        #region Public Static Members
        /// <summary>
        /// Static constructor.
        /// </summary>
        static DicomVr()
        {
            _vrs.Add(AEvr.Name, AEvr);
            _vrs.Add(ASvr.Name, ASvr);
            _vrs.Add(ATvr.Name, ATvr);
            _vrs.Add(CSvr.Name, CSvr);
            _vrs.Add(DAvr.Name, DAvr);
            _vrs.Add(DSvr.Name, DSvr);
            _vrs.Add(DTvr.Name, DTvr);
            _vrs.Add(FLvr.Name, FLvr);
            _vrs.Add(FDvr.Name, FDvr);
            _vrs.Add(ISvr.Name, ISvr);
            _vrs.Add(LOvr.Name, LOvr);
            _vrs.Add(LTvr.Name, LTvr);
            _vrs.Add(OBvr.Name, OBvr);
            _vrs.Add(ODvr.Name, ODvr);
            _vrs.Add(OFvr.Name, OFvr);
            _vrs.Add(OWvr.Name, OWvr);
            _vrs.Add(PNvr.Name, PNvr);
            _vrs.Add(SHvr.Name, SHvr);
            _vrs.Add(SLvr.Name, SLvr);
            _vrs.Add(SQvr.Name, SQvr);
            _vrs.Add(SSvr.Name, SSvr);
            _vrs.Add(STvr.Name, STvr);
            _vrs.Add(TMvr.Name, TMvr);
            _vrs.Add(UIvr.Name, UIvr);
            _vrs.Add(ULvr.Name, ULvr);
            _vrs.Add(USvr.Name, USvr);
            _vrs.Add(UTvr.Name, UTvr);
        }
        /// <summary>
        /// The Application Entity VR.
        /// </summary>
        public static readonly DicomVr AEvr = new DicomVr("AE", true, false, true, 16, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeAE(tag);
                return new DicomAttributeAE(tag, bb);
            } );
        /// <summary>
        /// The Age String VR.
        /// </summary>
        public static readonly DicomVr ASvr = new DicomVr("AS", true, false, true, 4, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeAS(tag);
                return new DicomAttributeAS(tag, bb);
            });
        /// <summary>
        /// The Attribute Tag VR.
        /// </summary>
        public static readonly DicomVr ATvr = new DicomVr("AT", false, false, true, 4, true, '\0', 4,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeAT(tag);
                return new DicomAttributeAT(tag, bb);
            });
        /// <summary>
        /// The Code String VR.
        /// </summary>
        public static readonly DicomVr CSvr = new DicomVr("CS", true, false, true, 16, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeCS(tag);
                return new DicomAttributeCS(tag, bb);
            });
        /// <summary>
        /// The Date VR.
        /// </summary>
        public static readonly DicomVr DAvr = new DicomVr("DA", true, false, true, 8, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeDA(tag);
                return new DicomAttributeDA(tag, bb);
            });
        /// <summary>
        /// The Decimal String VR.
        /// </summary>
        public static readonly DicomVr DSvr = new DicomVr("DS", true, false, true, 16, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeDS(tag);
                return new DicomAttributeDS(tag, bb);
            });
        /// <summary>
        /// The Date Time VR.
        /// </summary>
        public static readonly DicomVr DTvr = new DicomVr("DT", true, false, true, 26, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeDT(tag);
                return new DicomAttributeDT(tag, bb);
            });
        /// <summary>
        /// The Floating Point Single VR.
        /// </summary>
        public static readonly DicomVr FLvr = new DicomVr("FL", false, false, true, 4, true, '\0', 4,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeFL(tag);
                return new DicomAttributeFL(tag, bb);
            });
        /// <summary>
        /// The Floating Point Double VR.
        /// </summary>
        public static readonly DicomVr FDvr = new DicomVr("FD", false, false, true, 8, true, '\0', 8,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeFD(tag);
                return new DicomAttributeFD(tag, bb);
            });
        /// <summary>
        /// The Integer String VR.
        /// </summary>
        public static readonly DicomVr ISvr = new DicomVr("IS", true, false, true, 12, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeIS(tag);
                return new DicomAttributeIS(tag, bb);
            });
        /// <summary>
        /// The Long String VR.
        /// </summary>
        public static readonly DicomVr LOvr = new DicomVr("LO", true, true, true, 64, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeLO(tag);
                return new DicomAttributeLO(tag, bb);
            });
        /// <summary>
        /// The Long Text VR.
        /// </summary>
        public static readonly DicomVr LTvr = new DicomVr("LT", true, true, false, 10240, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeLT(tag);
                return new DicomAttributeLT(tag, bb);
            });
        /// <summary>
        /// The Other Byte String VR.
        /// </summary>
        public static readonly DicomVr OBvr = new DicomVr("OB", false, false, false, 1, false, '\0', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeOB(tag);
                return new DicomAttributeOB(tag, bb);
            });
        /// <summary>
        /// The Other Double String VR.
        /// </summary>
        public static readonly DicomVr ODvr = new DicomVr("OD", false, false, false, 8, false, '\0', 8,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeOD(tag);
                return new DicomAttributeOD(tag, bb);
            });
        /// <summary>
        /// The Other Float String VR.
        /// </summary>
        public static readonly DicomVr OFvr = new DicomVr("OF", false, false, false, 4, false, '\0', 4,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeOF(tag);
                return new DicomAttributeOF(tag, bb);
            });
        /// <summary>
        /// The Other Word String VR.
        /// </summary>
        public static readonly DicomVr OWvr = new DicomVr("OW", false, false, false, 2, false, '\0', 2,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeOW(tag);
                return new DicomAttributeOW(tag, bb);
            });
        /// <summary>
        /// The Person Name VR.
        /// </summary>
        public static readonly DicomVr PNvr = new DicomVr("PN", true, true, true, 64 * 5, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributePN(tag);
                return new DicomAttributePN(tag, bb);
            });
        /// <summary>
        /// The Short String VR.
        /// </summary>
        public static readonly DicomVr SHvr = new DicomVr("SH", true, true, true, 16, true, ' ', 1,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeSH(tag);
                return new DicomAttributeSH(tag, bb);
            });
        /// <summary>
        /// The Signed Long VR.
        /// </summary>
        public static readonly DicomVr SLvr = new DicomVr("SL", false, false, true, 4, true, '\0', 4,
            delegate(DicomTag tag, ByteBuffer bb)
            {
                if (bb == null) return new DicomAttributeSL(tag);


Answer:                 return new DicomAttributeSL(tag, bb);