You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Brian DiRito <bd...@gmail.com> on 2008/07/10 20:16:54 UTC

function arguments in setDocumentLocator

setDocumentLocator is declared in DocuemntHandler as

virtual void setDocumentLocator(const Locator *const locator)

my understanding of this function is that by saving a reference to the 
Locator later methods can query that locater to get line numbers (and 
other things Locator can provide). In return we have to be careful not 
to alter or delete the Locator.

In java this method is declared as
void setDocumentLocator(Locator locator)
and examples found online do things such as

  public void setDocumentLocator(Locator locator) {
    this.locator = locator;
  }
(and then presumably using this.locator in later callbacks)

The catch is because the c++ declares the argument as a const Locator 
*const such an assignment is impossible [without a cast].

http://xerces.apache.org/xerces-c/apiDocs/classDocumentHandler.html
http://xerces.apache.org/xerces-c/apiDocs/classLocator.html
http://xerces.apache.org/xerces-j/apiDocs/org/xml/sax/DocumentHandler.html
http://www.cafeconleche.org/books/xmljava/chapters/ch06s12.html

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: function arguments in setDocumentLocator

Posted by David Bertoni <db...@apache.org>.
Brian DiRito wrote:
> setDocumentLocator is declared in DocuemntHandler as
> 
> virtual void setDocumentLocator(const Locator *const locator)
> 
> my understanding of this function is that by saving a reference to the 
> Locator later methods can query that locater to get line numbers (and 
> other things Locator can provide). In return we have to be careful not 
> to alter or delete the Locator.
It's not a reference -- it's a pointer.

> 
> In java this method is declared as
> void setDocumentLocator(Locator locator)
> and examples found online do things such as
> 
>  public void setDocumentLocator(Locator locator) {
>    this.locator = locator;
>  }
> (and then presumably using this.locator in later callbacks)
> 
> The catch is because the c++ declares the argument as a const Locator 
> *const such an assignment is impossible [without a cast].
All you need to to is declare the variable as a pointer to a const 
Locator, and assignment is not a problem:

class myClass : public DefaultHandler
{
public:

   myClass() :
     DefaultHandler(),
     m_locator(0)
   {
   }

   virtual void
   setDocumentLocator(const Locator* const locator)
   {
     m_locator = locator;
   }

private:

   const Locator* m_locator;
}

BTW, the Xerces-C User list is a more appropriate forum for this type of 
post.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org