/[resiprocate]/main/sip/resiprocate/LazyParser.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/LazyParser.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1282 - (show annotations) (download)
Mon Mar 17 17:54:02 2003 UTC (16 years, 10 months ago) by davidb
File size: 1962 byte(s)
pass (header) context into ParserBuffer for message on throw

1
2 #include <cassert>
3
4 #include "sip2/sipstack/LazyParser.hxx"
5 #include "sip2/util/ParseBuffer.hxx"
6 #include "sip2/sipstack/ParserCategories.hxx"
7 #include "sip2/sipstack/Headers.hxx"
8
9 using namespace Vocal2;
10
11 LazyParser::LazyParser(HeaderFieldValue* headerFieldValue)
12 : mHeaderField(headerFieldValue),
13 mIsMine(false),
14 mIsParsed(mHeaderField->mField == 0) //although this has a hfv it is
15 //parsed, as the hfv has no content
16 {
17 }
18
19 LazyParser::LazyParser()
20 : mHeaderField(0),
21 mIsMine(true),
22 mIsParsed(true)
23 {
24 }
25
26 LazyParser::LazyParser(const LazyParser& rhs)
27 : mHeaderField(0),
28 mIsMine(true),
29 mIsParsed(rhs.mIsParsed)
30 {
31 if (!mIsParsed && rhs.mHeaderField)
32 {
33 mHeaderField = new HeaderFieldValue(*rhs.mHeaderField);
34 }
35 }
36
37 LazyParser::~LazyParser()
38 {
39 clear();
40 }
41
42 LazyParser&
43 LazyParser::operator=(const LazyParser& rhs)
44 {
45 assert( &rhs != 0 );
46
47 if (this != &rhs)
48 {
49 clear();
50 mIsParsed = rhs.mIsParsed;
51 if (rhs.mIsParsed)
52 {
53 mHeaderField = 0;
54 mIsMine = false;
55 }
56 else
57 {
58 mHeaderField = new HeaderFieldValue(*rhs.mHeaderField);
59 mIsMine = true;
60 }
61 }
62 return *this;
63 }
64
65 void
66 LazyParser::checkParsed() const
67 {
68 if (!mIsParsed)
69 {
70 LazyParser* ncThis = const_cast<LazyParser*>(this);
71 ncThis->mIsParsed = true;
72 ParseBuffer pb(mHeaderField->mField, mHeaderField->mFieldLength, errorContext());
73 ncThis->parse(pb);
74 }
75 }
76
77 void
78 LazyParser::clear()
79 {
80 if (mIsMine)
81 {
82 delete mHeaderField;
83 mHeaderField = 0;
84 }
85 }
86
87 std::ostream&
88 LazyParser::encode(std::ostream& str) const
89 {
90 if (isParsed())
91 {
92 return encodeParsed(str);
93 }
94 else
95 {
96 assert(mHeaderField);
97 mHeaderField->encode(str);
98 return str;
99 }
100 }
101
102 std::ostream&
103 Vocal2::operator<<(std::ostream& s, const LazyParser& lp)
104 {
105 lp.encode(s);
106 return s;
107 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27