problem with const objects in lazy parser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joegen@pldtweroam.com

    #1

    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::Get Authorization(
    Authorization & h
    )
    {
    if( !ParseAuthoriza tion() )
    return FALSE;

    if( !HasAuthorizati on() )
    return FALSE;

    h = *m_Authorizatio n;

    return TRUE;
    }

    Since this function is performing a none const action
    "ParseAuthoriza tion()", 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

  • Karl Heinz Buchegger

    #2
    Re: problem with const objects in lazy parser

    "joegen@pldtwer oam.com" wrote:[color=blue]
    >
    > 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::Get Authorization(
    > Authorization & h
    > )
    > {
    > if( !ParseAuthoriza tion() )
    > return FALSE;
    >
    > if( !HasAuthorizati on() )
    > return FALSE;
    >
    > h = *m_Authorizatio n;
    >
    > return TRUE;
    > }
    >
    > Since this function is performing a none const action
    > "ParseAuthoriza tion()", 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?[/color]

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

    if( ! (<const_cast*>( this))->ParseAuthoriza tion() )


    --
    Karl Heinz Buchegger
    kbuchegg@gascad .at

    Comment

    • joegen@pldtweroam.com

      #3
      Re: problem with const objects in lazy parser

      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 ))->ParseAuthoriza tion() )

      Thanks again!

      Joegen

      Comment

      Working...