home *** CD-ROM | disk | FTP | other *** search
Text File | 2003-05-21 | 42.3 KB | 2,220 lines |
- ////////////////////////////////////////////////////////////////////////
- //
- // SchemaTypes.cpp
- //
- // This file was generated by XMLSPY 5 Enterprise Edition.
- //
- // YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
- // OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
- //
- // Refer to the XMLSPY Documentation for further details.
- // http://www.altova.com/xmlspy
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- #include "StdAfx.h"
- #include "SchemaTypes.h"
- #include "XmlException.h"
- #include <math.h>
-
-
- namespace altova {
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaBoolean
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaBoolean::CSchemaBoolean(bool value) : m_Value(value)
- {
- }
-
-
- CSchemaBoolean::CSchemaBoolean(const TCHAR* szValue)
- {
- m_Value = _tcscmp(szValue, _T("true")) == 0 || _tcscmp(szValue, _T("1")) == 0;
- }
-
-
- CSchemaBoolean::operator bool() const
- {
- return m_Value;
- }
-
-
- CSchemaBoolean::operator tstring() const
- {
- return m_Value ? _T("true") : _T("false");
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaFloat
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaFloat::CSchemaFloat(float value) : m_Value(value)
- {
- }
-
-
- CSchemaFloat::CSchemaFloat(const TCHAR* szValue)
- {
- TCHAR* endptr;
- m_Value = _tcstod(szValue, &endptr);
- }
-
-
- CSchemaFloat::operator float() const
- {
- return m_Value;
- }
-
-
- CSchemaFloat::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%G"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDouble
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDouble::CSchemaDouble(double value) : m_Value(value)
- {
- }
-
-
- CSchemaDouble::CSchemaDouble(const TCHAR* szValue)
- {
- TCHAR* endptr;
- m_Value = _tcstod(szValue, &endptr);
- }
-
-
- CSchemaDouble::operator double() const
- {
- return m_Value;
- }
-
-
- CSchemaDouble::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%lG"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDecimal
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDecimal::CSchemaDecimal(double value) : m_Value(value)
- {
- }
-
-
- CSchemaDecimal::CSchemaDecimal(const TCHAR* szValue)
- {
- TCHAR* endptr;
- m_Value = _tcstod(szValue, &endptr);
- }
-
-
- CSchemaDecimal::operator double() const
- {
- return m_Value;
- }
-
-
- CSchemaDecimal::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%f"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaLong
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaLong::CSchemaLong(__int64 nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaLong::CSchemaLong(const TCHAR* szValue)
- {
- m_Value = _ttoi64(szValue);
- }
-
-
- CSchemaLong::operator __int64() const
- {
- return m_Value;
- }
-
-
- CSchemaLong::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%I64i"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaUnsignedLong
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaUnsignedLong::CSchemaUnsignedLong(unsigned __int64 nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaUnsignedLong::CSchemaUnsignedLong(const TCHAR* szValue)
- {
- m_Value = _ttoi64(szValue);
- }
-
-
- CSchemaUnsignedLong::operator unsigned __int64() const
- {
- return m_Value;
- }
-
-
- CSchemaUnsignedLong::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%I64u"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaInt
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaInt::CSchemaInt(long nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaInt::CSchemaInt(const TCHAR* szValue)
- {
- m_Value = _ttol(szValue);
- }
-
-
- CSchemaInt::operator long() const
- {
- return m_Value;
- }
-
-
- CSchemaInt::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%li"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaUnsignedInt
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaUnsignedInt::CSchemaUnsignedInt(unsigned long nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaUnsignedInt::CSchemaUnsignedInt(const TCHAR* szValue)
- {
- m_Value = _ttol(szValue);
- }
-
-
- CSchemaUnsignedInt::operator unsigned long() const
- {
- return m_Value;
- }
-
-
- CSchemaUnsignedInt::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%lu"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaShort
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaShort::CSchemaShort(short nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaShort::CSchemaShort(const TCHAR* szValue)
- {
- m_Value = _ttoi(szValue);
- }
-
-
- CSchemaShort::operator short() const
- {
- return m_Value;
- }
-
-
- CSchemaShort::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%hi"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaUnsignedShort
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaUnsignedShort::CSchemaUnsignedShort(unsigned short nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaUnsignedShort::CSchemaUnsignedShort(const TCHAR* szValue)
- {
- m_Value = _ttoi(szValue);
- }
-
-
- CSchemaUnsignedShort::operator unsigned short() const
- {
- return m_Value;
- }
-
-
- CSchemaUnsignedShort::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%hu"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaByte
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaByte::CSchemaByte(char nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaByte::CSchemaByte(const TCHAR* szValue)
- {
- m_Value = _ttoi(szValue);
- }
-
-
- CSchemaByte::operator char() const
- {
- return m_Value;
- }
-
-
- CSchemaByte::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%hi"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaUnsignedByte
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaUnsignedByte::CSchemaUnsignedByte(unsigned char nValue) : m_Value(nValue)
- {
- }
-
-
- CSchemaUnsignedByte::CSchemaUnsignedByte(const TCHAR* szValue)
- {
- m_Value = _ttoi(szValue);
- }
-
-
- CSchemaUnsignedByte::operator unsigned char() const
- {
- return m_Value;
- }
-
-
- CSchemaUnsignedByte::operator tstring() const
- {
- TCHAR szValue\[32\];
- _sntprintf(szValue, 32, _T("%hu"), m_Value);
- return szValue;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaString
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaString::CSchemaString(tstring sValue) : m_Value(sValue)
- {
- }
-
-
- CSchemaString::CSchemaString(const TCHAR* szValue) : m_Value(szValue)
- {
- }
-
-
- CSchemaString::operator tstring() const
- {
- return m_Value;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Utility functions
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- void ThrowFormatError()
- {
- throw CXmlException(CXmlException::eError1, _T("Format error"));
- }
-
-
- int ParseInt(const TCHAR** pszData)
- {
- TCHAR* szEndPtr;
- int n = _tcstol(*pszData, &szEndPtr, 10);
- if (*pszData == szEndPtr)
- ThrowFormatError();
- *pszData = szEndPtr;
- return n;
- }
-
-
- double ParseDouble(const TCHAR** pszData)
- {
- TCHAR* szEndPtr;
- double d = _tcstod(*pszData, &szEndPtr);
- if (*pszData == szEndPtr)
- ThrowFormatError();
- *pszData = szEndPtr;
- return d;
- }
-
-
- void ParseChar(const TCHAR** pszData, TCHAR chValue)
- {
- if (**pszData != chValue)
- ThrowFormatError();
- (*pszData)++;
- }
-
-
- int fQuotient(int a, int b)
- {
- return div(a, b).quot;
- }
-
-
- int modulo(int a, int b)
- {
- return a - fQuotient(a, b) * b;
- }
-
-
- double modulo(double a, double b)
- {
- return a - fQuotient(a, b) * b;
- }
-
-
- int fQuotient(int a, int low, int high)
- {
- return fQuotient(a - low, high - low);
- }
-
-
- int modulo(int a, int low, int high)
- {
- return modulo(a - low, high - low) + low;
- }
-
-
- bool isLeapYear(int year)
- {
- return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
- }
-
-
- int maxDayInMonthFor(int year, int month)
- {
- if (month == 4 || month == 6 || month == 9 || month == 11)
- return 30;
- else if (month == 2)
- return isLeapYear(year) ? 29 : 28;
- else
- return 31;
- }
-
-
- void DateTimeAddDuration(int& nYear, int& nMonth, int& nDay, int& nHour, int& nMinute, double& dSecond, const CSchemaDuration& dur)
- {
- int temp = nMonth + dur.GetMonth();
- nMonth = modulo(temp, 1, 13);
- int carry = fQuotient(temp, 1, 13);
-
- nYear += dur.GetYear() + carry;
-
- double dtemp = dSecond + dur.GetSecond();
- dSecond = modulo(dtemp, 60.0);
- carry = fQuotient(dtemp, 60);
-
- temp = nMinute + dur.GetMinute() + carry;
- nMinute = modulo(temp, 60);
- carry = fQuotient(temp, 60);
-
- temp = nHour + dur.GetHour() + carry;
- nHour = modulo(temp, 24);
- carry = fQuotient(temp, 24);
-
- nDay += dur.GetDay() + carry;
-
- while (true)
- {
- temp = maxDayInMonthFor(nYear, nMonth);
- if (nDay < 1)
- {
- nDay += maxDayInMonthFor(nYear, nMonth - 1);
- carry = -1;
- }
- else if (nDay > temp)
- {
- nDay -= temp;
- carry = 1;
- }
- else
- {
- break;
- }
-
- temp = nMonth + carry;
- nMonth = modulo(temp, 1, 13);
- nYear += fQuotient(temp, 1, 13);
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDuration
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDuration::CSchemaDuration(bool bPositive, int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond)
- {
- m_bPositive = bPositive;
- m_nYear = nYear;
- m_nMonth = nMonth;
- m_nDay = nDay;
- m_nHour = nHour;
- m_nMinute = nMinute;
- m_dSecond = dSecond;
- }
-
-
- CSchemaDuration::CSchemaDuration(const TCHAR* szValue)
- {
- Parse(szValue);
- }
-
-
- CSchemaDuration::operator tstring() const
- {
- TCHAR szResult\[64\];
- TCHAR* szTmp = szResult;
-
- if (!m_bPositive)
- *szTmp++ = _T('-');
- *szTmp++ = _T('P');
- if (m_nYear != 0)
- szTmp += _stprintf(szTmp, _T("%iY"), abs(m_nYear));
- if (m_nMonth != 0)
- szTmp += _stprintf(szTmp, _T("%iM"), abs(m_nMonth));
- if (m_nDay != 0)
- szTmp += _stprintf(szTmp, _T("%iD"), abs(m_nDay));
- if (m_nHour != 0 || m_nMinute != 0 || m_dSecond != 0)
- {
- *szTmp++ = _T('T');
- if (m_nHour != 0)
- szTmp += _stprintf(szTmp, _T("%iH"), abs(m_nHour));
- if (m_nMinute != 0)
- szTmp += _stprintf(szTmp, _T("%iM"), abs(m_nMinute));
- if (m_dSecond != 0)
- {
- double d = m_dSecond < 0 ? m_dSecond * -1 : m_dSecond;
- if (m_dSecond - floor(m_dSecond) == 0)
- {
- szTmp += _stprintf(szTmp, _T("%01.f"), d);
- }
- else
- {
- szTmp += _stprintf(szTmp, _T("%.9f"), d);
- while (*(szTmp-1) == _T('0'))
- *--szTmp = 0;
- }
- *szTmp++ = _T('S');
- }
- }
- *szTmp = 0;
-
- return szResult;
- }
-
-
- bool CSchemaDuration::IsPositive() const
- {
- return m_bPositive;
- }
-
-
- int CSchemaDuration::GetYear() const
- {
- return m_nYear;
- }
-
-
- int CSchemaDuration::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- int CSchemaDuration::GetDay() const
- {
- return m_nDay;
- }
-
-
- int CSchemaDuration::GetHour() const
- {
- return m_nHour;
- }
-
-
- int CSchemaDuration::GetMinute() const
- {
- return m_nMinute;
- }
-
-
- double CSchemaDuration::GetSecond() const
- {
- return m_dSecond;
- }
-
-
- void CSchemaDuration::SetPositive(bool bPositive)
- {
- m_bPositive = bPositive;
- }
-
-
- void CSchemaDuration::SetYear(int nYear)
- {
- m_nYear = nYear;
- }
-
-
- void CSchemaDuration::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaDuration::SetDay(int nDay)
- {
- m_nDay = nDay;
- }
-
-
- void CSchemaDuration::SetHour(int nHour)
- {
- m_nHour = nHour;
- }
-
-
- void CSchemaDuration::SetMinute(int nMinute)
- {
- m_nMinute = nMinute;
- }
-
-
- void CSchemaDuration::SetSecond(double dSecond)
- {
- m_dSecond = dSecond;
- }
-
-
- void CSchemaDuration::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
- bool bTime = false;
- int nTmp;
-
- m_bPositive = *szTmp != _T('-');
- int nSign = m_bPositive ? 1 : -1;
- ParseChar(&szTmp, _T('P'));
-
- while (*szTmp)
- {
- if (*szTmp == _T('T'))
- {
- if (bTime)
- ThrowFormatError();
- szTmp++;
- bTime = true;
- }
- nTmp = ParseInt(&szTmp);
- if (!bTime)
- {
- switch (*szTmp)
- {
- case _T('Y'): m_nYear = nTmp * nSign; break;
- case _T('M'): m_nMonth = nTmp * nSign; break;
- case _T('D'): m_nDay = nTmp * nSign; break;
- default: ThrowFormatError();
- }
- }
- else
- {
- switch (*szTmp)
- {
- case _T('H'): m_nHour = nTmp * nSign; break;
- case _T('M'): m_nMinute = nTmp * nSign; break;
- case _T('S'): m_dSecond = nTmp * nSign; break;
- case _T('.'): m_dSecond = (nTmp + ParseDouble(&szTmp)) * nSign;
- if (*szTmp != _T('S'))
- ThrowFormatError();
- break;
- default: ThrowFormatError();
- }
- }
- szTmp++;
- }
- }
-
-
- CSchemaDuration operator+(const CSchemaDuration& dur1, const CSchemaDuration& dur2)
- {
- return CSchemaDuration(
- !(dur1.m_bPositive ^ dur2.m_bPositive),
- dur1.m_nYear + dur2.m_nYear,
- dur1.m_nMonth + dur2.m_nMonth,
- dur1.m_nDay + dur2.m_nDay,
- dur1.m_nHour + dur2.m_nHour,
- dur1.m_nMinute + dur2.m_nMinute,
- dur1.m_dSecond + dur2.m_dSecond
- );
- }
-
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDateTimeBase
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDateTimeBase::CSchemaDateTimeBase()
- {
- }
-
-
- CSchemaDateTimeBase::CSchemaDateTimeBase(bool bUTC)
- {
- m_nTZMode = bUTC ? TZ_UTC : TZ_Missing;
- m_nOffset = 0;
- }
-
-
- CSchemaDateTimeBase::CSchemaDateTimeBase(int nOffset)
- {
- m_nTZMode = TZ_Offset;
- m_nOffset = nOffset;
- }
-
-
- bool CSchemaDateTimeBase::HasTimezone() const
- {
- return m_nTZMode != TZ_Missing;
- }
-
-
- int CSchemaDateTimeBase::GetTimezoneMode() const
- {
- return m_nTZMode;
- }
-
-
- int CSchemaDateTimeBase::GetOffset() const
- {
- return m_nOffset;
- }
-
-
- void CSchemaDateTimeBase::SetTimezoneMode(int nTZMode)
- {
- m_nTZMode = nTZMode;
- if (m_nTZMode == TZ_Missing || m_nTZMode == TZ_UTC)
- m_nOffset = 0;
- }
-
-
- void CSchemaDateTimeBase::SetOffset(int nOffset)
- {
- m_nTZMode = TZ_Offset;
- m_nOffset = nOffset;
- }
-
-
- int CSchemaDateTimeBase::WriteTime(TCHAR* szTarget, int nHour, int nMinute, double dSecond)
- {
- if (dSecond - floor(dSecond) == 0)
- {
- return _stprintf(szTarget, _T("%02i:%02i:%02.f"), nHour, nMinute, floor(dSecond));
- }
- else
- {
- TCHAR* szLast = szTarget + _stprintf(szTarget, _T("%02i:%02i:%02.9f"), nHour, nMinute, dSecond);
-
- while (*--szLast == _T('0'))
- *szLast = 0;
-
- return szLast - szTarget;
- }
- }
-
-
- void CSchemaDateTimeBase::ParseTZ(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- if (*szTmp == 0)
- {
- m_nTZMode = TZ_Missing;
- m_nOffset = 0;
- }
- else if (*szTmp == _T('Z'))
- {
- m_nTZMode = TZ_UTC;
- m_nOffset = 0;
- if (*++szTmp)
- ThrowFormatError();
- }
- else
- {
- m_nTZMode = TZ_Offset;
- int nOffsetHour = ParseInt(&szTmp);
- ParseChar(&szTmp, _T(':'));
- int nOffsetMinute = ParseInt(&szTmp);
- if (nOffsetHour < 0)
- m_nOffset = nOffsetHour * 60 - nOffsetMinute;
- else
- m_nOffset = nOffsetHour * 60 + nOffsetMinute;
- if (*szTmp)
- ThrowFormatError();
- }
- }
-
-
- void CSchemaDateTimeBase::WriteTZ(TCHAR* szTarget) const
- {
- switch (m_nTZMode)
- {
- case TZ_UTC:
- _tcscat(szTarget, _T("Z"));
- break;
-
- case TZ_Offset:
- _stprintf(szTarget + _tcslen(szTarget), _T("%c%02i:%02i"),
- m_nOffset < 0 ? _T('-') : _T('+'),
- abs(m_nOffset / 60),
- abs(m_nOffset % 60)
- );
- break;
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDate
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDate::CSchemaDate(int nYear, int nMonth, int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- m_nDay = nDay;
- }
-
-
- CSchemaDate::CSchemaDate(int nYear, int nMonth, int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- m_nDay = nDay;
- }
-
-
- CSchemaDate::CSchemaDate(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaDate::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("%04i-%02i-%02i"), m_nYear, m_nMonth, m_nDay);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaDate::GetYear() const
- {
- return m_nYear;
- }
-
-
- int CSchemaDate::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- int CSchemaDate::GetDay() const
- {
- return m_nDay;
- }
-
-
- void CSchemaDate::SetYear(int nYear)
- {
- m_nYear = nYear;
- }
-
-
- void CSchemaDate::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaDate::SetDay(int nDay)
- {
- m_nDay = nDay;
- }
-
-
- void CSchemaDate::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- m_nYear = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nMonth = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nDay = ParseInt(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- bool operator==(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- if (t1.HasTimezone() == t2.HasTimezone())
- return t1.m_nYear == t2.m_nYear
- && t1.m_nMonth == t2.m_nMonth
- && t1.m_nDay == t2.m_nDay;
- else
- return false;
- }
-
-
- bool operator<(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- if (t1.HasTimezone() == t2.HasTimezone())
- return t1.m_nYear < t2.m_nYear
- || t1.m_nYear == t2.m_nYear && t1.m_nMonth < t2.m_nMonth
- || t1.m_nYear == t2.m_nYear && t1.m_nMonth == t2.m_nMonth && t1.m_nDay < t2.m_nDay;
- else
- return false;
- }
-
-
- bool operator!=(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- return !(t1 == t2);
- }
-
-
- bool operator<=(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- return t1 < t2 || t1 == t2;
- }
-
-
- bool operator>(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- return t2 < t1;
- }
-
-
- bool operator>=(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- return t2 < t1 || t1 == t2;
- }
-
-
- CSchemaDate operator+(const CSchemaDate& t, const CSchemaDuration& dur)
- {
- CSchemaDate r = t;
- int nHour = 0;
- int nMinute = 0;
- double dSecond = 0;
-
- DateTimeAddDuration(r.m_nYear, r.m_nMonth, r.m_nDay, nHour, nMinute, dSecond, dur);
-
- return r;
- }
-
-
- CSchemaDuration operator-(const CSchemaDate& t1, const CSchemaDate& t2)
- {
- CSchemaDuration tmp(false, -t2.m_nYear, -t2.m_nMonth, -t2.m_nDay, 0, 0, 0);
- CSchemaDate t = t1 + tmp;
- return CSchemaDuration(true, t.m_nYear, t.m_nMonth, t.m_nDay, 0, 0, 0);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaTime
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaTime::CSchemaTime(int nHour, int nMinute, double dSecond, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nHour = nHour;
- m_nMinute = nMinute;
- m_dSecond = dSecond;
- }
-
-
- CSchemaTime::CSchemaTime(int nHour, int nMinute, double dSecond, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nHour = nHour;
- m_nMinute = nMinute;
- m_dSecond = dSecond;
- }
-
-
- CSchemaTime::CSchemaTime(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaTime::operator tstring() const
- {
- TCHAR szTmp\[64\];
- int nPos = WriteTime(szTmp, m_nHour, m_nMinute, m_dSecond);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaTime::GetHour() const
- {
- return m_nHour;
- }
-
-
- int CSchemaTime::GetMinute() const
- {
- return m_nMinute;
- }
-
-
-
- double CSchemaTime::GetSecond() const
- {
- return m_dSecond;
- }
-
-
- void CSchemaTime::SetHour(int nHour)
- {
- m_nHour = nHour;
- }
-
-
- void CSchemaTime::SetMinute(int nMinute)
- {
- m_nMinute = nMinute;
- }
-
-
- void CSchemaTime::SetSecond(double dSecond)
- {
- m_dSecond = dSecond;
- }
-
-
- void CSchemaTime::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- m_nHour = ParseInt(&szTmp);
- ParseChar(&szTmp, _T(':'));
- m_nMinute = ParseInt(&szTmp);
- ParseChar(&szTmp, _T(':'));
- m_dSecond = ParseDouble(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- double CSchemaTime::NormalizedSeconds() const
- {
- return m_nHour * 3600 + m_nMinute * 60 + m_dSecond - m_nOffset * 60;
- }
-
-
- bool operator==(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- if (t1.HasTimezone() == t2.HasTimezone())
- return t1.NormalizedSeconds() == t2.NormalizedSeconds();
- else
- return false;
- }
-
-
- bool operator<(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- if (t1.HasTimezone() == t2.HasTimezone())
- return t1.NormalizedSeconds() < t2.NormalizedSeconds();
-
- if (t1.HasTimezone())
- return t1.NormalizedSeconds() < t2.NormalizedSeconds() - 50400;
- else
- return t1.NormalizedSeconds() + 50400 < t2.NormalizedSeconds();
- }
-
-
- bool operator!=(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- return !(t1 == t2);
- }
-
-
- bool operator<=(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- return t1 < t2 || t1 == t2;
- }
-
-
- bool operator>(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- return t2 < t1;
- }
-
-
- bool operator>=(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- return t2 < t1 || t1 == t2;
- }
-
-
- CSchemaTime operator+(const CSchemaTime& t, const CSchemaDuration& dur)
- {
- CSchemaTime r = t;
- int nYear = 1;
- int nMonth = 1;
- int nDay = 1;
-
- DateTimeAddDuration(nYear, nMonth, nDay, r.m_nHour, r.m_nMinute, r.m_dSecond, dur);
-
- return r;
- }
-
-
- CSchemaDuration operator-(const CSchemaTime& t1, const CSchemaTime& t2)
- {
- CSchemaDuration tmp(false, 0, 0, 0, -t2.m_nHour, -t2.m_nMinute, -t2.m_dSecond);
- CSchemaTime t = t1 + tmp;
- return CSchemaDuration(true, 0, 0, 0, t.m_nHour, t.m_nMinute, t.m_dSecond);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDateTime
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDateTime::CSchemaDateTime(int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- m_nDay = nDay;
- m_nHour = nHour;
- m_nMinute = nMinute;
- m_dSecond = dSecond;
- }
-
-
- CSchemaDateTime::CSchemaDateTime(int nYear, int nMonth, int nDay, int nHour, int nMinute, double dSecond, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- m_nDay = nDay;
- m_nHour = nHour;
- m_nMinute = nMinute;
- m_dSecond = dSecond;
- }
-
-
- CSchemaDateTime::CSchemaDateTime(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaDateTime::operator tstring() const
- {
- TCHAR szTmp\[64\];
- int nPos = _stprintf(szTmp, _T("%04i-%02i-%02iT"), m_nYear, m_nMonth, m_nDay);
- nPos += WriteTime(szTmp + nPos, m_nHour, m_nMinute, m_dSecond);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaDateTime::GetYear() const
- {
- return m_nYear;
- }
-
-
- int CSchemaDateTime::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- int CSchemaDateTime::GetDay() const
- {
- return m_nDay;
- }
-
-
- int CSchemaDateTime::GetHour() const
- {
- return m_nHour;
- }
-
-
- int CSchemaDateTime::GetMinute() const
- {
- return m_nMinute;
- }
-
-
- double CSchemaDateTime::GetSecond() const
- {
- return m_dSecond;
- }
-
-
- void CSchemaDateTime::SetYear(int nYear)
- {
- m_nYear = nYear;
- }
-
-
- void CSchemaDateTime::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaDateTime::SetDay(int nDay)
- {
- m_nDay = nDay;
- }
-
-
- void CSchemaDateTime::SetHour(int nHour)
- {
- m_nHour = nHour;
- }
-
-
- void CSchemaDateTime::SetMinute(int nMinute)
- {
- m_nMinute = nMinute;
- }
-
-
- void CSchemaDateTime::SetSecond(double dSecond)
- {
- m_dSecond = dSecond;
- }
-
-
- void CSchemaDateTime::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- m_nYear = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nMonth = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nDay = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('T'));
- m_nHour = ParseInt(&szTmp);
- ParseChar(&szTmp, _T(':'));
- m_nMinute = ParseInt(&szTmp);
- ParseChar(&szTmp, _T(':'));
- m_dSecond = ParseDouble(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- bool operator==(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- if (t1.HasTimezone() == t2.HasTimezone())
- return t1.m_nYear == t2.m_nYear
- && t1.m_nMonth == t2.m_nMonth
- && t1.m_nDay == t2.m_nDay
- && t1.m_nHour == t2.m_nHour
- && t1.m_nMinute == t2.m_nMinute
- && t1.m_dSecond == t2.m_dSecond;
- else
- return false;
- }
-
-
- bool operator<(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- CSchemaDateTime x1 = t1;
- CSchemaDateTime x2 = t2;
-
- if (t1.HasTimezone() != t2.HasTimezone())
- {
- if (t1.HasTimezone())
- {
- CSchemaDuration dur(false, 0, 0, 0, -14, 0, 0);
- DateTimeAddDuration(x2.m_nYear, x2.m_nMonth, x2.m_nDay, x2.m_nHour, x2.m_nMinute, x2.m_dSecond, dur);
- }
- else
- {
- CSchemaDuration dur(true, 0, 0, 0, 14, 0, 0);
- DateTimeAddDuration(x1.m_nYear, x2.m_nMonth, x2.m_nDay, x2.m_nHour, x2.m_nMinute, x2.m_dSecond, dur);
- }
- }
-
- if (x1.m_nYear < x2.m_nYear) return true;
- if (x1.m_nYear > x2.m_nYear) return false;
- if (x1.m_nMonth < x2.m_nMonth) return true;
- if (x1.m_nMonth > x2.m_nMonth) return false;
- if (x1.m_nDay < x2.m_nDay) return true;
- if (x1.m_nDay > x2.m_nDay) return false;
- if (x1.m_nHour < x2.m_nHour) return true;
- if (x1.m_nHour > x2.m_nHour) return false;
- if (x1.m_nMinute < x2.m_nMinute) return true;
- if (x1.m_nMinute > x2.m_nMinute) return false;
- if (x1.m_dSecond < x2.m_dSecond) return true;
- return false;
- }
-
-
- bool operator!=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- return !(t1 == t2);
- }
-
-
- bool operator<=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- return t1 < t2 || t1 == t2;
- }
-
-
- bool operator>(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- return t2 < t1;
- }
-
-
- bool operator>=(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- return t2 < t1 || t1 == t2;
- }
-
-
- CSchemaDateTime operator+(const CSchemaDateTime& t, const CSchemaDuration& dur)
- {
- CSchemaDateTime r = t;
- DateTimeAddDuration(r.m_nYear, r.m_nMonth, r.m_nDay, r.m_nHour, r.m_nMinute, r.m_dSecond, dur);
- return r;
- }
-
-
- CSchemaDuration operator-(const CSchemaDateTime& t1, const CSchemaDateTime& t2)
- {
- CSchemaDuration tmp(false, -t2.m_nYear, -t2.m_nMonth, -t2.m_nDay, -t2.m_nHour, -t2.m_nMinute, -t2.m_dSecond);
- CSchemaDateTime t = t1 + tmp;
- return CSchemaDuration(true, t.m_nYear, t.m_nMonth, t.m_nDay, t.m_nHour, t.m_nMinute, t.m_dSecond);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaYear
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaYear::CSchemaYear(int nYear, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nYear = nYear;
- }
-
-
- CSchemaYear::CSchemaYear(int nYear, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nYear = nYear;
- }
-
-
- CSchemaYear::CSchemaYear(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaYear::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("%04i"), m_nYear);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaYear::GetYear() const
- {
- return m_nYear;
- }
-
-
- void CSchemaYear::SetYear(int nYear)
- {
- m_nYear = nYear;
- }
-
-
- void CSchemaYear::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- m_nYear = ParseInt(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaYearMonth
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaYearMonth::CSchemaYearMonth(int nYear, int nMonth, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- }
-
-
- CSchemaYearMonth::CSchemaYearMonth(int nYear, int nMonth, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nYear = nYear;
- m_nMonth = nMonth;
- }
-
-
- CSchemaYearMonth::CSchemaYearMonth(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaYearMonth::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("%04i-%02i"), m_nYear, m_nMonth);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaYearMonth::GetYear() const
- {
- return m_nYear;
- }
-
-
- int CSchemaYearMonth::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- void CSchemaYearMonth::SetYear(int nYear)
- {
- m_nYear = nYear;
- }
-
-
- void CSchemaYearMonth::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaYearMonth::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- m_nYear = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nMonth = ParseInt(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaMonth
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaMonth::CSchemaMonth(int nMonth, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nMonth = nMonth;
- }
-
-
- CSchemaMonth::CSchemaMonth(int nMonth, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nMonth = nMonth;
- }
-
-
- CSchemaMonth::CSchemaMonth(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaMonth::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("--%02i--"), m_nMonth);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaMonth::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- void CSchemaMonth::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaMonth::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- ParseChar(&szTmp, _T('-'));
- ParseChar(&szTmp, _T('-'));
- m_nMonth = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- ParseChar(&szTmp, _T('-'));
- ParseTZ(szTmp);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaMonthDay
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaMonthDay::CSchemaMonthDay(int nMonth, int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nMonth = nMonth;
- m_nDay = nDay;
- }
-
-
- CSchemaMonthDay::CSchemaMonthDay(int nMonth, int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nMonth = nMonth;
- m_nDay = nDay;
- }
-
-
- CSchemaMonthDay::CSchemaMonthDay(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaMonthDay::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("--%02i-%02i"), m_nMonth, m_nDay);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
- int CSchemaMonthDay::GetMonth() const
- {
- return m_nMonth;
- }
-
-
- int CSchemaMonthDay::GetDay() const
- {
- return m_nDay;
- }
-
-
- void CSchemaMonthDay::SetMonth(int nMonth)
- {
- m_nMonth = nMonth;
- }
-
-
- void CSchemaMonthDay::SetDay(int nDay)
- {
- m_nDay = nDay;
- }
-
-
- void CSchemaMonthDay::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- ParseChar(&szTmp, _T('-'));
- ParseChar(&szTmp, _T('-'));
- m_nMonth = ParseInt(&szTmp);
- ParseChar(&szTmp, _T('-'));
- m_nDay = ParseInt(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaDay
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- CSchemaDay::CSchemaDay(int nDay, bool bUTC) : CSchemaDateTimeBase(bUTC)
- {
- m_nDay = nDay;
- }
-
-
- CSchemaDay::CSchemaDay(int nDay, int nOffset) : CSchemaDateTimeBase(nOffset)
- {
- m_nDay = nDay;
- }
-
-
- CSchemaDay::CSchemaDay(const TCHAR* szValue) : CSchemaDateTimeBase()
- {
- Parse(szValue);
- }
-
-
- CSchemaDay::operator tstring() const
- {
- TCHAR szTmp\[32\];
- int nPos = _stprintf(szTmp, _T("---%02i"), m_nDay);
- WriteTZ(szTmp + nPos);
- return szTmp;
- }
-
-
-
- int CSchemaDay::GetDay() const
- {
- return m_nDay;
- }
-
-
- void CSchemaDay::SetDay(int nDay)
- {
- m_nDay = nDay;
- }
-
-
- void CSchemaDay::Parse(const TCHAR* szValue)
- {
- const TCHAR* szTmp = szValue;
-
- ParseChar(&szTmp, _T('-'));
- ParseChar(&szTmp, _T('-'));
- ParseChar(&szTmp, _T('-'));
- m_nDay = ParseInt(&szTmp);
- ParseTZ(szTmp);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaHexBinary
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- const TCHAR CSchemaHexBinary::sm_EncodeArray\[\] =
- _T("0123456789abcdef");
-
-
- const TCHAR CSchemaHexBinary::sm_DecodeArray\[\] =
- {
-
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-
-
- CSchemaHexBinary::CSchemaHexBinary(const CSchemaHexBinary& rOther)
- {
- Clone(rOther);
- }
-
-
- CSchemaHexBinary::CSchemaHexBinary(const unsigned char* pData, int nSize)
- {
- Clone(pData, nSize);
- }
-
-
- CSchemaHexBinary::CSchemaHexBinary(const TCHAR* szValue)
- {
- Parse(szValue);
- }
-
-
- CSchemaHexBinary::~CSchemaHexBinary()
- {
- if (m_pData)
- {
- delete\[\] m_pData;
- m_pData = NULL;
- }
- }
-
-
- CSchemaHexBinary& CSchemaHexBinary::operator=(const CSchemaHexBinary& rOther)
- {
- Clone(rOther);
- return *this;
- }
-
-
- CSchemaHexBinary::operator tstring() const
- {
- if (m_pData == NULL)
- {
- return _T("");
- }
-
- tstring s;
- s.reserve(m_nSize * 2);
- const unsigned char* pReader = m_pData;
- for (int i = 0; i < m_nSize; i++)
- {
- s += sm_EncodeArray\[*pReader >> 4\];
- s += sm_EncodeArray\[*pReader & 0xF\];
- pReader++;
- }
- return s;
- }
-
-
- int CSchemaHexBinary::GetSize() const
- {
- return m_nSize;
- }
-
-
- const unsigned char* CSchemaHexBinary::GetData() const
- {
- return m_pData;
- }
-
-
- unsigned char* CSchemaHexBinary::GetData()
- {
- return m_pData;
- }
-
-
- void CSchemaHexBinary::SetData(const unsigned char* pData, int nSize)
- {
- if (m_pData)
- delete\[\] m_pData;
- Clone(pData, nSize);
- }
-
-
- void CSchemaHexBinary::Clone(const CSchemaHexBinary& rOther)
- {
- m_nSize = rOther.m_nSize;
- if (m_nSize == 0)
- {
- m_pData = NULL;
- return;
- }
- m_pData = new unsigned char\[m_nSize\];
- memcpy(m_pData, rOther.m_pData, m_nSize);
- }
-
-
- void CSchemaHexBinary::Clone(const unsigned char* pData, int nSize)
- {
- m_nSize = nSize;
- if (m_nSize == 0)
- {
- m_pData = NULL;
- return;
- }
- m_pData = new unsigned char\[m_nSize\];
- memcpy(m_pData, pData, m_nSize);
- }
-
-
- void CSchemaHexBinary::Parse(const TCHAR* szValue)
- {
- m_nSize = _tcslen(szValue) / 2;
- if (m_nSize == 0)
- {
- m_pData = NULL;
- return;
- }
- m_pData = new unsigned char\[m_nSize\];
-
- unsigned char* szDataWriter = m_pData;
- while (*szValue && *(szValue + 1))
- {
- char nDigit1 = sm_DecodeArray\[*szValue++\];
- char nDigit2 = sm_DecodeArray\[*szValue++\];
- if (nDigit1 == -1 ||nDigit2 == -1)
- ThrowFormatError();
- *szDataWriter++ = nDigit1 * 16 + nDigit2;
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // CSchemaBase64Binary
- //
- ////////////////////////////////////////////////////////////////////////
-
-
- const TCHAR CSchemaBase64Binary::sm_EncodeArray\[\] =
- _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
-
-
- const TCHAR CSchemaBase64Binary::sm_DecodeArray\[\] =
- {
-
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
- -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-
-
- CSchemaBase64Binary::CSchemaBase64Binary(const CSchemaBase64Binary& rOther)
- {
- Clone(rOther);
- }
-
-
- CSchemaBase64Binary::CSchemaBase64Binary(const unsigned char* pData, int nSize)
- {
- Clone(pData, nSize);
- }
-
-
- CSchemaBase64Binary::CSchemaBase64Binary(const TCHAR* szValue)
- {
- Decode(szValue, m_pData, m_nSize);
- }
-
-
- CSchemaBase64Binary::~CSchemaBase64Binary()
- {
- if (m_pData)
- {
- delete\[\] m_pData;
- m_pData = NULL;
- }
- }
-
-
- CSchemaBase64Binary& CSchemaBase64Binary::operator=(const CSchemaBase64Binary& rOther)
- {
- Clone(rOther);
- return *this;
- }
-
-
- CSchemaBase64Binary::operator tstring() const
- {
- if (m_pData == NULL)
- {
- return _T("");
- }
-
- tstring sResult;
- TCHAR* szDst;
- int nDstSize;
-
- Encode(m_pData, m_nSize, szDst, nDstSize);
- sResult = szDst;
- delete\[\] szDst;
- return sResult;
- }
-
-
- int CSchemaBase64Binary::GetSize() const
- {
- return m_nSize;
- }
-
-
- const unsigned char* CSchemaBase64Binary::GetData() const
- {
- return m_pData;
- }
-
-
- unsigned char* CSchemaBase64Binary::GetData()
- {
- return m_pData;
- }
-
-
- void CSchemaBase64Binary::SetData(const unsigned char* pData, int nSize)
- {
- if (m_pData)
- delete\[\] m_pData;
- Clone(pData, nSize);
- }
-
-
- void CSchemaBase64Binary::Clone(const CSchemaBase64Binary& rOther)
- {
- m_nSize = rOther.m_nSize;
- if (m_nSize == 0)
- {
- m_pData = NULL;
- return;
- }
- m_pData = new unsigned char\[m_nSize\];
- memcpy(m_pData, rOther.m_pData, m_nSize);
- }
-
-
- void CSchemaBase64Binary::Clone(const unsigned char* pData, int nSize)
- {
- m_nSize = nSize;
- if (m_nSize == 0)
- {
- m_pData = NULL;
- return;
- }
- m_pData = new unsigned char\[m_nSize\];
- memcpy(m_pData, pData, m_nSize);
- }
-
-
- void CSchemaBase64Binary::Encode(unsigned char* pSrc, int nSrcSize, TCHAR*& rszDst, int& rnDstSize, int nMaxLineLength) const
- {
- int nTmpSize, nAllocSize, nLineLength, i;
- TCHAR* szDstWriter;
- unsigned long bBuf;
-
- if (nSrcSize == 0)
- {
- rszDst = NULL;
- rnDstSize = 0;
- return;
- }
-
- nTmpSize = nSrcSize * 4 / 3;
- nAllocSize = nTmpSize + 8;
- if (nMaxLineLength > 0)
- nAllocSize += nTmpSize * 2 / nMaxLineLength;
-
- rszDst = new TCHAR\[nAllocSize\];
- szDstWriter = rszDst;
-
- nTmpSize = nSrcSize / 3 * 3;
- rnDstSize = 0;
- nLineLength = 0;
-
- if (nMaxLineLength > 0)
- {
- for (i = 0; i < nTmpSize; i += 3)
- {
- bBuf = *(pSrc + i) << 16 | *(pSrc + i + 1) << 8 | *(pSrc + i + 2);
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 18) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 12) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 6) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[ bBuf & 0x3F\];
- rnDstSize += 4;
-
- nLineLength += 4;
- if (nMaxLineLength > 0 && nLineLength >= nMaxLineLength)
- {
- *szDstWriter++ = _T('\\r');
- *szDstWriter++ = _T('\\n');
- rnDstSize += 2;
- nLineLength = 0;
- }
- }
- }
- else
- {
- for (i = 0; i < nTmpSize; i += 3)
- {
- bBuf = *(pSrc + i) << 16 | *(pSrc + i + 1) << 8 | *(pSrc + i + 2);
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 18) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 12) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 6) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[ bBuf & 0x3F\];
- rnDstSize += 4;
- }
- }
-
- int nRest = nSrcSize - nTmpSize;
- if (nRest == 2)
- {
- bBuf = *(pSrc + i) << 8 | *(pSrc + i + 1);
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 10) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 4) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf << 2) & 0x3F\];
- *szDstWriter++ = _T('=');
- rnDstSize += 4;
- }
- else if (nRest == 1)
- {
- bBuf = *(pSrc + i);
- *szDstWriter++ = sm_EncodeArray\[(bBuf >> 2) & 0x3F\];
- *szDstWriter++ = sm_EncodeArray\[(bBuf << 4) & 0x3F\];
- *szDstWriter++ = _T('=');
- *szDstWriter++ = _T('=');
- rnDstSize += 4;
- }
-
- *szDstWriter = 0;
- }
-
-
- void CSchemaBase64Binary::Decode(const TCHAR* szSrc, unsigned char*& rpDst, int& rnDstSize)
- {
- int nSrcSize;
- const TCHAR* szSrcReader;
- unsigned char* pDstWriter;
- unsigned long nBuf;
- int nCount;
-
- szSrcReader = szSrc;
- while (*szSrcReader && sm_DecodeArray\[*szSrcReader\] == -1)
- {
- szSrcReader++;
- }
- nSrcSize = _tcslen(szSrcReader);
- if (nSrcSize == 0)
- {
- rpDst = NULL;
- rnDstSize = 0;
- return;
- }
-
- rpDst = new unsigned char\[nSrcSize\];
- pDstWriter = rpDst;
- rnDstSize = 0;
- nBuf = 0;
- nCount = 0;
-
- while (*szSrcReader)
- {
- while (sm_DecodeArray\[*szSrcReader\] == -1)
- {
- if (!*++szSrcReader)
- goto finish;
- }
-
- nBuf |= sm_DecodeArray\[*szSrcReader++\];
-
- if (++nCount == 4)
- {
- *pDstWriter++ = (unsigned char)(nBuf >> 16);
- *pDstWriter++ = (unsigned char)(nBuf >> 8);
- *pDstWriter++ = (unsigned char) nBuf;
- rnDstSize += 3;
- nBuf = 0;
- nCount = 0;
- }
- else
- {
- nBuf <<= 6;
- }
- }
-
- finish:
- if (nCount == 2)
- {
- *pDstWriter++ = (unsigned char)(nBuf >> 10);
- rnDstSize++;
- }
- else if (nCount == 3)
- {
- *pDstWriter++ = (unsigned char)(nBuf >> 16) & 0xFF;
- *pDstWriter++ = (unsigned char)(nBuf >> 8) & 0xFF;
- rnDstSize += 2;
- }
- }
-
-
- } // namespace altova
-