problem with const objects in lazy parser

Discussion in 'C++' started by joegen@pldtweroam.com, Dec 15, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. "" 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
    Karl Heinz Buchegger, Dec 15, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    1,089
  2. Javier
    Replies:
    2
    Views:
    548
    James Kanze
    Sep 4, 2007
  3. Ken Pu
    Replies:
    3
    Views:
    663
    Steven D'Aprano
    Jan 16, 2009
  4. Boris Borcic
    Replies:
    0
    Views:
    542
    Boris Borcic
    Jan 16, 2009
  5. Boris Borcic
    Replies:
    0
    Views:
    539
    Boris Borcic
    Jan 16, 2009
Loading...

Share This Page