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

  1 mike  1.1 #ifndef _omi_wsbufinline_h
  2           #define _omi_wsbufinline_h
  3           
  4           /* add literal string to the buffer; 
  5            * skip encoding of special characters;
  6            * length of the string is provided;
  7            * see LIT() macro
  8            */
  9           #if !defined(WSBUF_DISABLE_INLINING)
 10           INLINE
 11           #endif
 12           MI_Result WSBuf_AddLit(
 13               WSBuf* buf,
 14               const MI_Char* str,
 15               MI_Uint32 size)
 16           {
 17               MI_Uint32 n;
 18           
 19               /* If enough capacity, add string inline */
 20               n = size * sizeof(MI_Char);
 21           
 22 mike  1.1     if (n + buf->position < buf->page->u.s.size)
 23               {
 24                   char* data = (char*)(buf->page + 1) + buf->position;
 25                   memcpy(data, str, n);
 26                   ((MI_Char*)data)[size] = 0;
 27           
 28                   buf->position += n;
 29                   return MI_RESULT_OK;
 30               }
 31           
 32               /* Expand buffer and add string */
 33               return __WSBuf_AddLit(buf, str, size);
 34           }
 35           
 36           #if !defined(WSBUF_DISABLE_INLINING)
 37           INLINE
 38           #endif
 39           MI_Result WSBuf_AddLit1(
 40               WSBuf* buf,
 41               MI_Char c1)
 42           {
 43 mike  1.1     const MI_Uint32 SIZE = sizeof(c1);
 44           
 45               if (SIZE + buf->position < buf->page->u.s.size)
 46               {
 47                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
 48                   data[0] = c1;
 49                   data[1] = '\0';
 50                   buf->position += SIZE;
 51                   return MI_RESULT_OK;
 52               }
 53               else
 54               {
 55                   return __WSBuf_AddLit(buf, &c1, 1);
 56               }
 57           }
 58           
 59           #if !defined(WSBUF_DISABLE_INLINING)
 60           INLINE
 61           #endif
 62           MI_Result WSBuf_AddLit2(
 63               WSBuf* buf,
 64 mike  1.1     MI_Char c1,
 65               MI_Char c2)
 66           {
 67               const MI_Uint32 SIZE = 2 * sizeof(c1);
 68           
 69               if (SIZE + buf->position < buf->page->u.s.size)
 70               {
 71                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
 72                   data[0] = c1;
 73                   data[1] = c2;
 74                   data[2] = '\0';
 75                   buf->position += SIZE;
 76                   return MI_RESULT_OK;
 77               }
 78               else
 79               {
 80                   MI_Char str[2];
 81           	    str[0] = c1;
 82           	    str[1] = c2;
 83                   return __WSBuf_AddLit(buf, str, 2);
 84               }
 85 mike  1.1 }
 86           
 87           #if !defined(WSBUF_DISABLE_INLINING)
 88           INLINE
 89           #endif
 90           MI_Result WSBuf_AddLit3(
 91               WSBuf* buf,
 92               MI_Char c1,
 93               MI_Char c2,
 94               MI_Char c3)
 95           {
 96               const MI_Uint32 SIZE = 3 * sizeof(c1);
 97           
 98               if (SIZE + buf->position < buf->page->u.s.size)
 99               {
100                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
101                   data[0] = c1;
102                   data[1] = c2;
103                   data[2] = c3;
104                   data[3] = '\0';
105                   buf->position += SIZE;
106 mike  1.1         return MI_RESULT_OK;
107               }
108               else
109               {
110                   MI_Char str[3];
111           	    str[0] = c1;
112           	    str[1] = c2;
113           	    str[2] = c3;
114                   return __WSBuf_AddLit(buf, str, 3);
115               }
116           }
117           
118           #if !defined(WSBUF_DISABLE_INLINING)
119           INLINE
120           #endif
121           MI_Result WSBuf_AddLit4(
122               WSBuf* buf,
123               MI_Char c1,
124               MI_Char c2,
125               MI_Char c3,
126               MI_Char c4)
127 mike  1.1 {
128               const MI_Uint32 SIZE = 4 * sizeof(c1);
129           
130               if (SIZE + buf->position < buf->page->u.s.size)
131               {
132                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
133                   data[0] = c1;
134                   data[1] = c2;
135                   data[2] = c3;
136                   data[3] = c4;
137                   data[4] = '\0';
138                   buf->position += SIZE;
139                   return MI_RESULT_OK;
140               }
141               else
142               {
143                   MI_Char str[4];
144           	    str[0] = c1;
145           	    str[1] = c2;
146           	    str[2] = c3;
147           	    str[3] = c4;
148 mike  1.1         return __WSBuf_AddLit(buf, str, 4);
149               }
150           }
151           
152           /* add string to the buffer; skip encoding of special characters 
153               typically used with const strings or already encoded values */
154           #if !defined(WSBUF_DISABLE_INLINING)
155           INLINE
156           #endif
157           MI_Result WSBuf_AddStringNoEncoding(
158               WSBuf* buf,
159               const MI_Char* str)
160           {
161               return WSBuf_AddLit(buf, str, (MI_Uint32)Zlen(str));
162           }
163           
164           #endif /* _omi_wsbufinline_h */

ViewCVS 0.9.2