By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

problem with const objects in lazy parser

P: n/a
Hi,

I am working on an o project that involves Lazy Parsing. To be more
specific, Its a SIP Message class that implements zero copy and lazy
parsing. Below is a sample function that is causing me problems.
Since my object is a lazy parser, it needs to evaluate the object to be
parsed during the time an accessor is called.

BOOL SIPMessage::GetAuthorization(
Authorization & h
)
{
if( !ParseAuthorization() )
return FALSE;

if( !HasAuthorization() )
return FALSE;

h = *m_Authorization;

return TRUE;
}

Since this function is performing a none const action
"ParseAuthorization()", I cannot declare this function as constant
which will eventually lead to making my object a perpetually none
constant object. Is there anyway to break this curse? I know I
could "mutate" my member objects ( probably a hundred of them ) but it
gives the shudder. Is there another technique to implement this
cleanly?

Joegen

Dec 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"jo****@pldtweroam.com" wrote:

Hi,

I am working on an o project that involves Lazy Parsing. To be more
specific, Its a SIP Message class that implements zero copy and lazy
parsing. Below is a sample function that is causing me problems.
Since my object is a lazy parser, it needs to evaluate the object to be
parsed during the time an accessor is called.

BOOL SIPMessage::GetAuthorization(
Authorization & h
)
{
if( !ParseAuthorization() )
return FALSE;

if( !HasAuthorization() )
return FALSE;

h = *m_Authorization;

return TRUE;
}

Since this function is performing a none const action
"ParseAuthorization()", I cannot declare this function as constant
which will eventually lead to making my object a perpetually none
constant object. Is there anyway to break this curse? I know I
could "mutate" my member objects ( probably a hundred of them ) but it
gives the shudder. Is there another technique to implement this
cleanly?


Well.
It might be on of those cases where a const_cast is acceptable.

if( ! (<const_cast*>(this))->ParseAuthorization() )
--
Karl Heinz Buchegger
kb******@gascad.at
Dec 15 '05 #2

P: n/a
Hi Karl,

Thanks for the tip. It should be the answer to my problem. By the
way i needed to rewrite it this way for it to compile

if( !(const_cast< SIPMessage * >( this ))->ParseAuthorization() )

Thanks again!

Joegen

Dec 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.