reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ParserContainerBase.hxx
Go to the documentation of this file.
1#ifndef RESIP_ParserContainerBase_hxx
2#define RESIP_ParserContainerBase_hxx
3
5#include <iosfwd>
7#include <vector>
8
10#include "rutil/PoolBase.hxx"
11
12namespace resip
13{
14
15class HeaderFieldValueList;
16class PoolBase;
17
23{
24 public:
25 typedef size_t size_type;
26
31
36 PoolBase& pool);
37
43
45 PoolBase& pool);
46
52
56 virtual ~ParserContainerBase();
57
61 inline void clear() {freeParsers(); mParsers.clear();}
62
67 virtual ParserContainerBase* clone() const = 0;
68
72 inline size_t size() const {return mParsers.size();}
73
78 inline bool empty() const {return mParsers.empty();}
79
87 EncodeStream& encode(const Data& headerName, EncodeStream& str) const;
88
93 std::ostream& encode(Headers::Type type,std::ostream& str) const;
94
99 EncodeStream& encodeEmbedded(const Data& headerName, EncodeStream& str) const;
100
104 void pop_front();
105
109 void pop_back();
110
116 void append(const ParserContainerBase& rhs);
117
123 virtual void parseAll()=0;
124
125 bool getHeaderValueByIndex(size_t index, Data& headerValue) const;
126
127 protected:
129
134 {
135 public:
136 static const HeaderKit Empty;
137
138 HeaderKit(): pc(0){}
139
140 // Poor man's move c'tor, watch out!
141 HeaderKit(const HeaderKit& orig)
142 : pc(orig.pc),
143 hfv(orig.hfv)
144 {
145 HeaderKit& nc_orig = const_cast<HeaderKit&>(orig);
146 std::swap(nc_orig.pc, pc);
147 hfv.swap(nc_orig.hfv);
148 }
149
150 // Poor man's move semantics, watch out!
152 {
153 if(this!=&rhs)
154 {
155 HeaderKit& nc_orig = const_cast<HeaderKit&>(rhs);
156 std::swap(nc_orig.pc, pc);
157 hfv.swap(nc_orig.hfv);
158 }
159 return *this;
160 }
161
163 {}
164
166 {
167 if(pc)
168 {
169 pc->encode(str);
170 }
171 else
172 {
173 hfv.encode(str);
174 }
175 return str;
176 }
177
180 };
181
182 typedef std::vector<HeaderKit, StlPoolAllocator<HeaderKit, PoolBase> > Parsers;
188
192 void copyParsers(const Parsers& parsers);
193
197 void freeParsers();
198
199 inline void freeParser(HeaderKit& kit)
200 {
201 if(kit.pc)
202 {
203 kit.pc->~ParserCategory();
204 if(mPool)
205 {
206 mPool->deallocate(kit.pc);
207 }
208 else
209 {
210 ::operator delete(kit.pc);
211 }
212 kit.pc=0;
213 }
214 }
215
217 {
218 return orig.clone(mPool);
219 }
220};
221
222}
223
224#endif
225
226/* ====================================================================
227 * The Vovida Software License, Version 1.0
228 *
229 * Copyright (c) 2023 SIP Spectrum, Inc. www.sipspectrum.com
230 * Copyright (c) 2000-2005
231 *
232 * Redistribution and use in source and binary forms, with or without
233 * modification, are permitted provided that the following conditions
234 * are met:
235 *
236 * 1. Redistributions of source code must retain the above copyright
237 * notice, this list of conditions and the following disclaimer.
238 *
239 * 2. Redistributions in binary form must reproduce the above copyright
240 * notice, this list of conditions and the following disclaimer in
241 * the documentation and/or other materials provided with the
242 * distribution.
243 *
244 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
245 * and "Vovida Open Communication Application Library (VOCAL)" must
246 * not be used to endorse or promote products derived from this
247 * software without prior written permission. For written
248 * permission, please contact vocal@vovida.org.
249 *
250 * 4. Products derived from this software may not be called "VOCAL", nor
251 * may "VOCAL" appear in their name, without prior written
252 * permission of Vovida Networks, Inc.
253 *
254 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
255 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
256 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
257 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
258 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
259 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
260 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
261 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
262 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
263 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
265 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
266 * DAMAGE.
267 *
268 * ====================================================================
269 *
270 * This software consists of voluntary contributions made by Vovida
271 * Networks, Inc. and many individuals on behalf of Vovida Networks,
272 * Inc. For more information on Vovida Networks, Inc., please see
273 * <http://www.vovida.org/>.
274 *
275 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
HeaderFieldValue & swap(HeaderFieldValue &orig)
EncodeStream & encode(EncodeStream &str) const
EncodeStream & encode(EncodeStream &str) const
Encodes this element to a stream, in the fashion it should be represented on the wire.
Base class for all SIP grammar elements that can have parameters.
virtual ParserCategory * clone() const =0
EncodeStream & encode(EncodeStream &str) const
HeaderKit & operator=(const HeaderKit &rhs)
Abstract Base class implemented in derived class ParserContainer.
bool getHeaderValueByIndex(size_t index, Data &headerValue) const
std::ostream & encode(Headers::Type type, std::ostream &str) const
std::vector< HeaderKit, StlPoolAllocator< HeaderKit, PoolBase > > Parsers
ParserCategory * makeParser(const ParserCategory &orig)
bool empty() const
return true or false indicating whether the mParsers vector is empty or not
EncodeStream & encodeEmbedded(const Data &headerName, EncodeStream &str) const
virtual ~ParserContainerBase()
virtual destructor - empty in this class
ParserContainerBase & operator=(const ParserContainerBase &rhs)
assignment operator copies the mParsers from the rhs
Parsers mParsers
the actual list (vector) of parsers on which encoding is done
void append(const ParserContainerBase &rhs)
append the vector to the mParsers vector held locally
void clear()
clear the mParsers vector
void pop_back()
if mParsers vector is not empty, erase the first element
virtual void parseAll()=0
pure virtual function to be implemented in derived classes The intention is to provide an ability to ...
void freeParsers()
free parser containers
void pop_front()
if mParsers vector is not empty, erase the first element
virtual ParserContainerBase * clone() const =0
pure virtual function to be implemented in derived classes with the intention of cloning this object
size_t size() const
return the size of the mParsers vector
EncodeStream & encode(const Data &headerName, EncodeStream &str) const
void copyParsers(const Parsers &parsers)
copy header kits
virtual void deallocate(void *ptr)=0
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream