⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmapr.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
//  description:
//      reading a string out of a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDoubleMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr = S_OK;
    CVariant cvar;
    CAutoBSTR bstrText;
     VARTYPE v;
    CAutoRefc<IXMLDOMNode> pNodeOfMapper(_pNodeOfMapper);

    // make sure we got a node
    CHK_BOOL(pNodeOfMapper, E_INVALIDARG);
    // and create an additional refcount, since we are handling it in a CAutoRefc
    pNodeOfMapper->AddRef();

    // follow the Href if necessary
    CHK (FollowHref(&pNodeOfMapper));

    // now we have the right guy, get text
    CHK(pNodeOfMapper->get_text(&bstrText));
    
    CHK (cvar.Assign(bstrText, false));    // now let's put this guy into our comobject
    bstrText.PvReturn();              // the variant took ownership of the bstr


    switch (m_enXSDType)
    {
        case enXSDfloat:
            v = VT_R4;
            break;
            
        case enXSDdecimal:            
        case enXSDDouble:
            v = VT_R8;
            break;
                

        default:
            hr = DISP_E_TYPEMISMATCH;
            goto Cleanup;
            break;
    }
    CHK (ConvertData((VARIANT)cvar, pvar, v));

Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDoubleMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      mapping a string into a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDoubleMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr=S_OK;
    double dbl;
    CVariant cvar;
    CVariant cvarResult;



    CHK (ConvertData(*pvar, (VARIANT *)&cvar, VT_R8));   // who cares what's in it ...

    // at least we know where the output type is going to be
    dbl = V_R8(&cvar);

    // now in case of exXSDdecimal, we need to persist slightly different...    
    if (m_enXSDType != enXSDdecimal)
    {
        CHK (ConvertData(cvar, (VARIANT *)&cvarResult, VT_BSTR));
        // now, the variant function ToString is used as it seems to be more precise as swprintf
        // as this is depending on the locale, we need to replace "," with "." if it appeared
        CHK( pSoapSerializer->writeString(V_BSTR(&cvarResult)));        
    }    
    


Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDecimalMapper::init(ISoapTypeMapperFactory *ptypeFactory, IXMLDOMNode * pSchema, enXSDType xsdType)
//
//  parameters:
//
//  description:
//      set the constrains for this guy
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDecimalMapper::init(ISoapTypeMapperFactory *ptypeFactory, IXMLDOMNode * pSchema, enXSDType xsdType)
{
    HRESULT hr = S_OK;

    CHK(CTypeMapper::init(ptypeFactory, pSchema, xsdType));
    CHK(varType(&m_vtType));
    
    m_xsdConstrains = c_XCNone;
    
    switch (xsdType)
    {
        case enXSDpositiveInteger:
            CHK(VarDecFromI4(1,  &m_decminInclusive));                        
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;
        case enXSDnonpositiveInteger:
            CHK(VarDecFromI4(0,  &m_decmaxInclusive));                                    
            m_xsdConstrains |= c_XCmaxInclusive;
            goto intDefault;
        case enXSDnegativeInteger:
            CHK(VarDecFromI4(-1,  &m_decmaxInclusive));                                                
            m_xsdConstrains |= c_XCmaxInclusive;
            goto intDefault;
        case enXSDlong:
            CHK(VarDecFromStr(_T("9223372036854775807"), LCID_TOUSE , 0, &m_decmaxInclusive));
            CHK(VarDecFromStr(_T("-9223372036854775808"), LCID_TOUSE , 0, &m_decminInclusive));            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;
        case enXSDint:
            CHK(VarDecFromStr(_T("2147483647"), LCID_TOUSE , 0, &m_decmaxInclusive));
            CHK(VarDecFromStr(_T("-2147483648"), LCID_TOUSE , 0, &m_decminInclusive));            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;
        case enXSDshort:
            CHK(VarDecFromI4(32767, &m_decmaxInclusive));
            CHK(VarDecFromI4(-32768, &m_decminInclusive));            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;
        case enXSDbyte:
            CHK(VarDecFromI4(127, &m_decmaxInclusive));
            CHK(VarDecFromI4(-128, &m_decminInclusive));            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;
        case enXSDnonNegativeInteger:
            CHK(VarDecFromI4(0, &m_decminInclusive));            
            m_xsdConstrains |= c_XCminInclusive;
            goto intDefault;

        case enXSDunsignedLong:
            CHK(VarDecFromStr(_T("18446744073709551615"), LCID_TOUSE , 0, &m_decmaxInclusive));
            CHK(VarDecFromI4(0, &m_decminInclusive));                                                            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;            
            goto intDefault;
        case enXSDunsignedInt:
            CHK(VarDecFromStr(_T("4294967295"), LCID_TOUSE , 0, &m_decmaxInclusive));
            CHK(VarDecFromI4(0, &m_decminInclusive));                                                            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;            
            goto intDefault;
        case enXSDunsignedShort:
            CHK(VarDecFromI4(65535, &m_decmaxInclusive));                        
            CHK(VarDecFromI4(0, &m_decminInclusive));                                                            
            m_xsdConstrains |= c_XCmaxInclusive;
            m_xsdConstrains |= c_XCminInclusive;            
            goto intDefault;
        case enXSDunsignedByte:
            CHK(VarDecFromI4(255, &m_decmaxInclusive));                                    
            CHK(VarDecFromI4(0, &m_decminInclusive));                                                
            m_xsdConstrains |= c_XCminInclusive;            
            m_xsdConstrains |= c_XCmaxInclusive;
            goto intDefault;
intDefault:
        case enXSDinteger:
            m_xsdConstrains |= c_XCscale;
            m_lscale = 0; 
            break;
        case enXSDdecimal:
            break;

        default:
            // invalid type
            hr = E_FAIL;
    }

Cleanup:    
    return (hr);
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDecimalMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      reading a string out of a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDecimalMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr = S_OK;
    CVariant cvar;
    CAutoBSTR bstrText;
    CAutoRefc<IXMLDOMNode> pNode(NULL);
    CAutoRefc<IXMLDOMNode> pNodeOfMapper(_pNodeOfMapper);

    // make sure we got a node
    CHK_BOOL(pNodeOfMapper, E_INVALIDARG);
    // and create an additional refcount, since we are handling it in a CAutorefc
    pNodeOfMapper->AddRef();

    // follow the Href if necessary
    CHK (FollowHref(&pNodeOfMapper));

    CHK(pNodeOfMapper->get_text(&bstrText));
    CHK(cvar.Assign(bstrText, false));    // now let's put this guy into our comobject
    bstrText.PvReturn();              // the variant took ownership of the bstr

    //convert to decimal first to easy compares etc...
    CHK (ConvertData((VARIANT)cvar, pvar, (VARTYPE) VT_DECIMAL));

    CHK(checkConstrains(pvar));

    // if we arrived here, everything is fine
    // convert to real targettype
    if (m_vtType != VT_DECIMAL)
    {
        CHK (ConvertData((VARIANT)cvar, pvar, (VARTYPE) m_vtType));
    }    


Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDecimalMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      mapping a string into a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDecimalMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr = E_INVALIDARG;
    CVariant cvar;
    CVariant cdec;
    CHK(ConvertData(*pvar, (VARIANT*) &cdec, VT_DECIMAL));
    CHK(checkConstrains(&cdec));
    CHK (ConvertData(*pvar, (VARIANT *)&cvar, VT_BSTR));

    CHK (pSoapSerializer->writeString(V_BSTR(&cvar)));
 
Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDecimalMapper::checkConstrains(VARIANT *pVar)
//
//  parameters:
//
//  description:
//      verifies that the values fit's the constrains
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDecimalMapper::checkConstrains(VARIANT *pvar)
{
    HRESULT hr = S_OK;
#ifndef UNDER_CE    
    HRESULT hrRes; 
#endif
    // only check constrains when we need them
    if (m_xsdConstrains != c_XCNone)
    {
        if (m_xsdConstrains & c_XCscale)
        {
            CHK_BOOL (V_DECIMAL(pvar).scale == m_lscale, E_INVALIDARG);
        }
        if (m_xsdConstrains & c_XCmaxInclusive)
        {
            CHK_BOOL((VarDecCmp(&m_decmaxInclusive, &V_DECIMAL(pvar)) !=VARCMP_LT), E_INVALIDARG)
        }
        if (m_xsdConstrains & c_XCminInclusive)
        {
            CHK_BOOL((VarDecCmp(&m_decminInclusive, &V_DECIMAL(pvar))!=VARCMP_GT), E_INVALIDARG);            
        }
        // now check constrains....
    }
Cleanup:
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CTimeMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      reading a string out of a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CTimeMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr = S_OK;
    CVariant cvar;
    CAutoBSTR bstrText;
    CAutoRefc<IXMLDOMNode> pNode(NULL);
    TCHAR *pchDate;
    TCHAR *pchTime;
    TCHAR   *pchTemp;
#ifndef UNDER_CE
    TCHAR   *pchTimeZone;
#endif 
    bool     bTimeZonePlus;
    DATE    dateOut;
    DATE    timeOut;
    DATE    timeDiff;
    CAutoRefc<IXMLDOMNode> pNodeOfMapper(_pNodeOfMapper);
#ifndef UNDER_CE
    TIME_ZONE_INFORMATION timeZone;
#endif 
    bool                    fLocalConversion = false;

    // make sure we got a node
    CHK_BOOL(pNodeOfMapper, E_INVALIDARG);
    // and create an additional refcount, since we are handling it in a CAutoRefc
    pNodeOfMapper->AddRef();

    // follow the Href if necessary
    CHK (FollowHref(&pNodeOfMapper));
    timeDiff = 0; 
    
    // now we have the right guy, get text
    CHK(pNodeOfMapper->get_text(&bstrText));

    CHK_BOOL(::SysStringLen(bstrText) > 0, E_INVALIDARG);
    pchDate = bstrText;

    // if there is a Z at the end, ignore it -> change to 0
    pchTemp = pchDate+_tcslen(pchDate)-1;
    if (*pchTemp == _T('Z'))
    {
        fLocalConversion = true; 
        *pchTemp = 0;        
    }
 
    pchDate = _tcstok(bstrText, _T("T"));
    pchTime = _tcstok(0, _T("T"));

    if (pchTime && (m_enXSDType == enXSDdate || m_enXSDType == enXSDtime))
    {
        // if we are a date or a time, we DO not want the T seperator, as this is only for timeinstant valid
        hr = E_INVALIDARG;
        goto Cleanup;
    }
    if (m_enXSDType == enXSDtime)
        pchTime = pchDate;

    if (m_enXSDType == enXSDtimeInstant)
        CHK_BOOL(pchTime, E_INVALIDARG);
 
    // first check for timezone indication. if exists, strip and store....
    bTimeZonePlus = true;
    pchTemp = 0; 

    if (pchTime)
    {
        pchTemp = wcsrchr(pchTime, _T('-'));
        if (pchTemp)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -