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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1305 - (hide annotations) (download)
Tue Mar 25 06:33:48 2003 UTC (16 years, 10 months ago) by jason
File size: 1959 byte(s)
rename namespace to resip

1 fluffy 786
2     #include <cassert>
3    
4 jason 1295 #include "resiprocate/LazyParser.hxx"
5     #include "resiprocate/os/ParseBuffer.hxx"
6     #include "resiprocate/ParserCategories.hxx"
7     #include "resiprocate/Headers.hxx"
8 davidb 718
9 jason 1305 using namespace resip;
10 davidb 718
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 fluffy 1000 assert( &rhs != 0 );
46    
47 davidb 718 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 davidb 1282 ParseBuffer pb(mHeaderField->mField, mHeaderField->mFieldLength, errorContext());
73 davidb 718 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 davidb 733 LazyParser::encode(std::ostream& str) const
89 davidb 718 {
90 davidb 733 if (isParsed())
91     {
92     return encodeParsed(str);
93     }
94     else
95     {
96     assert(mHeaderField);
97 davidb 1028 mHeaderField->encode(str);
98     return str;
99 davidb 733 }
100 davidb 718 }
101    
102     std::ostream&
103 jason 1305 resip::operator<<(std::ostream& s, const LazyParser& lp)
104 davidb 718 {
105     lp.encode(s);
106     return s;
107     }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27