Beispiel #1
0
void CDesk::SetDesk(float flen, float fwidth, float fheight, COLOR enucolor) 
{
    SetLen(flen);
    SetWidth(fwidth);
    SetHeight(fheight);
    SetColor(enucolor);
}
Beispiel #2
0
int CBufQueue::Enqueue(const char *buffer,unsigned int len)
{
	if (_header == NULL || _data == NULL || len > _header->iBufSize) {
		return -1;
	}

	if(IsFull(len)) {
		return 0;
	}

	// 长度字段被分段
	if(_header->iEnd+sizeof(unsigned int)-1 >= _header->iBufSize)
	{
		char tmp[4]; SetLen(tmp, len);
		unsigned len_in_tail_size = _header->iBufSize - _header->iEnd;
		unsigned len_in_head_size = sizeof(unsigned int) - len_in_tail_size;		
		memcpy(&_data[_header->iEnd], tmp, len_in_tail_size);		
		memcpy(_data, &tmp[len_in_tail_size], len_in_head_size);
		memcpy(_data+len_in_head_size, buffer, len);
		_header->iEnd = len_in_head_size + len;
		if (_header->iEnd+ReserveLen > _header->iBegin)
			return -1;
	}	
	// 数据被分段
	else if(_header->iEnd+sizeof(unsigned int)+len > _header->iBufSize){
		unsigned data_in_tail_size = _header->iBufSize-_header->iEnd-sizeof(unsigned int);
		SetLen(_data+_header->iEnd,len);
		memcpy(_data+_header->iEnd+sizeof(unsigned int),buffer,data_in_tail_size);
		memcpy(_data,buffer+data_in_tail_size,len-data_in_tail_size);
		_header->iEnd = len-data_in_tail_size;
		if (_header->iEnd+ReserveLen > _header->iBegin)
			return -1;
	} else {
		SetLen(_data+_header->iEnd,len);
		memcpy(_data+_header->iEnd+sizeof(unsigned int),buffer,len);
		_header->iEnd = (_header->iEnd+sizeof(unsigned int)+len)%_header->iBufSize;
	}

	return len;
}
BOOL
ISAPI_STRINGW::CopyToOffset(
    WCHAR * szStringW,
    DWORD   cchStringW,
    DWORD   cchOffset
    )
/*++

Purpose:

    Copies a Unicode string into the ISAPI_STRINGW's data, starting at the
    specified offset, in characters.

Arguments:

    szStringW  - The Unicode string to copy
    cchStringW - The number of characters to copy
    cchOffset  - The offset, in chracters, at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    DWORD   cbData;

    //
    // Ensure that we have enough storage available
    //

    cbData = ( cchStringW + 1 ) * sizeof(WCHAR);

    if ( ResizeBuffer( cbData + cchOffset * sizeof(WCHAR) ) == FALSE )
    {
        return FALSE;
    }

    //
    // Copy the data and ensure proper termination
    //

    CopyMemory( QueryStr() + cchOffset, szStringW, cbData );

    SetLen( QueryCCH() + cchStringW );

    return TRUE;
}
BOOL
ISAPI_STRING::CopyToOffset(
    CHAR *  szString,
    DWORD   cchString,
    DWORD   dwOffset
    )
/*++

Purpose:

    Copies a string into the ISAPI_STRING's data, starting at the
    specified offset.

Arguments:

    szString  - The string to copy
    cchString - The number of characters to copy
    dwOffset  - The offset at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    DWORD   cbData;

    //
    // Ensure that we have enough storage available
    //

    cbData = cchString + sizeof(CHAR);

    if ( ResizeBuffer( cbData + dwOffset ) == FALSE )
    {
        return FALSE;
    }

    //
    // Copy the data and ensure proper termination
    //

    CopyMemory( QueryStr() + dwOffset, szString, cbData );

    SetLen( QueryCCH() + cbData - sizeof(CHAR) );

    return TRUE;
}
BOOL
ISAPI_STRINGW::CopyAToOffset(
    CHAR *  szString,
    DWORD   cchString,
    DWORD   cchOffset
    )
/*++

Purpose:

    Copies an ANSI string into the ISAPI_STRINGW's data, starting at the
    specified offset, in characters.

Arguments:

    szString  - The ANSI string to copy
    cchString - The number of characters to copy
    cchOffset - The offset, in chracters, at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    WCHAR * pCursor;
    DWORD   cbString;
    DWORD   cchCopied;
    DWORD   cchData;
    DWORD   cbData;

    cchData = QueryCCH();
    cbData = QueryCB();

    //
    // Ensure that we have enough storage available
    //

    cbString = ( cchString + 1 ) * sizeof(WCHAR);

    if ( ResizeBuffer( cbString + cchOffset * sizeof(WCHAR) ) == FALSE )
    {
        goto Failed;
    }

    //
    // Set the point into which the copy will occur
    //

    pCursor = QueryStr() + cchData;

    //
    // Convert the ANSI string into Unicode using
    // the default system code page.
    //

    cchCopied = MultiByteToWideChar( CP_ACP,
                                     MB_PRECOMPOSED,
                                     szString,
                                     cchString,
                                     pCursor,
                                     cbData );

    if ( cchCopied == 0 )
    {
        goto Failed;
    }

    SetLen( cchData + cchCopied );

    return TRUE;

Failed:

    //
    // No special cleanup to be done
    //

    return FALSE;
}
BOOL
ISAPI_STRINGW::vsprintf_s(
    WCHAR * szFormatW,
    va_list args
    )
/*++

Purpose:

    Sets the specified printf-style formatted Unicode string
    into the ISAPI_STRINGW object using a va_list of args.

Arguments:

    szFormat - The Unicode string format
    ...      - Zero or more additional arguments

Returns:

    TRUE on success, FALSE on failure

--*/
{
    INT     cchWritten;
    DWORD   cbBuffer;
    BOOL    fResult;

    //
    // Build the formatted string
    //

    do
    {
        cbBuffer = QueryBufferSize();

        cchWritten = (DWORD)_vsnwprintf_s( QueryStr(),
										sizeof(QueryStr()),
                                         cbBuffer,
                                         szFormatW,
                                         args );

        if ( cchWritten < 0 )
        {
            //
            // If we just failed, and the buffer
            // is already at its maximum size,
            // then fail.
            //

            if ( cbBuffer >= QueryMaxAlloc() )
            {
                goto Failed;
            }

            //
            // Grow the buffer and try again
            //

            cbBuffer *= 2;

            //
            // Don't exceed the max buffer size
            //

            if ( cbBuffer > QueryMaxAlloc() )
            {
                cbBuffer = QueryMaxAlloc();
            }

            fResult = ResizeBuffer( cbBuffer );

            if ( !fResult )
            {
                goto Failed;
            }
        }

    } while ( cchWritten < 0 );

    SetLen( cchWritten );

    return TRUE;

Failed:

    //
    // No special cleanup needed
    //

    return FALSE;
}
BOOL
ISAPI_STRING::CopyWToOffset(
    WCHAR * szStringW,
    DWORD   cchStringW,
    DWORD   dwOffset
    )
/*++

Purpose:

    Copies a Unicode string into the ISAPI_STRING's data,
    starting at the specified offset.

Arguments:

    szStringW  - The Unicode string to copy
    cchStringW - The number of characters to copy
    dwOffset   - The offset at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    CHAR *  pCursor;
    DWORD   cbData;
    DWORD   cbCopied;
    DWORD   cchData;

    cchData = QueryCCH();

    //
    // Ensure that we have enough storage available
    //

    cbData = cchStringW + sizeof(CHAR);

    if ( QueryBufferSize() < cbData + dwOffset &&
         ResizeBuffer( cbData + dwOffset ) == FALSE )
    {
        goto Failed;
    }

    //
    // Set the point into which the copy will occur
    //

    pCursor = QueryStr() + cchData;

    //
    // Convert the wide string into ANSI using
    // the default system code page.
    //

    cbCopied = WideCharToMultiByte( CP_ACP,
                                    0,
                                    szStringW,
                                    cchStringW,
                                    pCursor,
                                    cbData,
                                    NULL,
                                    NULL );

    if ( cbCopied == 0 )
    {
        goto Failed;
    }

    SetLen( cchData + cbCopied );

    return TRUE;

Failed:

    //
    // No special cleanup to be done
    //

    return FALSE;
}
Beispiel #8
0
    int Ardb::GetValueByPattern(Context& ctx, const Slice& pattern, Data& subst, Data& value,
            ValueObjectMap* meta_cache)
    {
        const char *p, *f;
        const char* spat;
        /* If the pattern is "#" return the substitution object itself in order
         * to implement the "SORT ... GET #" feature. */
        spat = pattern.data();
        if (spat[0] == '#' && spat[1] == '\0')
        {
            value = subst;
            return 0;
        }

        /* If we can't find '*' in the pattern we return NULL as to GET a
         * fixed key does not make sense. */
        p = strchr(spat, '*');
        if (!p)
        {
            return -1;
        }
        std::string vstr;
        subst.GetDecodeString(vstr);

        f = strstr(spat, "->");
        if (NULL != f && (uint32) (f - spat) == (pattern.size() - 2))
        {
            f = NULL;
        }
        std::string keystr(pattern.data(), pattern.size());
        string_replace(keystr, "*", vstr);

        if (f == NULL)
        {
            /*
             * keystr = "len(...)"
             */
            if (keystr.find("len(") == 0 && keystr.rfind(")") == keystr.size() - 1)
            {
                keystr = keystr.substr(4, keystr.size() - 5);

                KeyType keytype = KEY_END;
                GetType(ctx, keystr, keytype);
                switch (keytype)
                {
                    case SET_META:
                    {
                        SetLen(ctx, keystr);
                        break;
                    }
                    case LIST_META:
                    {
                        ListLen(ctx, keystr);
                        break;
                    }
                    case ZSET_META:
                    {
                        ZSetLen(ctx, keystr);
                        break;
                    }
                    default:
                    {
                        return -1;
                    }
                }
                value.SetInt64(ctx.reply.integer);
                value.ToString();
                return 0;
            }
            ValueObject vv;
            int ret = StringGet(ctx, keystr, vv);
            if (0 == ret)
            {
                value = vv.meta.str_value;
                //value.ToString();
            }
            return ret;
        }
        else
        {
            size_t pos = keystr.find("->");
            std::string field = keystr.substr(pos + 2);
            keystr = keystr.substr(0, pos);
            int ret = 0;
            if (NULL == meta_cache)
            {
                ret = HashGet(ctx, keystr, field, value);
            }
            else
            {
                ValueObjectMap::iterator fit = meta_cache->find(keystr);
                if (fit == meta_cache->end())
                {
                    ValueObject meta;
                    GetMetaValue(ctx, keystr, HASH_META, meta);
                    fit = meta_cache->insert(ValueObjectMap::value_type(keystr, meta)).first;
                }
                Data ff;
                ff.SetString(field, true);
                ret = HashGet(ctx, fit->second, ff, value);
            }
            //value.ToString();
            return ret;
        }
    }