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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1000 - (hide annotations) (download)
Thu Jan 2 03:02:04 2003 UTC (17 years ago) by fluffy
File size: 1935 byte(s)
few assertions

1 fluffy 786
2     #include <cassert>
3    
4 davidb 718 #include "sip2/sipstack/LazyParser.hxx"
5     #include "sip2/util/ParseBuffer.hxx"
6 fluffy 786 #include "sip2/sipstack/ParserCategories.hxx"
7     #include "sip2/sipstack/Headers.hxx"
8 davidb 718
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 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     ParseBuffer pb(mHeaderField->mField, mHeaderField->mFieldLength);
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 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     return mHeaderField->encode(str);
98     }
99 davidb 718 }
100    
101     std::ostream&
102     Vocal2::operator<<(std::ostream& s, const LazyParser& lp)
103     {
104     lp.encode(s);
105     return s;
106     }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27