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

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

ViewCVS 0.9.2