(file) Return to wsbufinline.h CVS log (file) (dir) Up to [OMI] / omi / wsman

File: [OMI] / omi / wsman / wsbufinline.h (download)
Revision: 1.1, Mon Jun 25 18:54:42 2012 UTC (12 years ago) by mike
Branch: MAIN
CVS Tags: OMI_1_0_2, OMI_1_0_0
1.0.2

#ifndef _omi_wsman_wsbufinline_h
#define _omi_wsman_wsbufinline_h

/* add literal string to the buffer; 
 * skip encoding of special characters;
 * length of the string is provided;
 * see LIT() macro
 */
#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddLit(
    WSBuf* buf,
    const MI_Char* str,
    MI_Uint32 size)
{
    MI_Uint32 n;

    /* If enough capacity, add string inline */
    n = size * sizeof(MI_Char);

    if (n + buf->position < buf->page->u.s.size)
    {
        char* data = (char*)(buf->page + 1) + buf->position;
        memcpy(data, str, n);
        ((MI_Char*)data)[size] = 0;

        buf->position += n;
        return MI_RESULT_OK;
    }

    /* Expand buffer and add string */
    return __WSBuf_AddLit(buf, str, size);
}

#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddLit1(
    WSBuf* buf,
    MI_Char c1)
{
    const MI_Uint32 SIZE = sizeof(c1);

    if (SIZE + buf->position < buf->page->u.s.size)
    {
        MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
        data[0] = c1;
        data[1] = '\0';
        buf->position += SIZE;
        return MI_RESULT_OK;
    }
    else
    {
        return __WSBuf_AddLit(buf, &c1, 1);
    }
}

#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddLit2(
    WSBuf* buf,
    MI_Char c1,
    MI_Char c2)
{
    const MI_Uint32 SIZE = 2 * sizeof(c1);

    if (SIZE + buf->position < buf->page->u.s.size)
    {
        MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
        data[0] = c1;
        data[1] = c2;
        data[2] = '\0';
        buf->position += SIZE;
        return MI_RESULT_OK;
    }
    else
    {
        MI_Char str[2];
	    str[0] = c1;
	    str[1] = c2;
        return __WSBuf_AddLit(buf, str, 2);
    }
}

#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddLit3(
    WSBuf* buf,
    MI_Char c1,
    MI_Char c2,
    MI_Char c3)
{
    const MI_Uint32 SIZE = 3 * sizeof(c1);

    if (SIZE + buf->position < buf->page->u.s.size)
    {
        MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
        data[0] = c1;
        data[1] = c2;
        data[2] = c3;
        data[3] = '\0';
        buf->position += SIZE;
        return MI_RESULT_OK;
    }
    else
    {
        MI_Char str[3];
	    str[0] = c1;
	    str[1] = c2;
	    str[2] = c3;
        return __WSBuf_AddLit(buf, str, 3);
    }
}

#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddLit4(
    WSBuf* buf,
    MI_Char c1,
    MI_Char c2,
    MI_Char c3,
    MI_Char c4)
{
    const MI_Uint32 SIZE = 4 * sizeof(c1);

    if (SIZE + buf->position < buf->page->u.s.size)
    {
        MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
        data[0] = c1;
        data[1] = c2;
        data[2] = c3;
        data[3] = c4;
        data[4] = '\0';
        buf->position += SIZE;
        return MI_RESULT_OK;
    }
    else
    {
        MI_Char str[4];
	    str[0] = c1;
	    str[1] = c2;
	    str[2] = c3;
	    str[3] = c4;
        return __WSBuf_AddLit(buf, str, 4);
    }
}

/* add string to the buffer; skip encoding of special characters 
    typically used with const strings or already encoded values */
#if !defined(WSBUF_DISABLE_INLINING)
INLINE
#endif
MI_Result WSBuf_AddStringNoEncoding(
    WSBuf* buf,
    const MI_Char* str)
{
    return WSBuf_AddLit(buf, str, (MI_Uint32)Zlen(str));
}

#endif /* _omi_wsman_wsbufinline_h */

ViewCVS 0.9.2