home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _C8C68B6CB0DF46E5BA03A67379BE3DAD < prev    next >
Encoding:
Text File  |  2003-05-21  |  42.3 KB  |  2,220 lines

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. // SchemaTypes.cpp
  4. //
  5. // This file was generated by XMLSPY 5 Enterprise Edition.
  6. //
  7. // YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
  8. // OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
  9. //
  10. // Refer to the XMLSPY Documentation for further details.
  11. // http://www.altova.com/xmlspy
  12. //
  13. ////////////////////////////////////////////////////////////////////////
  14.  
  15.  
  16. #include "StdAfx.h"
  17. #include "SchemaTypes.h"
  18. #include "XmlException.h"
  19. #include <math.h>
  20.  
  21.  
  22. namespace altova {
  23.  
  24.  
  25. ////////////////////////////////////////////////////////////////////////
  26. //
  27. //  CSchemaBoolean
  28. //
  29. ////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32. CSchemaBoolean::CSchemaBoolean(bool value) : m_Value(value)
  33. {
  34. }
  35.  
  36.  
  37. CSchemaBoolean::CSchemaBoolean(const TCHAR* szValue)
  38. {
  39.     m_Value = _tcscmp(szValue, _T("true")) == 0 || _tcscmp(szValue, _T("1")) == 0;
  40. }
  41.  
  42.  
  43. CSchemaBoolean::operator bool() const
  44. {
  45.     return m_Value;
  46. }
  47.  
  48.  
  49. CSchemaBoolean::operator tstring() const
  50. {
  51.     return m_Value ? _T("true") : _T("false");
  52. }
  53.  
  54.  
  55. ////////////////////////////////////////////////////////////////////////
  56. //
  57. //  CSchemaFloat
  58. //
  59. ////////////////////////////////////////////////////////////////////////
  60.  
  61.  
  62. CSchemaFloat::CSchemaFloat(float value) : m_Value(value)
  63. {
  64. }
  65.  
  66.  
  67. CSchemaFloat::CSchemaFloat(const TCHAR* szValue)
  68. {
  69.     TCHAR* endptr;
  70.     m_Value = _tcstod(szValue, &endptr);
  71. }
  72.  
  73.  
  74. CSchemaFloat::operator float() const
  75. {
  76.     return m_Value;
  77. }
  78.  
  79.  
  80. CSchemaFloat::operator tstring() const
  81. {
  82.     TCHAR szValue\[32\];
  83.     _sntprintf(szValue, 32, _T("%G"), m_Value);
  84.     return szValue;
  85. }
  86.  
  87.  
  88. ////////////////////////////////////////////////////////////////////////
  89. //
  90. //  CSchemaDouble
  91. //
  92. ////////////////////////////////////////////////////////////////////////
  93.  
  94.  
  95. CSchemaDouble::CSchemaDouble(double value) : m_Value(value)
  96. {
  97. }
  98.  
  99.  
  100. CSchemaDouble::CSchemaDouble(const TCHAR* szValue)
  101. {
  102.     TCHAR* endptr;
  103.     m_Value = _tcstod(szValue, &endptr);
  104. }
  105.  
  106.  
  107. CSchemaDouble::operator double() const
  108. {
  109.     return m_Value;
  110. }
  111.  
  112.  
  113. CSchemaDouble::operator tstring() const
  114. {
  115.     TCHAR szValue\[32\];
  116.     _sntprintf(szValue, 32, _T("%lG"), m_Value);
  117.     return szValue;
  118. }
  119.  
  120.  
  121. ////////////////////////////////////////////////////////////////////////
  122. //
  123. //  CSchemaDecimal
  124. //
  125. ////////////////////////////////////////////////////////////////////////
  126.  
  127.  
  128. CSchemaDecimal::CSchemaDecimal(double value) : m_Value(value)
  129. {
  130. }
  131.  
  132.  
  133. CSchemaDecimal::CSchemaDecimal(const TCHAR* szValue)
  134. {
  135.     TCHAR* endptr;
  136.     m_Value = _tcstod(szValue, &endptr);
  137. }
  138.  
  139.  
  140. CSchemaDecimal::operator double() const
  141. {
  142.     return m_Value;
  143. }
  144.  
  145.  
  146. CSchemaDecimal::operator tstring() const
  147. {
  148.     TCHAR szValue\[32\];
  149.     _sntprintf(szValue, 32, _T("%f"), m_Value);
  150.     return szValue;
  151. }
  152.  
  153.  
  154. ////////////////////////////////////////////////////////////////////////
  155. //
  156. //  CSchemaLong
  157. //
  158. ////////////////////////////////////////////////////////////////////////
  159.  
  160.  
  161. CSchemaLong::CSchemaLong(__int64 nValue) : m_Value(nValue)
  162. {
  163. }
  164.  
  165.  
  166. CSchemaLong::CSchemaLong(const TCHAR* szValue)
  167. {
  168.     m_Value = _ttoi64(szValue);
  169. }
  170.  
  171.  
  172. CSchemaLong::operator __int64() const
  173. {
  174.     return m_Value;
  175. }
  176.  
  177.  
  178. CSchemaLong::operator tstring() const
  179. {
  180.     TCHAR szValue\[32\];
  181.     _sntprintf(szValue, 32, _T("%I64i"), m_Value);
  182.     return szValue;
  183. }
  184.  
  185.  
  186. ////////////////////////////////////////////////////////////////////////
  187. //
  188. //  CSchemaUnsignedLong
  189. //
  190. ////////////////////////////////////////////////////////////////////////
  191.  
  192.  
  193. CSchemaUnsignedLong::CSchemaUnsignedLong(unsigned __int64 nValue) : m_Value(nValue)
  194. {
  195. }
  196.  
  197.  
  198. CSchemaUnsignedLong::CSchemaUnsignedLong(const TCHAR* szValue)
  199. {
  200.     m_Value = _ttoi64(szValue);
  201. }
  202.  
  203.  
  204. CSchemaUnsignedLong::operator unsigned __int64() const
  205. {
  206.     return m_Value;
  207. }
  208.  
  209.  
  210. CSchemaUnsignedLong::operator tstring() const
  211. {
  212.     TCHAR szValue\[32\];
  213.     _sntprintf(szValue, 32, _T("%I64u"), m_Value);
  214.     return szValue;
  215. }
  216.  
  217.  
  218. ////////////////////////////////////////////////////////////////////////
  219. //
  220. //  CSchemaInt
  221. //
  222. ////////////////////////////////////////////////////////////////////////
  223.  
  224.  
  225. CSchemaInt::CSchemaInt(long nValue) : m_Value(nValue)
  226. {
  227. }
  228.  
  229.  
  230. CSchemaInt::CSchemaInt(const TCHAR* szValue)
  231. {
  232.     m_Value = _ttol(szValue);
  233. }
  234.  
  235.  
  236. CSchemaInt::operator long() const
  237. {
  238.     return m_Value;
  239. }
  240.  
  241.  
  242. CSchemaInt::operator tstring() const
  243. {
  244.     TCHAR szValue\[32\];
  245.     _sntprintf(szValue, 32, _T("%li"), m_Value);
  246.     return szValue;
  247. }
  248.  
  249.  
  250. ////////////////////////////////////////////////////////////////////////
  251. //
  252. //  CSchemaUnsignedInt
  253. //
  254. ////////////////////////////////////////////////////////////////////////
  255.  
  256.  
  257. CSchemaUnsignedInt::CSchemaUnsignedInt(unsigned long nValue) : m_Value(nValue)
  258. {
  259. }
  260.  
  261.  
  262. CSchemaUnsignedInt::CSchemaUnsignedInt(const TCHAR* szValue)
  263. {
  264.     m_Value = _ttol(szValue);
  265. }
  266.  
  267.  
  268. CSchemaUnsignedInt::operator unsigned long() const
  269. {
  270.     return m_Value;
  271. }
  272.  
  273.  
  274. CSchemaUnsignedInt::operator tstring() const
  275. {
  276.     TCHAR szValue\[32\];
  277.     _sntprintf(szValue, 32, _T("%lu"), m_Value);
  278.     return szValue;
  279. }
  280.  
  281.  
  282. ////////////////////////////////////////////////////////////////////////
  283. //
  284. //  CSchemaShort
  285. //
  286. ////////////////////////////////////////////////////////////////////////
  287.  
  288.  
  289. CSchemaShort::CSchemaShort(short nValue) : m_Value(nValue)
  290. {
  291. }
  292.  
  293.  
  294. CSchemaShort::CSchemaShort(const TCHAR* szValue)
  295. {
  296.     m_Value = _ttoi(szValue);
  297. }
  298.  
  299.  
  300. CSchemaShort::operator short() const
  301. {
  302.     return m_Value;
  303. }
  304.  
  305.  
  306. CSchemaShort::operator tstring() const
  307. {
  308.     TCHAR szValue\[32\];
  309.     _sntprintf(szValue, 32, _T("%hi"), m_Value);
  310.     return szValue;
  311. }
  312.  
  313.  
  314. ////////////////////////////////////////////////////////////////////////
  315. //
  316. //  CSchemaUnsignedShort
  317. //
  318. ////////////////////////////////////////////////////////////////////////
  319.  
  320.  
  321. CSchemaUnsignedShort::CSchemaUnsignedShort(unsigned short nValue) : m_Value(nValue)
  322. {
  323. }
  324.  
  325.  
  326. CSchemaUnsignedShort::CSchemaUnsignedShort(const TCHAR* szValue)
  327. {
  328.     m_Value = _ttoi(szValue);
  329. }
  330.  
  331.  
  332. CSchemaUnsignedShort::operator unsigned short() const
  333. {
  334.     return m_Value;
  335. }
  336.  
  337.  
  338. CSchemaUnsignedShort::operator tstring() const
  339. {
  340.     TCHAR szValue\[32\];
  341.     _sntprintf(szValue, 32, _T("%hu"), m_Value);
  342.     return szValue;
  343. }
  344.  
  345.  
  346. ////////////////////////////////////////////////////////////////////////
  347. //
  348. //  CSchemaByte
  349. //
  350. ////////////////////////////////////////////////////////////////////////
  351.  
  352.  
  353. CSchemaByte::CSchemaByte(char nValue) : m_Value(nValue)
  354. {
  355. }
  356.  
  357.  
  358. CSchemaByte::CSchemaByte(const TCHAR* szValue)
  359. {
  360.     m_Value = _ttoi(szValue);
  361. }
  362.  
  363.  
  364. CSchemaByte::operator char() const
  365. {
  366.     return m_Value;
  367. }
  368.  
  369.  
  370. CSchemaByte::operator tstring() const
  371. {
  372.     TCHAR szValue\[32\];
  373.     _sntprintf(szValue, 32, _T("%hi"), m_Value);
  374.     return szValue;
  375. }
  376.  
  377.  
  378. ////////////////////////////////////////////////////////////////////////
  379. //
  380. //  CSchemaUnsignedByte
  381. //
  382. ////////////////////////////////////////////////////////////////////////
  383.  
  384.  
  385. CSchemaUnsignedByte::CSchemaUnsignedByte(unsigned char nValue) : m_Value(nValue)
  386. {
  387. }
  388.  
  389.  
  390. CSchemaUnsignedByte::CSchemaUnsignedByte(const TCHAR* szValue)
  391. {
  392.     m_Value = _ttoi(szValue);
  393. }
  394.  
  395.  
  396. CSchemaUnsignedByte::operator unsigned char() const
  397. {
  398.     return m_Value;
  399. }
  400.  
  401.  
  402. CSchemaUnsignedByte::operator tstring() const
  403. {
  404.     TCHAR szValue\[32\];
  405.     _sntprintf(szValue, 32, _T("%hu"), m_Value);
  406.     return szValue;
  407. }
  408.  
  409.  
  410. ////////////////////////////////////////////////////////////////////////
  411. //
  412. //  CSchemaString
  413. //
  414. ////////////////////////////////////////////////////////////////////////
  415.  
  416.  
  417. CSchemaString::CSchemaString(tstring sValue) : m_Value(sValue)
  418. {
  419. }
  420.  
  421.  
  422. CSchemaString::CSchemaString(const TCHAR* szValue) : m_Value(szValue)
  423. {
  424. }
  425.  
  426.  
  427. CSchemaString::operator tstring() const
  428. {
  429.     return m_Value;
  430. }
  431.  
  432.  
  433. ////////////////////////////////////////////////////////////////////////
  434. //
  435. //  Utility functions
  436. //
  437. ////////////////////////////////////////////////////////////////////////
  438.  
  439.  
  440. void ThrowFormatError()
  441. {
  442.     throw CXmlException(CXmlException::eError1, _T("Format error"));
  443. }
  444.  
  445.  
  446. int ParseInt(const TCHAR** pszData)
  447. {
  448.     TCHAR* szEndPtr;
  449.     int n = _tcstol(*pszData, &szEndPtr, 10);
  450.     if (*pszData == szEndPtr)
  451.         ThrowFormatError();
  452.     *pszData = szEndPtr;
  453.     return n;
  454. }
  455.  
  456.  
  457. double ParseDouble(const TCHAR** pszData)
  458. {
  459.     TCHAR* szEndPtr;
  460.     double d = _tcstod(*pszData, &szEndPtr);
  461.     if (*pszData == szEndPtr)
  462.         ThrowFormatError();
  463.     *pszData = szEndPtr;
  464.     return d;
  465. }
  466.  
  467.  
  468. void ParseChar(const TCHAR** pszData, TCHAR chValue)
  469. {
  470.     if (**pszData != chValue)
  471.         ThrowFormatError();
  472.     (*pszData)++;
  473. }
  474.  
  475.  
  476. int fQuotient(int a, int b)
  477. {
  478.     return div(a, b).quot;
  479. }
  480.  
  481.  
  482. int modulo(int a, int b)
  483. {
  484.     return a - fQuotient(a, b) * b;
  485. }
  486.  
  487.  
  488. double modulo(double a, double b)
  489. {
  490.     return a - fQuotient(a, b) * b;
  491. }
  492.  
  493.  
  494. int fQuotient(int a, int low, int high)
  495. {
  496.     return fQuotient(a - low, high - low);
  497. }
  498.  
  499.  
  500. int modulo(int a, int low, int high)
  501. {
  502.     return modulo(a - low, high - low) + low;
  503. }
  504.  
  505.  
  506. bool isLeapYear(int year)
  507. {
  508.     return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
  509. }
  510.  
  511.  
  512. int maxDayInMonthFor(int year, int month)
  513. {
  514.     if (month == 4 || month == 6 || month == 9 || month == 11)
  515.         return 30;
  516.     else if (month == 2)
  517.         return isLeapYear(year) ? 29 : 28;
  518.     else
  519.         return 31;
  520. }
  521.  
  522.  
  523. void DateTimeAddDuration(int& nYear, int& nMonth, int& nDay, int& nHour, int& nMinute, double& dSecond, const CSchemaDuration& dur)
  524. {
  525.     int temp = nMonth + dur.GetMonth();
  526.     nMonth = modulo(temp, 1, 13);
  527.     int carry = fQuotient(temp, 1, 13);
  528.  
  529.     nYear += dur.GetYear() + carry;
  530.  
  531.     double dtemp = dSecond + dur.GetSecond();
  532.     dSecond = modulo(dtemp, 60.0);
  533.     carry = fQuotient(dtemp, 60);
  534.  
  535.     temp = nMinute + dur.GetMinute() + carry;
  536.     nMinute = modulo(temp, 60);
  537.     carry = fQuotient(temp, 60);
  538.  
  539.     temp = nHour + dur.GetHour() + carry;
  540.     nHour = modulo(temp, 24);
  541.     carry = fQuotient(temp, 24);
  542.  
  543.     nDay += dur.GetDay() + carry;
  544.  
  545.     while (true)
  546.     {
  547.         temp = maxDayInMonthFor(nYear, nMonth);
  548.         if (nDay < 1)
  549.         {
  550.             nDay += maxDayInMonthFor(nYear, nMonth - 1);
  551.             carry = -1;
  552.         }
  553.         else if (nDay > temp)
  554.         {
  555.             nDay -= temp;
  556.             carry = 1;
  557.         }
  558.         else
  559.         {
  560.             break;
  561.         }
  562.  
  563.         temp = nMonth + carry;
  564.         nMonth = modulo(temp, 1, 13);
  565.         nYear += fQuotient(temp, 1, 13);
  566.     }
  567. }
  568.  
  569.  
  570. ////////////////////////////////////////////////////////////////////////
  571. //
  572. //  CSchemaDuration
  573. //
  574. ////////////////////////////////////////////////////////////////////////
  575.  
  576.     
  577. CSchemaDuration::CSchemaDuration(bool bPositive, int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond)
  578. {
  579.     m_bPositive    = bPositive;
  580.     m_nYear        = nYear;
  581.     m_nMonth    = nMonth;
  582.     m_nDay        = nDay;
  583.     m_nHour        = nHour;
  584.     m_nMinute    = nMinute;
  585.     m_dSecond    = dSecond;
  586. }
  587.  
  588.  
  589. CSchemaDuration::CSchemaDuration(const TCHAR* szValue)
  590. {
  591.     Parse(szValue);
  592. }
  593.  
  594.  
  595. CSchemaDuration::operator tstring() const
  596. {
  597.     TCHAR szResult\[64\];
  598.     TCHAR* szTmp = szResult;
  599.  
  600.     if (!m_bPositive)
  601.         *szTmp++ = _T('-');
  602.     *szTmp++ = _T('P');
  603.     if (m_nYear != 0)
  604.         szTmp += _stprintf(szTmp, _T("%iY"), abs(m_nYear));
  605.     if (m_nMonth != 0)
  606.         szTmp += _stprintf(szTmp, _T("%iM"), abs(m_nMonth));
  607.     if (m_nDay != 0)
  608.         szTmp += _stprintf(szTmp, _T("%iD"), abs(m_nDay));
  609.     if (m_nHour != 0 || m_nMinute != 0 || m_dSecond != 0)
  610.     {
  611.         *szTmp++ = _T('T');
  612.         if (m_nHour != 0)
  613.             szTmp += _stprintf(szTmp, _T("%iH"), abs(m_nHour));
  614.         if (m_nMinute != 0)
  615.             szTmp += _stprintf(szTmp, _T("%iM"), abs(m_nMinute));
  616.         if (m_dSecond != 0)
  617.         {
  618.             double d = m_dSecond < 0 ? m_dSecond * -1 : m_dSecond;
  619.             if (m_dSecond - floor(m_dSecond) == 0)
  620.             {
  621.                 szTmp += _stprintf(szTmp, _T("%01.f"), d);
  622.             }
  623.             else
  624.             {
  625.                 szTmp += _stprintf(szTmp, _T("%.9f"), d);
  626.                 while (*(szTmp-1) == _T('0'))
  627.                     *--szTmp = 0;
  628.             }
  629.             *szTmp++ = _T('S');
  630.         }
  631.     }
  632.     *szTmp = 0;
  633.  
  634.     return szResult;
  635. }
  636.  
  637.  
  638. bool CSchemaDuration::IsPositive() const
  639. {
  640.     return m_bPositive;
  641. }
  642.  
  643.  
  644. int CSchemaDuration::GetYear() const
  645. {
  646.     return m_nYear;
  647. }
  648.  
  649.  
  650. int CSchemaDuration::GetMonth() const
  651. {
  652.     return m_nMonth;
  653. }
  654.  
  655.  
  656. int CSchemaDuration::GetDay() const
  657. {
  658.     return m_nDay;
  659. }
  660.  
  661.  
  662. int CSchemaDuration::GetHour() const
  663. {
  664.     return m_nHour;
  665. }
  666.  
  667.  
  668. int CSchemaDuration::GetMinute() const
  669. {
  670.     return m_nMinute;
  671. }
  672.  
  673.  
  674. double CSchemaDuration::GetSecond() const
  675. {
  676.     return m_dSecond;
  677. }
  678.  
  679.  
  680. void CSchemaDuration::SetPositive(bool bPositive)
  681. {
  682.     m_bPositive = bPositive;
  683. }
  684.  
  685.  
  686. void CSchemaDuration::SetYear(int nYear)
  687. {
  688.     m_nYear = nYear;
  689. }
  690.  
  691.  
  692. void CSchemaDuration::SetMonth(int nMonth)
  693. {
  694.     m_nMonth = nMonth;
  695. }
  696.  
  697.  
  698. void CSchemaDuration::SetDay(int nDay)
  699. {
  700.     m_nDay = nDay;
  701. }
  702.  
  703.  
  704. void CSchemaDuration::SetHour(int nHour)
  705. {
  706.     m_nHour = nHour;
  707. }
  708.  
  709.  
  710. void CSchemaDuration::SetMinute(int nMinute)
  711. {
  712.     m_nMinute = nMinute;
  713. }
  714.  
  715.  
  716. void CSchemaDuration::SetSecond(double dSecond)
  717. {
  718.     m_dSecond = dSecond;
  719. }
  720.  
  721.  
  722. void CSchemaDuration::Parse(const TCHAR* szValue)
  723. {
  724.     const TCHAR* szTmp = szValue;
  725.     bool bTime = false;
  726.     int nTmp;
  727.  
  728.     m_bPositive = *szTmp != _T('-');
  729.     int nSign = m_bPositive ? 1 : -1;
  730.     ParseChar(&szTmp, _T('P'));
  731.  
  732.     while (*szTmp)
  733.     {
  734.         if (*szTmp == _T('T'))
  735.         {
  736.             if (bTime)
  737.                 ThrowFormatError();
  738.             szTmp++;
  739.             bTime = true;
  740.         }
  741.         nTmp = ParseInt(&szTmp);
  742.         if (!bTime)
  743.         {
  744.             switch (*szTmp)
  745.             {
  746.             case _T('Y'):    m_nYear  = nTmp * nSign; break;
  747.             case _T('M'):    m_nMonth = nTmp * nSign; break;
  748.             case _T('D'):    m_nDay   = nTmp * nSign; break;
  749.             default:        ThrowFormatError();
  750.             }
  751.         }
  752.         else
  753.         {
  754.             switch (*szTmp)
  755.             {
  756.             case _T('H'):    m_nHour   = nTmp * nSign; break;
  757.             case _T('M'):    m_nMinute = nTmp * nSign; break;
  758.             case _T('S'):    m_dSecond = nTmp * nSign; break;
  759.             case _T('.'):    m_dSecond = (nTmp + ParseDouble(&szTmp)) * nSign;
  760.                             if (*szTmp != _T('S'))
  761.                                 ThrowFormatError();
  762.                             break;
  763.             default:        ThrowFormatError();
  764.             }
  765.         }
  766.         szTmp++;
  767.     }
  768. }
  769.  
  770.  
  771. CSchemaDuration operator+(const CSchemaDuration& dur1, const CSchemaDuration& dur2)
  772. {
  773.     return CSchemaDuration(
  774.             !(dur1.m_bPositive    ^ dur2.m_bPositive),
  775.             dur1.m_nYear        + dur2.m_nYear,
  776.             dur1.m_nMonth        + dur2.m_nMonth,
  777.             dur1.m_nDay            + dur2.m_nDay,
  778.             dur1.m_nHour        + dur2.m_nHour,
  779.             dur1.m_nMinute        + dur2.m_nMinute,
  780.             dur1.m_dSecond        + dur2.m_dSecond
  781.             );
  782. }
  783.  
  784.  
  785.  
  786. ////////////////////////////////////////////////////////////////////////
  787. //
  788. //  CSchemaDateTimeBase
  789. //
  790. ////////////////////////////////////////////////////////////////////////
  791.  
  792.  
  793. CSchemaDateTimeBase::CSchemaDateTimeBase()
  794. {
  795. }
  796.  
  797.  
  798. CSchemaDateTimeBase::CSchemaDateTimeBase(bool bUTC)
  799. {
  800.     m_nTZMode    = bUTC ? TZ_UTC : TZ_Missing;
  801.     m_nOffset    = 0;
  802. }
  803.  
  804.  
  805. CSchemaDateTimeBase::CSchemaDateTimeBase(int nOffset)
  806. {
  807.     m_nTZMode        = TZ_Offset;
  808.     m_nOffset        = nOffset;
  809. }
  810.  
  811.  
  812. bool CSchemaDateTimeBase::HasTimezone() const
  813. {
  814.     return m_nTZMode != TZ_Missing;
  815. }
  816.  
  817.  
  818. int CSchemaDateTimeBase::GetTimezoneMode() const
  819. {
  820.     return m_nTZMode;
  821. }
  822.  
  823.  
  824. int CSchemaDateTimeBase::GetOffset() const
  825. {
  826.     return m_nOffset;
  827. }
  828.  
  829.  
  830. void CSchemaDateTimeBase::SetTimezoneMode(int nTZMode)
  831. {
  832.     m_nTZMode = nTZMode;
  833.     if (m_nTZMode == TZ_Missing || m_nTZMode == TZ_UTC)
  834.         m_nOffset = 0;
  835. }
  836.  
  837.  
  838. void CSchemaDateTimeBase::SetOffset(int nOffset)
  839. {
  840.     m_nTZMode = TZ_Offset;
  841.     m_nOffset = nOffset;
  842. }
  843.  
  844.  
  845. int CSchemaDateTimeBase::WriteTime(TCHAR* szTarget, int nHour, int nMinute, double dSecond)
  846. {
  847.     if (dSecond - floor(dSecond) == 0)
  848.     {
  849.         return _stprintf(szTarget, _T("%02i:%02i:%02.f"), nHour, nMinute, floor(dSecond));
  850.     }
  851.     else
  852.     {
  853.         TCHAR* szLast = szTarget + _stprintf(szTarget, _T("%02i:%02i:%02.9f"), nHour, nMinute, dSecond);
  854.  
  855.         while (*--szLast == _T('0'))
  856.             *szLast = 0;
  857.  
  858.         return szLast - szTarget;
  859.     }
  860. }
  861.  
  862.  
  863. void CSchemaDateTimeBase::ParseTZ(const TCHAR* szValue)
  864. {
  865.     const TCHAR* szTmp = szValue;
  866.  
  867.     if (*szTmp == 0)
  868.     {
  869.         m_nTZMode = TZ_Missing;
  870.         m_nOffset = 0;
  871.     }
  872.     else if (*szTmp == _T('Z'))
  873.     {
  874.         m_nTZMode = TZ_UTC;
  875.         m_nOffset = 0;
  876.         if (*++szTmp)
  877.             ThrowFormatError();
  878.     }
  879.     else
  880.     {
  881.         m_nTZMode = TZ_Offset;
  882.         int nOffsetHour = ParseInt(&szTmp);
  883.         ParseChar(&szTmp, _T(':'));
  884.         int nOffsetMinute = ParseInt(&szTmp);
  885.         if (nOffsetHour < 0)
  886.             m_nOffset = nOffsetHour * 60 - nOffsetMinute;
  887.         else
  888.             m_nOffset = nOffsetHour * 60 + nOffsetMinute;
  889.         if (*szTmp)
  890.             ThrowFormatError();
  891.     }
  892. }
  893.  
  894.  
  895. void CSchemaDateTimeBase::WriteTZ(TCHAR* szTarget) const
  896. {
  897.     switch (m_nTZMode)
  898.     {
  899.     case TZ_UTC:
  900.         _tcscat(szTarget, _T("Z"));
  901.         break;
  902.     
  903.     case TZ_Offset:
  904.         _stprintf(szTarget + _tcslen(szTarget), _T("%c%02i:%02i"),
  905.                 m_nOffset < 0 ? _T('-') : _T('+'),
  906.                 abs(m_nOffset / 60),
  907.                 abs(m_nOffset % 60)
  908.                 );
  909.         break;
  910.     }
  911. }
  912.  
  913.  
  914. ////////////////////////////////////////////////////////////////////////
  915. //
  916. //  CSchemaDate
  917. //
  918. ////////////////////////////////////////////////////////////////////////
  919.  
  920.  
  921. CSchemaDate::CSchemaDate(int nYear, int nMonth, int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
  922. {
  923.     m_nYear        = nYear;
  924.     m_nMonth    = nMonth;
  925.     m_nDay        = nDay;
  926. }
  927.  
  928.  
  929. CSchemaDate::CSchemaDate(int nYear, int nMonth, int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
  930. {
  931.     m_nYear        = nYear;
  932.     m_nMonth    = nMonth;
  933.     m_nDay        = nDay;
  934. }
  935.  
  936.  
  937. CSchemaDate::CSchemaDate(const TCHAR* szValue) : CSchemaDateTimeBase()
  938. {
  939.     Parse(szValue);
  940. }
  941.  
  942.  
  943. CSchemaDate::operator tstring() const
  944. {
  945.     TCHAR szTmp\[32\];
  946.     int nPos = _stprintf(szTmp, _T("%04i-%02i-%02i"), m_nYear, m_nMonth, m_nDay);
  947.     WriteTZ(szTmp + nPos);
  948.     return szTmp;
  949. }
  950.  
  951.  
  952. int CSchemaDate::GetYear() const
  953. {
  954.     return m_nYear;
  955. }
  956.  
  957.  
  958. int CSchemaDate::GetMonth() const
  959. {
  960.     return m_nMonth;
  961. }
  962.  
  963.  
  964. int CSchemaDate::GetDay() const
  965. {
  966.     return m_nDay;
  967. }
  968.  
  969.  
  970. void CSchemaDate::SetYear(int nYear)
  971. {
  972.     m_nYear = nYear;
  973. }
  974.  
  975.  
  976. void CSchemaDate::SetMonth(int nMonth)
  977. {
  978.     m_nMonth = nMonth;
  979. }
  980.  
  981.  
  982. void CSchemaDate::SetDay(int nDay)
  983. {
  984.     m_nDay = nDay;
  985. }
  986.  
  987.  
  988. void CSchemaDate::Parse(const TCHAR* szValue)
  989. {
  990.     const TCHAR* szTmp = szValue;
  991.  
  992.     m_nYear = ParseInt(&szTmp);
  993.     ParseChar(&szTmp, _T('-'));
  994.     m_nMonth = ParseInt(&szTmp);
  995.     ParseChar(&szTmp, _T('-'));
  996.     m_nDay = ParseInt(&szTmp);
  997.     ParseTZ(szTmp);
  998. }
  999.  
  1000.  
  1001. bool operator==(const CSchemaDate& t1, const CSchemaDate& t2)
  1002. {
  1003.     if (t1.HasTimezone() == t2.HasTimezone())
  1004.         return t1.m_nYear == t2.m_nYear
  1005.             && t1.m_nMonth == t2.m_nMonth
  1006.             && t1.m_nDay == t2.m_nDay;
  1007.     else
  1008.         return false;
  1009. }
  1010.  
  1011.  
  1012. bool operator<(const CSchemaDate& t1, const CSchemaDate& t2)
  1013. {
  1014.     if (t1.HasTimezone() == t2.HasTimezone())
  1015.         return t1.m_nYear < t2.m_nYear
  1016.             || t1.m_nYear == t2.m_nYear && t1.m_nMonth < t2.m_nMonth
  1017.             || t1.m_nYear == t2.m_nYear && t1.m_nMonth == t2.m_nMonth && t1.m_nDay < t2.m_nDay;
  1018.     else
  1019.         return false;
  1020. }
  1021.  
  1022.  
  1023. bool operator!=(const CSchemaDate& t1, const CSchemaDate& t2)
  1024. {
  1025.     return !(t1 == t2);
  1026. }
  1027.  
  1028.  
  1029. bool operator<=(const CSchemaDate& t1, const CSchemaDate& t2)
  1030. {
  1031.     return t1 < t2 || t1 == t2;
  1032. }
  1033.  
  1034.  
  1035. bool operator>(const CSchemaDate& t1, const CSchemaDate& t2)
  1036. {
  1037.     return t2 < t1;
  1038. }
  1039.  
  1040.  
  1041. bool operator>=(const CSchemaDate& t1, const CSchemaDate& t2)
  1042. {
  1043.     return t2 < t1 || t1 == t2;
  1044. }
  1045.  
  1046.  
  1047. CSchemaDate operator+(const CSchemaDate& t, const CSchemaDuration& dur)
  1048. {
  1049.     CSchemaDate r    = t;
  1050.     int nHour        = 0;
  1051.     int nMinute        = 0;
  1052.     double dSecond    = 0;
  1053.  
  1054.     DateTimeAddDuration(r.m_nYear, r.m_nMonth, r.m_nDay, nHour, nMinute, dSecond, dur);
  1055.  
  1056.     return r;
  1057. }
  1058.  
  1059.  
  1060. CSchemaDuration operator-(const CSchemaDate& t1, const CSchemaDate& t2)
  1061. {
  1062.     CSchemaDuration tmp(false, -t2.m_nYear, -t2.m_nMonth, -t2.m_nDay, 0, 0, 0);
  1063.     CSchemaDate t = t1 + tmp;
  1064.     return CSchemaDuration(true, t.m_nYear, t.m_nMonth, t.m_nDay, 0, 0, 0);
  1065. }
  1066.  
  1067.  
  1068. ////////////////////////////////////////////////////////////////////////
  1069. //
  1070. //  CSchemaTime
  1071. //
  1072. ////////////////////////////////////////////////////////////////////////
  1073.  
  1074.  
  1075. CSchemaTime::CSchemaTime(int nHour, int nMinute, double dSecond, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1076. {
  1077.     m_nHour        = nHour;
  1078.     m_nMinute    = nMinute;
  1079.     m_dSecond    = dSecond;
  1080. }
  1081.  
  1082.  
  1083. CSchemaTime::CSchemaTime(int nHour, int nMinute, double dSecond, int nOffset) : CSchemaDateTimeBase(nOffset)
  1084. {
  1085.     m_nHour        = nHour;
  1086.     m_nMinute    = nMinute;
  1087.     m_dSecond    = dSecond;
  1088. }
  1089.  
  1090.  
  1091. CSchemaTime::CSchemaTime(const TCHAR* szValue) : CSchemaDateTimeBase()
  1092. {
  1093.     Parse(szValue);
  1094. }
  1095.  
  1096.  
  1097. CSchemaTime::operator tstring() const
  1098. {
  1099.     TCHAR szTmp\[64\];
  1100.     int nPos = WriteTime(szTmp, m_nHour, m_nMinute, m_dSecond);
  1101.     WriteTZ(szTmp + nPos);
  1102.     return szTmp;
  1103. }
  1104.  
  1105.  
  1106. int CSchemaTime::GetHour() const
  1107. {
  1108.     return m_nHour;
  1109. }
  1110.  
  1111.  
  1112. int CSchemaTime::GetMinute() const
  1113. {
  1114.     return m_nMinute;
  1115. }
  1116.  
  1117.  
  1118.  
  1119. double CSchemaTime::GetSecond() const
  1120. {
  1121.     return m_dSecond;
  1122. }
  1123.  
  1124.  
  1125. void CSchemaTime::SetHour(int nHour)
  1126. {
  1127.     m_nHour = nHour;
  1128. }
  1129.  
  1130.  
  1131. void CSchemaTime::SetMinute(int nMinute)
  1132. {
  1133.     m_nMinute = nMinute;
  1134. }
  1135.  
  1136.  
  1137. void CSchemaTime::SetSecond(double dSecond)
  1138. {
  1139.     m_dSecond = dSecond;
  1140. }
  1141.  
  1142.  
  1143. void CSchemaTime::Parse(const TCHAR* szValue)
  1144. {
  1145.     const TCHAR* szTmp = szValue;
  1146.  
  1147.     m_nHour = ParseInt(&szTmp);
  1148.     ParseChar(&szTmp, _T(':'));
  1149.     m_nMinute = ParseInt(&szTmp);
  1150.     ParseChar(&szTmp, _T(':'));
  1151.     m_dSecond = ParseDouble(&szTmp);
  1152.     ParseTZ(szTmp);
  1153. }
  1154.  
  1155.  
  1156. double CSchemaTime::NormalizedSeconds() const
  1157. {
  1158.     return m_nHour * 3600 + m_nMinute * 60 + m_dSecond - m_nOffset * 60;
  1159. }
  1160.  
  1161.  
  1162. bool operator==(const CSchemaTime& t1, const CSchemaTime& t2)
  1163. {
  1164.     if (t1.HasTimezone() == t2.HasTimezone())
  1165.         return t1.NormalizedSeconds() == t2.NormalizedSeconds();
  1166.     else
  1167.         return false;
  1168. }
  1169.  
  1170.  
  1171. bool operator<(const CSchemaTime& t1, const CSchemaTime& t2)
  1172. {
  1173.     if (t1.HasTimezone() == t2.HasTimezone())
  1174.         return t1.NormalizedSeconds() < t2.NormalizedSeconds();
  1175.  
  1176.     if (t1.HasTimezone())
  1177.         return t1.NormalizedSeconds() < t2.NormalizedSeconds() - 50400;
  1178.     else
  1179.         return t1.NormalizedSeconds() + 50400 < t2.NormalizedSeconds();
  1180. }
  1181.  
  1182.  
  1183. bool operator!=(const CSchemaTime& t1, const CSchemaTime& t2)
  1184. {
  1185.     return !(t1 == t2);
  1186. }
  1187.  
  1188.  
  1189. bool operator<=(const CSchemaTime& t1, const CSchemaTime& t2)
  1190. {
  1191.     return t1 < t2 || t1 == t2;
  1192. }
  1193.  
  1194.  
  1195. bool operator>(const CSchemaTime& t1, const CSchemaTime& t2)
  1196. {
  1197.     return t2 < t1;
  1198. }
  1199.  
  1200.  
  1201. bool operator>=(const CSchemaTime& t1, const CSchemaTime& t2)
  1202. {
  1203.     return t2 < t1 || t1 == t2;
  1204. }
  1205.  
  1206.  
  1207. CSchemaTime operator+(const CSchemaTime& t, const CSchemaDuration& dur)
  1208. {
  1209.     CSchemaTime r    = t;
  1210.     int nYear        = 1;
  1211.     int nMonth        = 1;
  1212.     int nDay        = 1;
  1213.  
  1214.     DateTimeAddDuration(nYear, nMonth, nDay, r.m_nHour, r.m_nMinute, r.m_dSecond, dur);
  1215.  
  1216.     return r;
  1217. }
  1218.  
  1219.  
  1220. CSchemaDuration operator-(const CSchemaTime& t1, const CSchemaTime& t2)
  1221. {
  1222.     CSchemaDuration tmp(false, 0, 0, 0, -t2.m_nHour, -t2.m_nMinute, -t2.m_dSecond);
  1223.     CSchemaTime t = t1 + tmp;
  1224.     return CSchemaDuration(true, 0, 0, 0, t.m_nHour, t.m_nMinute, t.m_dSecond);
  1225. }
  1226.  
  1227.  
  1228. ////////////////////////////////////////////////////////////////////////
  1229. //
  1230. //  CSchemaDateTime
  1231. //
  1232. ////////////////////////////////////////////////////////////////////////
  1233.  
  1234.  
  1235. CSchemaDateTime::CSchemaDateTime(int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1236. {
  1237.     m_nYear        = nYear;
  1238.     m_nMonth    = nMonth;
  1239.     m_nDay        = nDay;
  1240.     m_nHour        = nHour;
  1241.     m_nMinute    = nMinute;
  1242.     m_dSecond    = dSecond;
  1243. }
  1244.  
  1245.  
  1246. CSchemaDateTime::CSchemaDateTime(int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond, int nOffset) : CSchemaDateTimeBase(nOffset)
  1247. {
  1248.     m_nYear        = nYear;
  1249.     m_nMonth    = nMonth;
  1250.     m_nDay        = nDay;
  1251.     m_nHour        = nHour;
  1252.     m_nMinute    = nMinute;
  1253.     m_dSecond    = dSecond;
  1254. }
  1255.  
  1256.  
  1257. CSchemaDateTime::CSchemaDateTime(const TCHAR* szValue) : CSchemaDateTimeBase()
  1258. {
  1259.     Parse(szValue);
  1260. }
  1261.  
  1262.  
  1263. CSchemaDateTime::operator tstring() const
  1264. {
  1265.     TCHAR szTmp\[64\];
  1266.     int nPos = _stprintf(szTmp, _T("%04i-%02i-%02iT"), m_nYear, m_nMonth, m_nDay);
  1267.     nPos += WriteTime(szTmp + nPos, m_nHour, m_nMinute, m_dSecond);
  1268.     WriteTZ(szTmp + nPos);
  1269.     return szTmp;
  1270. }
  1271.  
  1272.  
  1273. int CSchemaDateTime::GetYear() const
  1274. {
  1275.     return m_nYear;
  1276. }
  1277.  
  1278.  
  1279. int CSchemaDateTime::GetMonth() const
  1280. {
  1281.     return m_nMonth;
  1282. }
  1283.  
  1284.  
  1285. int CSchemaDateTime::GetDay() const
  1286. {
  1287.     return m_nDay;
  1288. }
  1289.  
  1290.  
  1291. int CSchemaDateTime::GetHour() const
  1292. {
  1293.     return m_nHour;
  1294. }
  1295.  
  1296.  
  1297. int CSchemaDateTime::GetMinute() const
  1298. {
  1299.     return m_nMinute;
  1300. }
  1301.  
  1302.  
  1303. double CSchemaDateTime::GetSecond() const
  1304. {
  1305.     return m_dSecond;
  1306. }
  1307.  
  1308.  
  1309. void CSchemaDateTime::SetYear(int nYear)
  1310. {
  1311.     m_nYear = nYear;
  1312. }
  1313.  
  1314.  
  1315. void CSchemaDateTime::SetMonth(int nMonth)
  1316. {
  1317.     m_nMonth = nMonth;
  1318. }
  1319.  
  1320.  
  1321. void CSchemaDateTime::SetDay(int nDay)
  1322. {
  1323.     m_nDay = nDay;
  1324. }
  1325.  
  1326.  
  1327. void CSchemaDateTime::SetHour(int nHour)
  1328. {
  1329.     m_nHour = nHour;
  1330. }
  1331.  
  1332.  
  1333. void CSchemaDateTime::SetMinute(int nMinute)
  1334. {
  1335.     m_nMinute = nMinute;
  1336. }
  1337.  
  1338.  
  1339. void CSchemaDateTime::SetSecond(double dSecond)
  1340. {
  1341.     m_dSecond = dSecond;
  1342. }
  1343.  
  1344.  
  1345. void CSchemaDateTime::Parse(const TCHAR* szValue)
  1346. {
  1347.     const TCHAR* szTmp = szValue;
  1348.  
  1349.     m_nYear = ParseInt(&szTmp);
  1350.     ParseChar(&szTmp, _T('-'));
  1351.     m_nMonth = ParseInt(&szTmp);
  1352.     ParseChar(&szTmp, _T('-'));
  1353.     m_nDay = ParseInt(&szTmp);
  1354.     ParseChar(&szTmp, _T('T'));
  1355.     m_nHour = ParseInt(&szTmp);
  1356.     ParseChar(&szTmp, _T(':'));
  1357.     m_nMinute = ParseInt(&szTmp);
  1358.     ParseChar(&szTmp, _T(':'));
  1359.     m_dSecond = ParseDouble(&szTmp);
  1360.     ParseTZ(szTmp);
  1361. }
  1362.  
  1363.  
  1364. bool operator==(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1365. {
  1366.     if (t1.HasTimezone() == t2.HasTimezone())
  1367.         return t1.m_nYear == t2.m_nYear
  1368.             && t1.m_nMonth == t2.m_nMonth
  1369.             && t1.m_nDay == t2.m_nDay
  1370.             && t1.m_nHour == t2.m_nHour
  1371.             && t1.m_nMinute == t2.m_nMinute
  1372.             && t1.m_dSecond == t2.m_dSecond;
  1373.     else
  1374.         return false;
  1375. }
  1376.  
  1377.  
  1378. bool operator<(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1379. {
  1380.     CSchemaDateTime x1 = t1;
  1381.     CSchemaDateTime x2 = t2;
  1382.  
  1383.     if (t1.HasTimezone() != t2.HasTimezone())
  1384.     {
  1385.         if (t1.HasTimezone())
  1386.         {
  1387.             CSchemaDuration dur(false, 0, 0, 0, -14, 0, 0);
  1388.             DateTimeAddDuration(x2.m_nYear, x2.m_nMonth, x2.m_nDay, x2.m_nHour, x2.m_nMinute, x2.m_dSecond, dur);
  1389.         }
  1390.         else
  1391.         {
  1392.             CSchemaDuration dur(true, 0, 0, 0, 14, 0, 0);
  1393.             DateTimeAddDuration(x1.m_nYear, x2.m_nMonth, x2.m_nDay, x2.m_nHour, x2.m_nMinute, x2.m_dSecond, dur);
  1394.         }
  1395.     }
  1396.  
  1397.     if (x1.m_nYear        < x2.m_nYear)    return true;
  1398.     if (x1.m_nYear        > x2.m_nYear)    return false;
  1399.     if (x1.m_nMonth        < x2.m_nMonth)    return true;
  1400.     if (x1.m_nMonth        > x2.m_nMonth)    return false;
  1401.     if (x1.m_nDay        < x2.m_nDay)    return true;
  1402.     if (x1.m_nDay        > x2.m_nDay)    return false;
  1403.     if (x1.m_nHour        < x2.m_nHour)    return true;
  1404.     if (x1.m_nHour        > x2.m_nHour)    return false;
  1405.     if (x1.m_nMinute    < x2.m_nMinute)    return true;
  1406.     if (x1.m_nMinute    > x2.m_nMinute)    return false;
  1407.     if (x1.m_dSecond    < x2.m_dSecond)    return true;
  1408.     return false;
  1409. }
  1410.  
  1411.  
  1412. bool operator!=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1413. {
  1414.     return !(t1 == t2);
  1415. }
  1416.  
  1417.  
  1418. bool operator<=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1419. {
  1420.     return t1 < t2 || t1 == t2;
  1421. }
  1422.  
  1423.  
  1424. bool operator>(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1425. {
  1426.     return t2 < t1;
  1427. }
  1428.  
  1429.  
  1430. bool operator>=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1431. {
  1432.     return t2 < t1 || t1 == t2;
  1433. }
  1434.  
  1435.  
  1436. CSchemaDateTime operator+(const CSchemaDateTime& t, const CSchemaDuration& dur)
  1437. {
  1438.     CSchemaDateTime r = t;
  1439.     DateTimeAddDuration(r.m_nYear, r.m_nMonth, r.m_nDay, r.m_nHour, r.m_nMinute, r.m_dSecond, dur);
  1440.     return r;
  1441. }
  1442.  
  1443.  
  1444. CSchemaDuration operator-(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
  1445. {
  1446.     CSchemaDuration tmp(false, -t2.m_nYear, -t2.m_nMonth, -t2.m_nDay, -t2.m_nHour, -t2.m_nMinute, -t2.m_dSecond);
  1447.     CSchemaDateTime t = t1 + tmp;
  1448.     return CSchemaDuration(true, t.m_nYear, t.m_nMonth, t.m_nDay, t.m_nHour, t.m_nMinute, t.m_dSecond);
  1449. }
  1450.  
  1451.  
  1452. ////////////////////////////////////////////////////////////////////////
  1453. //
  1454. //  CSchemaYear
  1455. //
  1456. ////////////////////////////////////////////////////////////////////////
  1457.  
  1458.  
  1459. CSchemaYear::CSchemaYear(int nYear, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1460. {
  1461.     m_nYear = nYear;
  1462. }
  1463.  
  1464.  
  1465. CSchemaYear::CSchemaYear(int nYear, int nOffset) : CSchemaDateTimeBase(nOffset)
  1466. {
  1467.     m_nYear = nYear;
  1468. }
  1469.  
  1470.  
  1471. CSchemaYear::CSchemaYear(const TCHAR* szValue) : CSchemaDateTimeBase()
  1472. {
  1473.     Parse(szValue);
  1474. }
  1475.  
  1476.  
  1477. CSchemaYear::operator tstring() const
  1478. {
  1479.     TCHAR szTmp\[32\];
  1480.     int nPos = _stprintf(szTmp, _T("%04i"), m_nYear);
  1481.     WriteTZ(szTmp + nPos);
  1482.     return szTmp;
  1483. }
  1484.  
  1485.  
  1486. int CSchemaYear::GetYear() const
  1487. {
  1488.     return m_nYear;
  1489. }
  1490.  
  1491.  
  1492. void CSchemaYear::SetYear(int nYear)
  1493. {
  1494.     m_nYear = nYear;
  1495. }
  1496.  
  1497.  
  1498. void CSchemaYear::Parse(const TCHAR* szValue)
  1499. {
  1500.     const TCHAR* szTmp = szValue;
  1501.  
  1502.     m_nYear = ParseInt(&szTmp);
  1503.     ParseTZ(szTmp);
  1504. }
  1505.  
  1506.  
  1507. ////////////////////////////////////////////////////////////////////////
  1508. //
  1509. //  CSchemaYearMonth
  1510. //
  1511. ////////////////////////////////////////////////////////////////////////
  1512.  
  1513.  
  1514. CSchemaYearMonth::CSchemaYearMonth(int nYear, int nMonth, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1515. {
  1516.     m_nYear        = nYear;
  1517.     m_nMonth    = nMonth;
  1518. }
  1519.  
  1520.  
  1521. CSchemaYearMonth::CSchemaYearMonth(int nYear, int nMonth, int nOffset) : CSchemaDateTimeBase(nOffset)
  1522. {
  1523.     m_nYear        = nYear;
  1524.     m_nMonth    = nMonth;
  1525. }
  1526.  
  1527.  
  1528. CSchemaYearMonth::CSchemaYearMonth(const TCHAR* szValue) : CSchemaDateTimeBase()
  1529. {
  1530.     Parse(szValue);
  1531. }
  1532.  
  1533.  
  1534. CSchemaYearMonth::operator tstring() const
  1535. {
  1536.     TCHAR szTmp\[32\];
  1537.     int nPos = _stprintf(szTmp, _T("%04i-%02i"), m_nYear, m_nMonth);
  1538.     WriteTZ(szTmp + nPos);
  1539.     return szTmp;
  1540. }
  1541.  
  1542.  
  1543. int CSchemaYearMonth::GetYear() const
  1544. {
  1545.     return m_nYear;
  1546. }
  1547.  
  1548.  
  1549. int CSchemaYearMonth::GetMonth() const
  1550. {
  1551.     return m_nMonth;
  1552. }
  1553.  
  1554.  
  1555. void CSchemaYearMonth::SetYear(int nYear)
  1556. {
  1557.     m_nYear = nYear;
  1558. }
  1559.  
  1560.  
  1561. void CSchemaYearMonth::SetMonth(int nMonth)
  1562. {
  1563.     m_nMonth = nMonth;
  1564. }
  1565.  
  1566.  
  1567. void CSchemaYearMonth::Parse(const TCHAR* szValue)
  1568. {
  1569.     const TCHAR* szTmp = szValue;
  1570.  
  1571.     m_nYear = ParseInt(&szTmp);
  1572.     ParseChar(&szTmp, _T('-'));
  1573.     m_nMonth = ParseInt(&szTmp);
  1574.     ParseTZ(szTmp);
  1575. }
  1576.  
  1577.  
  1578. ////////////////////////////////////////////////////////////////////////
  1579. //
  1580. //  CSchemaMonth
  1581. //
  1582. ////////////////////////////////////////////////////////////////////////
  1583.  
  1584.  
  1585. CSchemaMonth::CSchemaMonth(int nMonth, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1586. {
  1587.     m_nMonth = nMonth;
  1588. }
  1589.  
  1590.  
  1591. CSchemaMonth::CSchemaMonth(int nMonth, int nOffset) : CSchemaDateTimeBase(nOffset)
  1592. {
  1593.     m_nMonth = nMonth;
  1594. }
  1595.  
  1596.  
  1597. CSchemaMonth::CSchemaMonth(const TCHAR* szValue) : CSchemaDateTimeBase()
  1598. {
  1599.     Parse(szValue);
  1600. }
  1601.  
  1602.  
  1603. CSchemaMonth::operator tstring() const
  1604. {
  1605.     TCHAR szTmp\[32\];
  1606.     int nPos = _stprintf(szTmp, _T("--%02i--"), m_nMonth);
  1607.     WriteTZ(szTmp + nPos);
  1608.     return szTmp;
  1609. }
  1610.  
  1611.  
  1612. int CSchemaMonth::GetMonth() const
  1613. {
  1614.     return m_nMonth;
  1615. }
  1616.  
  1617.  
  1618. void CSchemaMonth::SetMonth(int nMonth)
  1619. {
  1620.     m_nMonth = nMonth;
  1621. }
  1622.  
  1623.  
  1624. void CSchemaMonth::Parse(const TCHAR* szValue)
  1625. {
  1626.     const TCHAR* szTmp = szValue;
  1627.  
  1628.     ParseChar(&szTmp, _T('-'));
  1629.     ParseChar(&szTmp, _T('-'));
  1630.     m_nMonth = ParseInt(&szTmp);
  1631.     ParseChar(&szTmp, _T('-'));
  1632.     ParseChar(&szTmp, _T('-'));
  1633.     ParseTZ(szTmp);
  1634. }
  1635.  
  1636.  
  1637. ////////////////////////////////////////////////////////////////////////
  1638. //
  1639. //  CSchemaMonthDay
  1640. //
  1641. ////////////////////////////////////////////////////////////////////////
  1642.  
  1643.  
  1644. CSchemaMonthDay::CSchemaMonthDay(int nMonth, int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1645. {
  1646.     m_nMonth    = nMonth;
  1647.     m_nDay        = nDay;
  1648. }
  1649.  
  1650.  
  1651. CSchemaMonthDay::CSchemaMonthDay(int nMonth, int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
  1652. {
  1653.     m_nMonth    = nMonth;
  1654.     m_nDay        = nDay;
  1655. }
  1656.  
  1657.  
  1658. CSchemaMonthDay::CSchemaMonthDay(const TCHAR* szValue) : CSchemaDateTimeBase()
  1659. {
  1660.     Parse(szValue);
  1661. }
  1662.  
  1663.  
  1664. CSchemaMonthDay::operator tstring() const
  1665. {
  1666.     TCHAR szTmp\[32\];
  1667.     int nPos = _stprintf(szTmp, _T("--%02i-%02i"), m_nMonth, m_nDay);
  1668.     WriteTZ(szTmp + nPos);
  1669.     return szTmp;
  1670. }
  1671.  
  1672.  
  1673. int CSchemaMonthDay::GetMonth() const
  1674. {
  1675.     return m_nMonth;
  1676. }
  1677.  
  1678.  
  1679. int CSchemaMonthDay::GetDay() const
  1680. {
  1681.     return m_nDay;
  1682. }
  1683.  
  1684.  
  1685. void CSchemaMonthDay::SetMonth(int nMonth)
  1686. {
  1687.     m_nMonth = nMonth;
  1688. }
  1689.  
  1690.  
  1691. void CSchemaMonthDay::SetDay(int nDay)
  1692. {
  1693.     m_nDay = nDay;
  1694. }
  1695.  
  1696.  
  1697. void CSchemaMonthDay::Parse(const TCHAR* szValue)
  1698. {
  1699.     const TCHAR* szTmp = szValue;
  1700.  
  1701.     ParseChar(&szTmp, _T('-'));
  1702.     ParseChar(&szTmp, _T('-'));
  1703.     m_nMonth = ParseInt(&szTmp);
  1704.     ParseChar(&szTmp, _T('-'));
  1705.     m_nDay = ParseInt(&szTmp);
  1706.     ParseTZ(szTmp);
  1707. }
  1708.  
  1709.  
  1710. ////////////////////////////////////////////////////////////////////////
  1711. //
  1712. //  CSchemaDay
  1713. //
  1714. ////////////////////////////////////////////////////////////////////////
  1715.  
  1716.  
  1717. CSchemaDay::CSchemaDay(int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
  1718. {
  1719.     m_nDay = nDay;
  1720. }
  1721.  
  1722.  
  1723. CSchemaDay::CSchemaDay(int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
  1724. {
  1725.     m_nDay = nDay;
  1726. }
  1727.  
  1728.  
  1729. CSchemaDay::CSchemaDay(const TCHAR* szValue) : CSchemaDateTimeBase()
  1730. {
  1731.     Parse(szValue);
  1732. }
  1733.  
  1734.  
  1735. CSchemaDay::operator tstring() const
  1736. {
  1737.     TCHAR szTmp\[32\];
  1738.     int nPos = _stprintf(szTmp, _T("---%02i"), m_nDay);
  1739.     WriteTZ(szTmp + nPos);
  1740.     return szTmp;
  1741. }
  1742.  
  1743.  
  1744.  
  1745. int CSchemaDay::GetDay() const
  1746. {
  1747.     return m_nDay;
  1748. }
  1749.  
  1750.  
  1751. void CSchemaDay::SetDay(int nDay)
  1752. {
  1753.     m_nDay = nDay;
  1754. }
  1755.  
  1756.  
  1757. void CSchemaDay::Parse(const TCHAR* szValue)
  1758. {
  1759.     const TCHAR* szTmp = szValue;
  1760.  
  1761.     ParseChar(&szTmp, _T('-'));
  1762.     ParseChar(&szTmp, _T('-'));
  1763.     ParseChar(&szTmp, _T('-'));
  1764.     m_nDay = ParseInt(&szTmp);
  1765.     ParseTZ(szTmp);
  1766. }
  1767.  
  1768.  
  1769. ////////////////////////////////////////////////////////////////////////
  1770. //
  1771. //  CSchemaHexBinary
  1772. //
  1773. ////////////////////////////////////////////////////////////////////////
  1774.  
  1775.  
  1776. const TCHAR CSchemaHexBinary::sm_EncodeArray\[\] =
  1777.     _T("0123456789abcdef");
  1778.  
  1779.  
  1780. const TCHAR CSchemaHexBinary::sm_DecodeArray\[\] =
  1781. {
  1782.  
  1783.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1784.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1785.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1786.      0,     1,     2,     3,     4,     5,     6,     7,     8,     9,    -1,    -1,    -1,    -1,    -1,    -1,
  1787.     -1,    10,    11,    12,    13,    14,    15,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1788.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1789.     -1,    10,    11,    12,    13,    14,    15,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1790.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1791.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1792.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1793.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1794.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1795.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1796.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1797.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1798.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1
  1799. };
  1800.  
  1801.  
  1802. CSchemaHexBinary::CSchemaHexBinary(const CSchemaHexBinary& rOther)
  1803. {
  1804.     Clone(rOther);
  1805. }
  1806.  
  1807.  
  1808. CSchemaHexBinary::CSchemaHexBinary(const unsigned char* pData, int nSize)
  1809. {
  1810.     Clone(pData, nSize);
  1811. }
  1812.  
  1813.  
  1814. CSchemaHexBinary::CSchemaHexBinary(const TCHAR* szValue)
  1815. {
  1816.     Parse(szValue);
  1817. }
  1818.  
  1819.  
  1820. CSchemaHexBinary::~CSchemaHexBinary()
  1821. {
  1822.     if (m_pData)
  1823.     {
  1824.         delete\[\] m_pData;
  1825.         m_pData = NULL;
  1826.     }
  1827. }
  1828.  
  1829.  
  1830. CSchemaHexBinary& CSchemaHexBinary::operator=(const CSchemaHexBinary& rOther)
  1831. {
  1832.     Clone(rOther);
  1833.     return *this;
  1834. }
  1835.  
  1836.  
  1837. CSchemaHexBinary::operator tstring() const
  1838. {
  1839.     if (m_pData == NULL)
  1840.     {
  1841.         return _T("");
  1842.     }
  1843.  
  1844.     tstring s;
  1845.     s.reserve(m_nSize * 2);
  1846.     const unsigned char* pReader = m_pData;
  1847.     for (int i = 0; i < m_nSize; i++)
  1848.     {
  1849.         s += sm_EncodeArray\[*pReader >> 4\];
  1850.         s += sm_EncodeArray\[*pReader & 0xF\];
  1851.         pReader++;
  1852.     }
  1853.     return s;
  1854. }
  1855.  
  1856.  
  1857. int CSchemaHexBinary::GetSize() const
  1858. {
  1859.     return m_nSize;
  1860. }
  1861.  
  1862.  
  1863. const unsigned char* CSchemaHexBinary::GetData() const
  1864. {
  1865.     return m_pData;
  1866. }
  1867.  
  1868.  
  1869. unsigned char* CSchemaHexBinary::GetData()
  1870. {
  1871.     return m_pData;
  1872. }
  1873.  
  1874.  
  1875. void CSchemaHexBinary::SetData(const unsigned char* pData, int nSize)
  1876. {
  1877.     if (m_pData)
  1878.         delete\[\] m_pData;
  1879.     Clone(pData, nSize);
  1880. }
  1881.  
  1882.  
  1883. void CSchemaHexBinary::Clone(const CSchemaHexBinary& rOther)
  1884. {
  1885.     m_nSize = rOther.m_nSize;
  1886.     if (m_nSize == 0)
  1887.     {
  1888.         m_pData = NULL;
  1889.         return;
  1890.     }
  1891.     m_pData = new unsigned char\[m_nSize\];
  1892.     memcpy(m_pData, rOther.m_pData, m_nSize);
  1893. }
  1894.  
  1895.  
  1896. void CSchemaHexBinary::Clone(const unsigned char* pData, int nSize)
  1897. {
  1898.     m_nSize = nSize;
  1899.     if (m_nSize == 0)
  1900.     {
  1901.         m_pData = NULL;
  1902.         return;
  1903.     }
  1904.     m_pData = new unsigned char\[m_nSize\];
  1905.     memcpy(m_pData, pData, m_nSize);
  1906. }
  1907.  
  1908.  
  1909. void CSchemaHexBinary::Parse(const TCHAR* szValue)
  1910. {
  1911.     m_nSize = _tcslen(szValue) / 2;
  1912.     if (m_nSize == 0)
  1913.     {
  1914.         m_pData = NULL;
  1915.         return;
  1916.     }
  1917.     m_pData = new unsigned char\[m_nSize\];
  1918.  
  1919.     unsigned char* szDataWriter = m_pData;
  1920.     while (*szValue && *(szValue + 1))
  1921.     {
  1922.         char nDigit1 = sm_DecodeArray\[*szValue++\];
  1923.         char nDigit2 = sm_DecodeArray\[*szValue++\];
  1924.         if (nDigit1 == -1 ||nDigit2 == -1)
  1925.             ThrowFormatError();
  1926.         *szDataWriter++ = nDigit1 * 16 + nDigit2;
  1927.     }
  1928. }
  1929.  
  1930.  
  1931. ////////////////////////////////////////////////////////////////////////
  1932. //
  1933. //  CSchemaBase64Binary
  1934. //
  1935. ////////////////////////////////////////////////////////////////////////
  1936.  
  1937.  
  1938. const TCHAR CSchemaBase64Binary::sm_EncodeArray\[\] =
  1939.     _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
  1940.  
  1941.  
  1942. const TCHAR CSchemaBase64Binary::sm_DecodeArray\[\] =
  1943. {
  1944.  
  1945.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1946.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1947.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    62,    -1,    -1,    -1,    63,
  1948.     52,    53,    54,    55,    56,    57,    58,    59,    60,    61,    -1,    -1,    -1,    -1,    -1,    -1,
  1949.     -1,     0,     1,     2,     3,     4,     5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
  1950.     15,    16,    17,    18,    19,    20,    21,    22,    23,    24,    25,    -1,    -1,    -1,    -1,    -1,
  1951.     -1,    26,    27,    28,    29,    30,    31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
  1952.     41,    42,    43,    44,    45,    46,    47,    48,    49,    50,    51,    -1,    -1,    -1,    -1,    -1,
  1953.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1954.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1955.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1956.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1957.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1958.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1959.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
  1960.     -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1
  1961. };
  1962.  
  1963.  
  1964. CSchemaBase64Binary::CSchemaBase64Binary(const CSchemaBase64Binary& rOther)
  1965. {
  1966.     Clone(rOther);
  1967. }
  1968.  
  1969.  
  1970. CSchemaBase64Binary::CSchemaBase64Binary(const unsigned char* pData, int nSize)
  1971. {
  1972.     Clone(pData, nSize);
  1973. }
  1974.  
  1975.  
  1976. CSchemaBase64Binary::CSchemaBase64Binary(const TCHAR* szValue)
  1977. {
  1978.     Decode(szValue, m_pData, m_nSize);
  1979. }
  1980.  
  1981.  
  1982. CSchemaBase64Binary::~CSchemaBase64Binary()
  1983. {
  1984.     if (m_pData)
  1985.     {
  1986.         delete\[\] m_pData;
  1987.         m_pData = NULL;
  1988.     }
  1989. }
  1990.  
  1991.  
  1992. CSchemaBase64Binary& CSchemaBase64Binary::operator=(const CSchemaBase64Binary& rOther)
  1993. {
  1994.     Clone(rOther);
  1995.     return *this;
  1996. }
  1997.  
  1998.  
  1999. CSchemaBase64Binary::operator tstring() const
  2000. {
  2001.     if (m_pData == NULL)
  2002.     {
  2003.         return _T("");
  2004.     }
  2005.  
  2006.     tstring sResult;
  2007.     TCHAR* szDst;
  2008.     int nDstSize;
  2009.  
  2010.     Encode(m_pData, m_nSize, szDst, nDstSize);
  2011.     sResult = szDst;
  2012.     delete\[\] szDst;
  2013.     return sResult;
  2014. }
  2015.  
  2016.  
  2017. int CSchemaBase64Binary::GetSize() const
  2018. {
  2019.     return m_nSize;
  2020. }
  2021.  
  2022.  
  2023. const unsigned char* CSchemaBase64Binary::GetData() const
  2024. {
  2025.     return m_pData;
  2026. }
  2027.  
  2028.  
  2029. unsigned char* CSchemaBase64Binary::GetData()
  2030. {
  2031.     return m_pData;
  2032. }
  2033.  
  2034.  
  2035. void CSchemaBase64Binary::SetData(const unsigned char* pData, int nSize)
  2036. {
  2037.     if (m_pData)
  2038.         delete\[\] m_pData;
  2039.     Clone(pData, nSize);
  2040. }
  2041.  
  2042.  
  2043. void CSchemaBase64Binary::Clone(const CSchemaBase64Binary& rOther)
  2044. {
  2045.     m_nSize = rOther.m_nSize;
  2046.     if (m_nSize == 0)
  2047.     {
  2048.         m_pData = NULL;
  2049.         return;
  2050.     }
  2051.     m_pData = new unsigned char\[m_nSize\];
  2052.     memcpy(m_pData, rOther.m_pData, m_nSize);
  2053. }
  2054.  
  2055.  
  2056. void CSchemaBase64Binary::Clone(const unsigned char* pData, int nSize)
  2057. {
  2058.     m_nSize = nSize;
  2059.     if (m_nSize == 0)
  2060.     {
  2061.         m_pData = NULL;
  2062.         return;
  2063.     }
  2064.     m_pData = new unsigned char\[m_nSize\];
  2065.     memcpy(m_pData, pData, m_nSize);
  2066. }
  2067.  
  2068.  
  2069. void CSchemaBase64Binary::Encode(unsigned char* pSrc, int nSrcSize, TCHAR*& rszDst, int& rnDstSize, int nMaxLineLength) const
  2070. {
  2071.     int                nTmpSize, nAllocSize, nLineLength, i;
  2072.     TCHAR*            szDstWriter;
  2073.     unsigned long    bBuf;
  2074.  
  2075.     if (nSrcSize == 0)
  2076.     {
  2077.         rszDst = NULL;
  2078.         rnDstSize = 0;
  2079.         return;
  2080.     }
  2081.  
  2082.     nTmpSize    = nSrcSize * 4 / 3;
  2083.     nAllocSize    = nTmpSize + 8;
  2084.     if (nMaxLineLength > 0)
  2085.         nAllocSize += nTmpSize * 2 / nMaxLineLength;
  2086.     
  2087.     rszDst        = new TCHAR\[nAllocSize\];
  2088.     szDstWriter    = rszDst;
  2089.  
  2090.     nTmpSize    = nSrcSize / 3 * 3;
  2091.     rnDstSize    = 0;
  2092.     nLineLength    = 0;
  2093.  
  2094.     if (nMaxLineLength > 0)
  2095.     {
  2096.         for (i = 0; i < nTmpSize; i += 3)
  2097.         {
  2098.             bBuf = *(pSrc + i) << 16 | *(pSrc + i + 1) << 8 | *(pSrc + i + 2);
  2099.             *szDstWriter++ = sm_EncodeArray\[(bBuf >> 18) & 0x3F\];
  2100.             *szDstWriter++ = sm_EncodeArray\[(bBuf >> 12) & 0x3F\];
  2101.             *szDstWriter++ = sm_EncodeArray\[(bBuf >>  6) & 0x3F\];
  2102.             *szDstWriter++ = sm_EncodeArray\[ bBuf        & 0x3F\];
  2103.             rnDstSize += 4;
  2104.  
  2105.             nLineLength += 4;
  2106.             if (nMaxLineLength > 0 && nLineLength >= nMaxLineLength)
  2107.             {
  2108.                 *szDstWriter++ = _T('\\r');
  2109.                 *szDstWriter++ = _T('\\n');
  2110.                 rnDstSize += 2;
  2111.                 nLineLength = 0;
  2112.             }
  2113.         }
  2114.     }
  2115.     else
  2116.     {
  2117.         for (i = 0; i < nTmpSize; i += 3)
  2118.         {
  2119.             bBuf = *(pSrc + i) << 16 | *(pSrc + i + 1) << 8 | *(pSrc + i + 2);
  2120.             *szDstWriter++ = sm_EncodeArray\[(bBuf >> 18) & 0x3F\];
  2121.             *szDstWriter++ = sm_EncodeArray\[(bBuf >> 12) & 0x3F\];
  2122.             *szDstWriter++ = sm_EncodeArray\[(bBuf >>  6) & 0x3F\];
  2123.             *szDstWriter++ = sm_EncodeArray\[ bBuf        & 0x3F\];
  2124.             rnDstSize += 4;
  2125.         }
  2126.     }
  2127.  
  2128.     int nRest = nSrcSize - nTmpSize;
  2129.     if (nRest == 2)
  2130.     {
  2131.         bBuf = *(pSrc + i) << 8 | *(pSrc + i + 1);
  2132.         *szDstWriter++ = sm_EncodeArray\[(bBuf >> 10) & 0x3F\];
  2133.         *szDstWriter++ = sm_EncodeArray\[(bBuf >>  4) & 0x3F\];
  2134.         *szDstWriter++ = sm_EncodeArray\[(bBuf <<  2) & 0x3F\];
  2135.         *szDstWriter++ = _T('=');
  2136.         rnDstSize += 4;
  2137.     }
  2138.     else if (nRest == 1)
  2139.     {
  2140.         bBuf = *(pSrc + i);
  2141.         *szDstWriter++ = sm_EncodeArray\[(bBuf >>  2) & 0x3F\];
  2142.         *szDstWriter++ = sm_EncodeArray\[(bBuf <<  4) & 0x3F\];
  2143.         *szDstWriter++ = _T('=');
  2144.         *szDstWriter++ = _T('=');
  2145.         rnDstSize += 4;
  2146.     }
  2147.  
  2148.     *szDstWriter = 0;
  2149. }
  2150.  
  2151.  
  2152. void CSchemaBase64Binary::Decode(const TCHAR* szSrc, unsigned char*& rpDst, int& rnDstSize)
  2153. {
  2154.     int                nSrcSize;
  2155.     const TCHAR*    szSrcReader;
  2156.     unsigned char*    pDstWriter;
  2157.     unsigned long    nBuf;
  2158.     int                nCount;
  2159.  
  2160.     szSrcReader    = szSrc;
  2161.     while (*szSrcReader && sm_DecodeArray\[*szSrcReader\] == -1)
  2162.     {
  2163.         szSrcReader++;
  2164.     }
  2165.     nSrcSize = _tcslen(szSrcReader);
  2166.     if (nSrcSize == 0)
  2167.     {
  2168.         rpDst = NULL;
  2169.         rnDstSize = 0;
  2170.         return;
  2171.     }
  2172.  
  2173.     rpDst        = new unsigned char\[nSrcSize\];
  2174.     pDstWriter    = rpDst;
  2175.     rnDstSize    = 0;
  2176.     nBuf        = 0;
  2177.     nCount        = 0;
  2178.  
  2179.     while (*szSrcReader)
  2180.     {
  2181.         while (sm_DecodeArray\[*szSrcReader\] == -1)
  2182.         {
  2183.             if (!*++szSrcReader)
  2184.                 goto finish;
  2185.         }
  2186.  
  2187.         nBuf |= sm_DecodeArray\[*szSrcReader++\];
  2188.  
  2189.         if (++nCount == 4)
  2190.         {
  2191.             *pDstWriter++ = (unsigned char)(nBuf >> 16);
  2192.             *pDstWriter++ = (unsigned char)(nBuf >>  8);
  2193.             *pDstWriter++ = (unsigned char) nBuf;
  2194.             rnDstSize += 3;
  2195.             nBuf = 0;
  2196.             nCount = 0;
  2197.         }
  2198.         else
  2199.         {
  2200.             nBuf <<= 6;
  2201.         }
  2202.     }
  2203.  
  2204. finish:
  2205.     if (nCount == 2)
  2206.     {
  2207.         *pDstWriter++ = (unsigned char)(nBuf >> 10);
  2208.         rnDstSize++;
  2209.     }
  2210.     else if (nCount == 3)
  2211.     {
  2212.         *pDstWriter++ = (unsigned char)(nBuf >> 16) & 0xFF;
  2213.         *pDstWriter++ = (unsigned char)(nBuf >>  8) & 0xFF;
  2214.         rnDstSize += 2;
  2215.     }
  2216. }
  2217.  
  2218.  
  2219. } // namespace altova
  2220.