problem with const objects in lazy parser

J

joegen

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
 
K

Karl Heinz Buchegger

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() )
 
J

joegen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top