switch case ex2

#include <stdio.h>

int main()

  int zhekou;
  int lucheng;
 
  
  printf("请输入路程\n");
  scanf("%d",&lucheng);
  
  switch(lucheng/250)
  {
     case 0:
         zhekou = 0;
         break;
     case 1:
         zhekou = 2;
         break;
     case 2:
     case 3:
         zhekou = 5;
         break;
     case 4:
     case 5:
     case 6:
     case 7:
         zhekou = 8;
         break;
     case 8:
     case 9:
     case 10:
     case 11:
         zhekou = 10;
         break;
    default:
         zhekou = 15;
         break;
         
  }     
     
 
 
   printf("折扣是:%.2f\n",(float)zhekou/100);

 return 0;
}

/** __ ___ _ ____ * ___\ \/ / |__ | | ___ __ _|___ \ * / _ \\ /| '_ \| |/ _ \ \ \ / / __) | * | __// \| |_) | | __/ \ V / / __/ * \___/_/\_\_.__/|_|\___| \_/ |_____| * * @file ex2_app_mouse.c * @brief exBLE v2 dual-mode mouse product demo. * @author onmicro * @date 2021/11 */ /******************************************************************************* * INCLUDES */ #include <stdbool.h> #include <stdio.h> #include <string.h> /* exBLE */ #include "ex2_api.h" #include "ex2_hal.h" #include "om_driver.h" #include "ex2_app_mouse.h" #include "evt.h" #include "mouse.h" /******************************************************************************* * TYPEDEFS */ /******************************************************************************* * CONST & VARIABLES */ mouse_adv_state_t mouse_state = MOUSE_LE_STATE_ADV; /* Peripheral Preferred Connection Parameters @ref ex2_gap_ppcp_t */ extern ex2_gap_ppcp_t ex2_gap_ppcp_value; /******************************************************************************* * LOCAL FUNCTIONS */ static bool ex2_app_mouse_broadcast_enable(uint32_t adv_interval_ms, uint32_t adv_timeout_ms, bool is_disc, bool swift_en) { uint8_t adv_ind_len; /* ADV_IND.AdvData */ uint8_t adv_ind[37] = { ///Flags: BLE limited discoverable mode and BR/EDR not supported 0x02, 0x01, BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, ///Complete list of service class UUIDs: HID 0x03, 0x03, 0x12, 0x18, ///Apperance: Mouse 0x03, 0x19, 0xC2, 0x03, ///Complete Local Name in 11 bytes always. (0 + 1), 0x09, }; if (!is_disc) { adv_ind[2] = BLE_GAP_ADV_FLAGS_LE_ONLY_NON_DISC_MODE; } /// Complete Local Name. adv_ind[11] = strlen(mouse_name) + 1U; memcpy(adv_ind+13, mouse_name, adv_ind[11] - 1U); adv_ind_len = 11 + adv_ind[11] + 1U; // 11 = 3(Flags) + 4 (HID UUID) + 4(Apperance); NameLength /// swift if (swift_en) { /// Manufacturer Specific Data: Swift const char swift_flag[] = {0x06, 0xFF, 0x06, 0x00, 0x03, 0x00, 0x80}; memcpy(&adv_ind[adv_ind_len], swift_flag, sizeof(swift_flag)); adv_ind_len += sizeof(swift_flag); } hid_notification_enable(0); return ex2_gap_set_broadcast_mode(adv_ind, adv_ind_len, is_disc, adv_interval_ms, adv_timeout_ms); } extern bool bhost_conn_ok; uint32_t adv_interval_ms; void ex2_app_mouse_broadcast_fsm(void) { // 广播状态机 bool is_disc; bool swift_en; uint32_t adv_timeout_ms; bool adv_en; bhost_conn_ok = false; adv_en = true; switch (mouse_state) { case MOUSE_LE_STATE_ADV: mouse_state = MOUSE_LE_STATE_STOP; /* Enter swift adv for pair w/ Manufacture field at 100ms advInterval. Stop adv in 180 seconds. */ adv_interval_ms = 20; adv_timeout_ms = 120*1000; is_disc = true; swift_en = true; break; case MOUSE_LE_STATE_STOP: adv_en = false; break; case MOUSE_LE_STATE_ADV_SWIFT: mouse_state = MOUSE_LE_STATE_ADV; /* Advertise w/o Manufacture field for swift before 3.5 seconds. */ /* Enter normal(advInterval=10ms) adv and discoverable mode for pair 3.5s timeout. */ adv_interval_ms = 10; adv_timeout_ms = 3500; is_disc = true; swift_en = false; break; case MOUSE_LE_STATE_DISCONN: mouse_state = MOUSE_LE_STATE_DISCONN_ADV; /* Enter fast(advInterval=5ms) adv and non-discoverable, connectable mode for connect-back. Stop connect-back in 10 seconds */ adv_interval_ms = 5; adv_timeout_ms = 5*1000; is_disc = false; swift_en = false; break; case MOUSE_LE_STATE_DISCONN_ADV: mouse_state = MOUSE_LE_STATE_STOP; /* Enter slow(advInterval=100ms) adv and non-discoverable, connectable mode for connect-back. Stop connect-back in 60 seconds */ adv_interval_ms = 20; adv_timeout_ms = 55*1000; is_disc = false; swift_en = false; break; default: adv_en = false; break; } if (adv_en) { ex2_app_mouse_broadcast_enable(adv_interval_ms, adv_timeout_ms, is_disc, swift_en); } } extern bool bble_conn_en; extern uint8_t mouse_bd_addr[]; extern ms_sleep_level_t ms_sleep_level; /******************************************************************************* * PUBLIC FUNCTIONS */ void ex2_app_mouse_ble_init(void) { adv_interval_ms = 0; ms_sleep_level = MS_SLEEP_LEVEL0; evt_callback_register(EVT_TYPE_BLE, ex2_stk_process); /* Part B, 1.3.2.1 Static device address */ mouse_bd_addr[5] |= 0xc0; ex2_stk_init(mouse_bd_addr); ex2_stk_register_app_evt_handler(app_ble_evt_dispatch); ex2_smp_enable_bond(); if(bble_conn_en) { drv_rf_set_tx_power(DRV_RF_PA_PWR_N12dBm); mouse_state = MOUSE_LE_STATE_ADV_SWIFT; } else { drv_rf_set_tx_power(DRV_RF_PA_PWR_5dBm); mouse_state = MOUSE_LE_STATE_DISCONN; } ex2_app_mouse_broadcast_fsm(); } /** @} */ 写上完整详细注释,不更改代码
08-22
解析如下代码,怎么实例化DicomAttributeCollection并添加元素 public class DicomAttributeCollection : System.Collections.Generic.IEnumerable<DicomAttribute>, System.Collections.IEnumerable, System.IDisposable { private SortedDictionary<uint, DicomAttribute> _attributeList = new SortedDictionary<uint, DicomAttribute>(); private long _bytesRead; private long _bytesRemain; private bool _disposed; private byte[] bPixelData; private byte[] bPixelDataType; public DicomAttribute this[uint tag] { get { return this._attributeList[tag]; } } public DicomAttribute this[Tag tag] { get { return this._attributeList[(uint)tag]; } } public int Count { get { return this._attributeList.Count; } } internal long ReadStream(System.IO.Stream s, TransferSyntax tsn, long streamLength) { if (streamLength >= DicomAttribute.UndefinedLength) { throw new DicomException("Tag value exceed the maximum length of the tag"); } System.IO.BinaryReader binaryReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); this._bytesRemain = streamLength; while (this._bytesRemain >= 4L) { ushort group = binaryReader.ReadUInt16(); ushort element = binaryReader.ReadUInt16(); this.RecordBytesRead(4L); DicomTag tag = new DicomTag(group, element); DicomAttribute dicomAttribute; if (tsn.IsExplicitVR) { string vr = new string(binaryReader.ReadChars(2)); this.RecordBytesRead(2L); VR vR = DicomVR.GetVR(vr); dicomAttribute = DicomAttribute.CreateAttribute(tag, vR); } else { dicomAttribute = DicomAttribute.CreateAttribute(tag); } ulong read = dicomAttribute.ReadStream(s, tsn); this.RecordBytesRead((long)read); this.AddDicomAttribute(dicomAttribute); } return this._bytesRead; } internal long ReadStream(System.IO.Stream s, TransferSyntax tsn, DicomTag stopTag) { long result; try { if (stopTag == null) { result = 0L; } else { System.IO.BinaryReader binaryReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); ushort group = binaryReader.ReadUInt16(); ushort element = binaryReader.ReadUInt16(); this.RecordBytesRead(4L); DicomTag dicomTag = new DicomTag(group, element); while (dicomTag <= stopTag && s.Position < s.Length - 1L) { DicomAttribute dicomAttribute; if (tsn.IsExplicitVR && dicomTag.TagVR.VR != VR.ITEM) { string vr = new string(binaryReader.ReadChars(2)); this.RecordBytesRead(2L); VR vR = DicomVR.GetVR(vr); dicomAttribute = DicomAttribute.CreateAttribute(dicomTag, vR); } else { dicomAttribute = DicomAttribute.CreateAttribute(dicomTag); } ulong read = dicomAttribute.ReadStream(s, tsn); this.RecordBytesRead((long)read); this.AddDicomAttribute(dicomAttribute); if (s.Position + 4L >= s.Length) { break; } group = binaryReader.ReadUInt16(); element = binaryReader.ReadUInt16(); dicomTag = new DicomTag(group, element); this.RecordBytesRead(4L); } s.Position -= 4L; this.RecordBytesRead(-4L); result = this._bytesRead; } } catch (DicomException ex) { ex.Source = this.ToString(); throw ex; } catch (System.Exception ex2) { throw ex2; } return result; } public void AddDicomAttribute(DicomAttribute attribute) { try { if (attribute != null && !this._attributeList.ContainsKey(attribute.Tag.Value)) { this._attributeList.Add(attribute.Tag.Value, attribute); } } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR(string.Concat(new object[] { "Add attribute element to Collection failed", ex.ToString(), "Attribute's Tag is:", attribute.Tag.Value })); } } public void RemoveDicomAttribute(DicomAttribute attribute) { this.RemoveDicomAttribute(attribute.Tag.Value); } public void RemoveDicomAttribute(Tag tag) { this.RemoveDicomAttribute((uint)tag); } public void RemoveDicomAttribute(uint tag) { try { if (!this._attributeList.ContainsKey(tag)) { return; } } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR(string.Concat(new object[] { "Remove attribute element from collection failed", ex.ToString(), "Tag is:", tag })); return; } this._attributeList.Remove(tag); } public bool Contains(Tag tag) { return this._attributeList.ContainsKey((uint)tag); } public bool Contains(uint tag) { return this._attributeList.ContainsKey(tag); } public bool Contains(DicomTag tag) { return this._attributeList.ContainsKey(tag.Value); } internal uint CalculateValueLength(TransferSyntax tsn) { if (this._attributeList == null || this._attributeList.Count == 0) { return 0u; } uint num = 0u; foreach (DicomAttribute current in this._attributeList.Values) { num += current.CalculateValueLength(tsn); } return num; } internal ulong WriteStream(System.IO.Stream s, TransferSyntax tsn) { ulong num = 0uL; foreach (DicomAttribute current in this._attributeList.Values) { num += current.WriteStream(s, tsn); } return num; } public bool SerializeToByteStream(DataHeaderWriteStream builder) { bool result = true; if (builder == null) { return false; } foreach (DicomAttribute current in this._attributeList.Values) { ByteStreamArchive.EnumArchiveType archiveElementType = current.GetArchiveElementType(); if (archiveElementType != ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { result = current.SerializeToByteStream(builder); } else { DicomAttributeSQ dicomAttributeSQ = current as DicomAttributeSQ; if (dicomAttributeSQ != null) { result = dicomAttributeSQ.SerializeToByteStream(builder); } } } return result; } private bool LongToByteArray(long lValue, out byte[] ret) { bool result; try { ret = null; string text = lValue.ToString(); if (9 > text.Length) { text = new string('0', 9 - text.Length) + text; } char[] array = text.ToCharArray(); ret = new byte[9]; for (int i = 0; i < 9; i++) { ret[i] = System.Convert.ToByte(array[i]); } result = true; } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR("from long to byte array failed" + ex.Message); ret = null; result = false; } return result; } private static bool ByteArrayToLong(byte[] bValue, out long ret) { bool result; try { char[] array = new char[9]; for (int i = 0; i < bValue.Length; i++) { array[i] = System.Convert.ToChar(bValue[i]); } string value = new string(array); ret = System.Convert.ToInt64(value); result = true; } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR("From byte array to long failed" + ex.Message); ret = 0L; result = false; } return result; } public bool SerializeToProtoElement(ProtoDataHeader pdh, uint depth, uint sequenceNo) { if (pdh == null) { return false; } foreach (DicomAttribute current in this._attributeList.Values) { ByteStreamArchive.EnumArchiveType archiveElementType = current.GetArchiveElementType(); if (archiveElementType != ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { ProtoElement protoElement = current.SerializeToProtoElement(depth, sequenceNo); if (protoElement != null) { pdh.ElementValueList.Add(protoElement); DataHeaderLog.PLOG_TRAC_INFO(string.Concat(new object[] { "Tag value is :", protoElement.Tag, "element's type is ", protoElement.Type.ToString() })); } } else { DicomAttributeSQ dicomAttributeSQ = current as DicomAttributeSQ; if (dicomAttributeSQ != null) { dicomAttributeSQ.SerializeToProtoElement(pdh, depth, sequenceNo); } } } return true; } public bool Serialize(out byte[] output) { output = null; StreamWriterFactory streamWriterFactory = new StreamWriterFactory(); DataHeaderWriteStream dataHeaderWriteStream = null; streamWriterFactory.Creator(ref dataHeaderWriteStream); if (streamWriterFactory.bProtoBufFlag) { ProtoDataHeader protoDataHeader = new ProtoDataHeader(); if (this.SerializeToProtoElement(protoDataHeader, 0u, 0u)) { output = protoDataHeader.ToByteArray(); return true; } } else { if (this.SerializeToByteStream(dataHeaderWriteStream)) { dataHeaderWriteStream.WriteTotalSize(); output = dataHeaderWriteStream.ToArray(); return true; } } return false; } public static DicomAttributeCollection Deserialize(byte[] input) { DicomAttributeCollection dicomAttributeCollection = new DicomAttributeCollection(); StreamReaderFactory streamReaderFactory = new StreamReaderFactory(); DataHeaderReadStream dataHeaderReadStream = null; if (!streamReaderFactory.Creator(ref input, ref dataHeaderReadStream)) { return null; } if (!dataHeaderReadStream.Deserialize(dicomAttributeCollection)) { return null; } return dicomAttributeCollection; } private void RecordBytesRead(long read) { this._bytesRead += read; this._bytesRemain -= read; } public System.Collections.Generic.IEnumerator<DicomAttribute> GetEnumerator() { return this._attributeList.Values.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public void Dispose() { if (!this._disposed) { foreach (DicomAttribute current in this._attributeList.Values) { current.Dispose(); } if (this.bPixelData != null) { this.bPixelData = null; } if (this.bPixelDataType != null) { this.bPixelDataType = null; } this._attributeList.Clear(); this._attributeList = null; this._disposed = true; } System.GC.SuppressFinalize(this); } } public abstract class DicomAttribute : System.IDisposable { protected const uint _undefinedLength = 4294967295u; private DicomTag _tag; private string _sVR; protected System.IO.BinaryReader _streamReader; protected ulong _bytesRead; protected System.IO.BinaryWriter _streamWriter; protected ulong _bytesWrite; protected bool _disposed; protected bool _needPadding; private static string[] _arrayVR = new string[] { "AE", "AS", "AT", "CS", "DA", "DS", "DT", "FD", "FL", "IS", "LO", "LT", "OB", "OD", "OF", "OV", "OW", "PN", "SH", "SL", "SQ", "SS", "ST", "SV", "TM", "UC", "UI", "UL", "UN", "UR", "US", "UT", "UV", "lt", "na", "ox", "xs" }; public DicomTag Tag { get { return this._tag; } } public ulong BytesRead { get { return this._bytesRead; } } public ulong BytesWrite { get { return this._bytesWrite; } } public static long UndefinedLength { get { return (long)((ulong)-1); } } public abstract int ValueCount { get; } public DicomTag GetDicomTag() { return this._tag; } protected DicomAttribute(DicomTag tag) { this._tag = tag; } public virtual ByteStreamArchive.EnumArchiveType GetArchiveElementType() { return ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UNKNOWN; } public virtual bool SetString(int index, string value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt16(int index, short value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt32(int index, int value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt64(int index, long value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt16(int index, ushort value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt32(int index, uint value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt32S(int index, uint[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt64(int index, ulong value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt64S(int index, ulong[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat32(int index, float value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat32S(int index, float[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat64(int index, double value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat64S(int index, double[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetDateTime(int index, System.DateTime value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetAttributeCollection(int index, DicomAttributeCollection item) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool PushBackAttributeCollection(DicomAttributeCollection item) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetBytes(int index, byte[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetOffSetTable(int[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual void SetVR(string sVR) { if (string.IsNullOrEmpty(sVR)) { return; } this._sVR = (DicomAttribute.isValidVR(ref sVR) ? sVR : "UN"); } public virtual bool GetString(int index, out string ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = ""; return false; } public virtual bool GetInt16(int index, out short ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetInt32(int index, out int ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetInt64(int index, out long ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0L; return false; } public virtual bool GetUInt16(int index, out ushort ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetUInt32(int index, out uint ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0u; return false; } public virtual bool GetUInt32S(int index, out uint[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetUInt64(int index, out ulong ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0uL; return false; } public virtual bool GetUInt64S(int index, out ulong[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetFloat32(int index, out float ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0f; return false; } public virtual bool GetFloat32S(int index, out float[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetFloat64(int index, out double ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0.0; return false; } public virtual bool GetFloat64S(int index, out double[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetDateTime(int index, out System.DateTime ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = System.DateTime.MinValue; return false; } public virtual bool GetBytes(int index, out byte[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetOffSetTable(out int[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetObject(int index, out object ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetAttributeCollection(int index, out DicomAttributeCollection ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetValueToString(int index, out string ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = ""; return false; } public virtual bool GetValueToInt64(int index, out long ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0L; return false; } public virtual bool GetValueToDouble(int index, out double ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0.0; return false; } public virtual string GetVR() { return this._sVR; } public static bool isValidVR(ref string sVR) { return System.Array.BinarySearch<string>(DicomAttribute._arrayVR, sVR) >= 0; } internal virtual string Dump() { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return null; } internal virtual ulong ReadStream(System.IO.Stream s, TransferSyntax tsn) { return this.ReadStream(s, tsn, s.Position); } internal virtual ulong ReadStream(System.IO.Stream s, TransferSyntax tsn, long startPosition) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return 0uL; } internal virtual ulong WriteStream(System.IO.Stream s, TransferSyntax tsn) { this.WriteStream(s, tsn, s.Position); return this._bytesWrite; } internal virtual void WriteStream(System.IO.Stream s, TransferSyntax tsn, long startPosition) { s.Position = startPosition; this._streamWriter = EndianBinaryWriter.CreateBinaryWriter(s, tsn.Endian); this._streamWriter.Write(this.Tag.GroupNumber); this._streamWriter.Write(this.Tag.ElementNumber); this._bytesWrite += 4uL; int num = (int)this.CalculateValueLength(tsn); if (tsn.IsExplicitVR) { byte[] array = CharacterProcessor.Encode(this.Tag.TagVR.VR.ToString()); this._streamWriter.Write(array); this._bytesWrite += (ulong)((long)array.Length); if (this.Tag.Is16BitLengthField) { this._streamWriter.Write((short)num); this._bytesWrite += 2uL; } else { this._streamWriter.Write(new byte[2]); this._streamWriter.Write(num); this._bytesWrite += 6uL; } } else { this._streamWriter.Write(num); this._bytesWrite += 4uL; } this.WriteAttributeValue(tsn); } public virtual ProtoElement SerializeToProtoElement(uint depth, uint iSequenceNo) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return null; } public virtual bool SerializeToByteStream(DataHeaderWriteStream archive) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return true; } public static DicomAttribute CreateAttribute(uint tag) { return DicomAttribute.CreateAttribute(new DicomTag(tag)); } public static DicomAttribute CreateAttribute(uint tag, string sVR) { return DicomAttribute.CreateAttribute(new DicomTag(tag), sVR); } public static DicomAttribute CreateAttribute(Tag tag) { return DicomAttribute.CreateAttribute(new DicomTag(tag)); } public static DicomAttribute CreateAttribute(Tag tag, string sVR) { return DicomAttribute.CreateAttribute(new DicomTag(tag), sVR); } public static DicomAttribute CreateAttribute(Tag tag, VR vr) { DicomTag dicomTag = DicomDictionary.GetDicomTag((uint)tag, vr); if (dicomTag == null) { return null; } return DicomAttribute.CreateAttribute(dicomTag, vr); } public static DicomAttribute CreateAttribute(ushort group, ushort element) { return DicomAttribute.CreateAttribute(new DicomTag(group, element)); } public static DicomAttribute CreateAttribute(DicomTag tag) { DicomAttribute dicomAttribute; switch (tag.TagVR.VR) { case VR.AE: dicomAttribute = new DicomAttributeAE(tag); dicomAttribute.SetVR("AE"); return dicomAttribute; case VR.AS: dicomAttribute = new DicomAttributeAS(tag); dicomAttribute.SetVR("AS"); return dicomAttribute; case VR.AT: dicomAttribute = new DicomAttributeAT(tag); dicomAttribute.SetVR("AT"); return dicomAttribute; case VR.CS: dicomAttribute = new DicomAttributeCS(tag); dicomAttribute.SetVR("CS"); return dicomAttribute; case VR.DA: dicomAttribute = new DicomAttributeDA(tag); dicomAttribute.SetVR("DA"); return dicomAttribute; case VR.DS: dicomAttribute = new DicomAttributeDS(tag); dicomAttribute.SetVR("DS"); return dicomAttribute; case VR.DT: dicomAttribute = new DicomAttributeDT(tag); dicomAttribute.SetVR("DT"); return dicomAttribute; case VR.FD: dicomAttribute = new DicomAttributeFD(tag); dicomAttribute.SetVR("FD"); return dicomAttribute; case VR.FL: dicomAttribute = new DicomAttributeFL(tag); dicomAttribute.SetVR("FL"); return dicomAttribute; case VR.IS: dicomAttribute = new DicomAttributeIS(tag); dicomAttribute.SetVR("IS"); return dicomAttribute; case VR.LO: dicomAttribute = new DicomAttributeLO(tag); dicomAttribute.SetVR("LO"); return dicomAttribute; case VR.LT: dicomAttribute = new DicomAttributeLT(tag); dicomAttribute.SetVR("LT"); return dicomAttribute; case VR.OB: dicomAttribute = new DicomAttributeOB(tag); dicomAttribute.SetVR("OB"); return dicomAttribute; case VR.OF: dicomAttribute = new DicomAttributeOF(tag); dicomAttribute.SetVR("OF"); return dicomAttribute; case VR.OW: dicomAttribute = new DicomAttributeOW(tag); dicomAttribute.SetVR("OW"); return dicomAttribute; case VR.PN: dicomAttribute = new DicomAttributePN(tag); dicomAttribute.SetVR("PN"); return dicomAttribute; case VR.SH: dicomAttribute = new DicomAttributeSH(tag); dicomAttribute.SetVR("SH"); return dicomAttribute; case VR.SL: dicomAttribute = new DicomAttributeSL(tag); dicomAttribute.SetVR("SL"); return dicomAttribute; case VR.SQ: dicomAttribute = new DicomAttributeSQ(tag); dicomAttribute.SetVR("SQ"); return dicomAttribute; case VR.SS: dicomAttribute = new DicomAttributeSS(tag); dicomAttribute.SetVR("SS"); return dicomAttribute; case VR.ST: dicomAttribute = new DicomAttributeST(tag); dicomAttribute.SetVR("ST"); return dicomAttribute; case VR.TM: dicomAttribute = new DicomAttributeTM(tag); dicomAttribute.SetVR("TM"); return dicomAttribute; case VR.UI: dicomAttribute = new DicomAttributeUI(tag); dicomAttribute.SetVR("UI"); return dicomAttribute; case VR.UL: dicomAttribute = new DicomAttributeUL(tag); dicomAttribute.SetVR("UL"); return dicomAttribute; case VR.US: dicomAttribute = new DicomAttributeUS(tag); dicomAttribute.SetVR("US"); return dicomAttribute; case VR.UT: dicomAttribute = new DicomAttributeUT(tag); dicomAttribute.SetVR("UT"); return dicomAttribute; case VR.OV: dicomAttribute = new DicomAttributeOV(tag); dicomAttribute.SetVR("OV"); return dicomAttribute; case VR.SV: dicomAttribute = new DicomAttributeSV(tag); dicomAttribute.SetVR("SV"); return dicomAttribute; case VR.UV: dicomAttribute = new DicomAttributeUV(tag); dicomAttribute.SetVR("UV"); return dicomAttribute; case VR.ITEM: return new DicomAttributeItemDelimitor(tag); case VR.OD: dicomAttribute = new DicomAttributeOD(tag); dicomAttribute.SetVR("OD"); return dicomAttribute; case VR.OL: dicomAttribute = new DicomAttributeOL(tag); dicomAttribute.SetVR("OL"); return dicomAttribute; case VR.UC: dicomAttribute = new DicomAttributeUC(tag); dicomAttribute.SetVR("UC"); return dicomAttribute; case VR.UR: dicomAttribute = new DicomAttributeUR(tag); dicomAttribute.SetVR("UR"); return dicomAttribute; } dicomAttribute = new DicomAttributeUN(tag); dicomAttribute.SetVR("UN"); return dicomAttribute; } public static DicomAttribute CreateAttribute(DicomTag tag, string sVR) { DicomAttribute dicomAttribute; switch (tag.TagVR.VR) { case VR.AE: dicomAttribute = new DicomAttributeAE(tag); goto IL_216; case VR.AS: dicomAttribute = new DicomAttributeAS(tag); goto IL_216; case VR.AT: dicomAttribute = new DicomAttributeAT(tag); goto IL_216; case VR.CS: dicomAttribute = new DicomAttributeCS(tag); goto IL_216; case VR.DA: dicomAttribute = new DicomAttributeDA(tag); goto IL_216; case VR.DS: dicomAttribute = new DicomAttributeDS(tag); goto IL_216; case VR.DT: dicomAttribute = new DicomAttributeDT(tag); goto IL_216; case VR.FD: dicomAttribute = new DicomAttributeFD(tag); goto IL_216; case VR.FL: dicomAttribute = new DicomAttributeFL(tag); goto IL_216; case VR.IS: dicomAttribute = new DicomAttributeIS(tag); goto IL_216; case VR.LO: dicomAttribute = new DicomAttributeLO(tag); goto IL_216; case VR.LT: dicomAttribute = new DicomAttributeLT(tag); goto IL_216; case VR.OB: dicomAttribute = new DicomAttributeOB(tag); goto IL_216; case VR.OF: dicomAttribute = new DicomAttributeOF(tag); goto IL_216; case VR.OW: dicomAttribute = new DicomAttributeOW(tag); goto IL_216; case VR.PN: dicomAttribute = new DicomAttributePN(tag); goto IL_216; case VR.SH: dicomAttribute = new DicomAttributeSH(tag); goto IL_216; case VR.SL: dicomAttribute = new DicomAttributeSL(tag); goto IL_216; case VR.SQ: dicomAttribute = new DicomAttributeSQ(tag); goto IL_216; case VR.SS: dicomAttribute = new DicomAttributeSS(tag); goto IL_216; case VR.ST: dicomAttribute = new DicomAttributeST(tag); goto IL_216; case VR.TM: dicomAttribute = new DicomAttributeTM(tag); goto IL_216; case VR.UI: dicomAttribute = new DicomAttributeUI(tag); goto IL_216; case VR.UL: dicomAttribute = new DicomAttributeUL(tag); goto IL_216; case VR.US: dicomAttribute = new DicomAttributeUS(tag); goto IL_216; case VR.UT: dicomAttribute = new DicomAttributeUT(tag); goto IL_216; case VR.OV: dicomAttribute = new DicomAttributeOV(tag); goto IL_216; case VR.SV: dicomAttribute = new DicomAttributeSV(tag); goto IL_216; case VR.UV: dicomAttribute = new DicomAttributeUV(tag); goto IL_216; case VR.ITEM: return new DicomAttributeItemDelimitor(tag); case VR.OD: dicomAttribute = new DicomAttributeOD(tag); goto IL_216; case VR.OL: dicomAttribute = new DicomAttributeOL(tag); goto IL_216; case VR.UC: dicomAttribute = new DicomAttributeUC(tag); goto IL_216; case VR.UR: dicomAttribute = new DicomAttributeUR(tag); goto IL_216; } dicomAttribute = new DicomAttributeUN(tag); IL_216: dicomAttribute.SetVR(sVR); return dicomAttribute; } public static DicomAttribute CreateAttribute(DicomTag tag, VR vr) { if (vr != VR.UN && tag.TagVR.VR != VR.UN) { VR arg_21_0 = tag.TagVR.VR; } DicomTag dicomTag = DicomDictionary.GetDicomTag(tag.Value, vr); if (dicomTag == null) { return null; } tag.TagVR = new DicomVR(vr); return DicomAttribute.CreateAttribute(tag); } protected uint GetAttributeValueLength(System.IO.Stream s, TransferSyntax tsn, long startPosition) { if (s == null) { return 0u; } if (tsn == null) { return 0u; } s.Seek(startPosition, System.IO.SeekOrigin.Begin); this._streamReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); uint result; if (tsn.IsExplicitVR) { if (this.Tag.Is16BitLengthField) { result = (uint)this._streamReader.ReadUInt16(); this._bytesRead += 2uL; } else { this._streamReader.ReadBytes(2); result = this._streamReader.ReadUInt32(); this._bytesRead += 6uL; } } else { result = this._streamReader.ReadUInt32(); this._bytesRead += 4uL; } return result; } protected static ProtoElement.Types.ElementType MapArchiveTypeToProtoType(ByteStreamArchive.EnumArchiveType eType) { if (eType <= ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DATA_HEADER) { if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM) { return ProtoElement.Types.ElementType.TYPE_ITEM; } if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DATA_HEADER) { return ProtoElement.Types.ElementType.TYPE_DATA_HEADER; } } else { switch (eType) { case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT8: return ProtoElement.Types.ElementType.TYPE_UINT8; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT16: return ProtoElement.Types.ElementType.TYPE_INT16; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT16: return ProtoElement.Types.ElementType.TYPE_UINT16; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT32: return ProtoElement.Types.ElementType.TYPE_INT32; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT32: return ProtoElement.Types.ElementType.TYPE_UINT32; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_SINGLE_FLOAT: return ProtoElement.Types.ElementType.TYPE_SINGLE_FLOAT; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DOUBLE_FLOAT: return ProtoElement.Types.ElementType.TYPE_DOUBLE_FLOAT; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_TIME: return ProtoElement.Types.ElementType.TYPE_TIME; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_VOIDPOINTER: return ProtoElement.Types.ElementType.TYPE_VOIDPOINTER; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_STRING: return ProtoElement.Types.ElementType.TYPE_STRING; default: switch (eType) { case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT8_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT8_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT16_ARRAY: return ProtoElement.Types.ElementType.TYPE_INT16_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT16_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT16_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT32_ARRAY: return ProtoElement.Types.ElementType.TYPE_INT32_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT32_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT32_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_SINGLE_FLOAT_ARRAY: return ProtoElement.Types.ElementType.TYPE_SINGLE_FLOAT_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DOUBLE_FLOAT_ARRAY: return ProtoElement.Types.ElementType.TYPE_DOUBLE_FLOAT_ARRAY; default: if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { return ProtoElement.Types.ElementType.TYPE_ITEM_LIST; } break; } break; } } return ProtoElement.Types.ElementType.TYPE_UNKNOWN; } internal abstract uint CalculateValueLength(TransferSyntax tsn); protected abstract void WriteAttributeValue(TransferSyntax tsn); public void Dispose() { this.Dispose(true); System.GC.SuppressFinalize(this); } protected abstract void Dispose(bool disposing); }
07-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值