The Labs \ Source Viewer \ SSCLI \ System.Globalization \ CalendarTable

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace System.Globalization
  16. {
  17.     using System.Runtime.Remoting;
  18.     using System;
  19.     using System.Runtime.CompilerServices;
  20.     using System.Threading;
  21.     using System.Runtime.Versioning;
  22.     using System.Runtime.InteropServices;
  23.    
  24. /*=============================================================================
  25.     *
  26.     * Calendar Data table for DateTimeFormatInfo classes.  Used by System.Globalization.DateTimeFormatInfo.
  27.     *
  28.     ==============================================================================*/   
  29.    
  30.     internal class CalendarTable : BaseInfoTable
  31.     {
  32.        
  33.         // The default instance of calendar table. We should only create one instance per app-domain.
  34.         private static CalendarTable m_defaultInstance;
  35.         unsafe CalendarTableData* m_calendars;
  36.        
  37.         [ResourceExposure(ResourceScope.Machine)]
  38.         [ResourceConsumption(ResourceScope.Machine)]
  39.         static CalendarTable()
  40.         {
  41.             m_defaultInstance = new CalendarTable("culture.nlp", true);
  42.         }
  43.        
  44.         [ResourceExposure(ResourceScope.Machine)]
  45.         [ResourceConsumption(ResourceScope.Machine)]
  46.         internal CalendarTable(string fileName, bool fromAssembly) : base(fileName, fromAssembly)
  47.         {
  48.             // Do nothing here.
  49.         }
  50.        
  51.         ////////////////////////////////////////////////////////////////////////
  52.         //
  53.         // Set Data Item Pointers that are unique to calendar table
  54.         //
  55.         ////////////////////////////////////////////////////////////////////////
  56.         unsafe internal override void SetDataItemPointers()
  57.         {
  58.             m_itemSize = m_pCultureHeader->sizeCalendarItem;
  59.             m_numItem = m_pCultureHeader->numCalendarItems;
  60.             m_pDataPool = (ushort*)(m_pDataFileStart + m_pCultureHeader->offsetToDataPool);
  61.             // We subtract item size because calender indices start at 1 but our table doesn't have an entry for 0
  62.             m_pItemData = m_pDataFileStart + m_pCultureHeader->offsetToCalendarItemData - m_itemSize;
  63.             // Get calendar list. We subtract 1 because calender indices start at 1 but our table doesn't have an entry for 0
  64.             m_calendars = (CalendarTableData*)(m_pDataFileStart + m_pCultureHeader->offsetToCalendarItemData) - 1;
  65.         }
  66.        
  67.         static internal CalendarTable Default {
  68.             get {
  69.                 BCLDebug.Assert(m_defaultInstance != null, "CalendarTable.Default: default instance is not created.");
  70.                 return (m_defaultInstance);
  71.             }
  72.         }
  73.        
  74.         unsafe internal int ICURRENTERA(int id)
  75.         {
  76.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.ICURRENTERA]id out of calendar range");
  77.            
  78.             return m_calendars[id].iCurrentEra;
  79.         }
  80.        
  81.         unsafe internal int IFORMATFLAGS(int id)
  82.         {
  83.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.IFORMATFLAGS]id out of calendar range");
  84.            
  85.             return m_calendars[id].iFormatFlags;
  86.         }
  87.        
  88.         unsafe internal string[] SDAYNAMES(int id)
  89.         {
  90.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SDAYNAMES]id out of calendar range");
  91.            
  92.             return GetStringArray(m_calendars[id].saDayNames);
  93.         }
  94.        
  95.         unsafe internal string[] SABBREVDAYNAMES(int id)
  96.         {
  97.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SABBREVDAYNAMES]id out of calendar range");
  98.            
  99.             return GetStringArray(m_calendars[id].saAbbrevDayNames);
  100.         }
  101.        
  102.         unsafe internal string[] SSUPERSHORTDAYNAMES(int id)
  103.         {
  104.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SSUPERSHORTDAYNAMES]id out of calendar range");
  105.            
  106.             return GetStringArray(m_calendars[id].saSuperShortDayNames);
  107.         }
  108.        
  109.         unsafe internal string[] SMONTHNAMES(int id)
  110.         {
  111.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SMONTHNAMES]id out of calendar range");
  112.            
  113.             return GetStringArray(m_calendars[id].saMonthNames);
  114.         }
  115.        
  116.         unsafe internal string[] SABBREVMONTHNAMES(int id)
  117.         {
  118.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SABBREVMONTHNAMES]id out of calendar range");
  119.            
  120.             return GetStringArray(m_calendars[id].saAbbrevMonthNames);
  121.         }
  122.        
  123.         unsafe internal string[] SLEAPYEARMONTHNAMES(int id)
  124.         {
  125.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SLEAPYEARMONTHNAMES]id out of calendar range");
  126.            
  127.             return GetStringArray(m_calendars[id].saLeapYearMonthNames);
  128.         }
  129.        
  130.         unsafe internal string[] SSHORTDATE(int id)
  131.         {
  132.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SSHORTDATE]id out of calendar range");
  133.            
  134.             return GetStringArray(m_calendars[id].saShortDate);
  135.         }
  136.        
  137.         unsafe internal string[] SLONGDATE(int id)
  138.         {
  139.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SLONGDATE]id out of calendar range");
  140.            
  141.             return GetStringArray(m_calendars[id].saLongDate);
  142.         }
  143.        
  144.         unsafe internal string[] SYEARMONTH(int id)
  145.         {
  146.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SYEARMONTH]id out of calendar range");
  147.            
  148.             return GetStringArray(m_calendars[id].saYearMonth);
  149.         }
  150.        
  151.         unsafe internal string SMONTHDAY(int id)
  152.         {
  153.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SMONTHDAY]id out of calendar range");
  154.            
  155.             return GetStringPoolString(m_calendars[id].sMonthDay);
  156.         }
  157.        
  158.         unsafe internal int[][] SERARANGES(int id)
  159.         {
  160.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SERARANGES]id out of calendar range");
  161.            
  162.             return GetWordArrayArray(m_calendars[id].waaEraRanges);
  163.         }
  164.        
  165.         unsafe internal string[] SERANAMES(int id)
  166.         {
  167.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SERANAMES]id out of calendar range");
  168.            
  169.             return GetStringArray(m_calendars[id].saEraNames);
  170.         }
  171.        
  172.         unsafe internal string[] SABBREVERANAMES(int id)
  173.         {
  174.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SABBREVERANAMES]id out of calendar range");
  175.            
  176.             return GetStringArray(m_calendars[id].saAbbrevEraNames);
  177.         }
  178.        
  179.         unsafe internal string[] SABBREVENGERANAMES(int id)
  180.         {
  181.             BCLDebug.Assert(id > 0 && id <= m_numItem, "[CalendarTable.SABBREVENGERANAMES]id out of calendar range");
  182.            
  183.             return GetStringArray(m_calendars[id].saAbbrevEnglishEraNames);
  184.         }
  185.        
  186.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  187.         static internal extern string nativeGetEraName(int culture, int calID);
  188.     }
  189. }

Developer Fusion