473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problem with const objects in lazy parser

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
2 1290
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
1
by: TheOne | last post by:
I have two classes: class OntologyParser { ... protected: virtual void startElement(void *userData, const char *name, const char **atts); virtual void endElement(void *userData, const char...
2
by: max_sang | last post by:
Hello I have a nasty problem... take a look at this code: struct Parser { Parser(const string& s) { ... tokenizes s into pieces... } template <class T> to(size_t idx); private: vector<string>...
15
by: Bit byte | last post by:
I am writing a small parser object. I need to store keywords etc in lsts. Because this data is to be shared by all instances of my parser class, I have declared the variable as class variables...
0
by: christophe_usenet | last post by:
Hi, I'm new to XML, and i'm trying to make a dummy SAX parser with Xerces-C 2.6.0-3. Unfortunately, though it compiles, it does not produce any output :-( Here is the code: ...
15
by: Jiří Paleček | last post by:
Hello, I know the rules for const handling in C++, but I'd like to ask what is the "right" way to use them, eg. when is it appropriate to make a member function const? This came across this...
3
by: Carroll, Barry | last post by:
Greetings: Please forgive me if this is the wrong place for this post. I couldn't find a more acceptable forum. If there is one, please point me in the right direction. I am part of a small...
5
by: Grzegorz Danowski | last post by:
Hi, I'd like to read all lines of caption text from a string: .... Name ="Paragraph" Caption ="The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. " "The...
7
by: Donn Ingle | last post by:
Hi, I really hope someone can help me -- I'm stuck. I have written three versions of code over a week and still can't get past this problem, it's blocking my path to getting other code written. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.