2003-09-11 12:26:53 +02:00
|
|
|
#ifndef ARABICA_LOCATOR_IMPL_H
|
|
|
|
#define ARABICA_LOCATOR_IMPL_H
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// LocatorImpl.h
|
|
|
|
// $Id$
|
|
|
|
|
2007-09-05 00:55:47 +02:00
|
|
|
#include <SAX/ArabicaConfig.hpp>
|
2002-06-21 13:16:28 +02:00
|
|
|
#include <string>
|
2007-09-05 00:55:47 +02:00
|
|
|
#include <Locator.hpp>
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 11:49:18 +02:00
|
|
|
namespace Arabica
|
|
|
|
{
|
2002-06-21 13:16:28 +02:00
|
|
|
namespace SAX
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide an optional convenience implementation of Locator.
|
|
|
|
*
|
|
|
|
* <p>This class is available mainly for application writers, who
|
|
|
|
* can use it to make a persistent snapshot of a locator at any
|
|
|
|
* point during a document parse:</p>
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* Locator locator;
|
|
|
|
* LocatorImpl startloc;
|
|
|
|
*
|
|
|
|
* void setLocator(const Locator& locator)
|
|
|
|
* {
|
|
|
|
* // note the locator
|
|
|
|
* this.locator = &locator;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* void startDocument ()
|
|
|
|
* {
|
|
|
|
* // save the location of the start of the document
|
|
|
|
* // for future use.
|
|
|
|
* startloc = locator;
|
|
|
|
* }
|
|
|
|
*</pre>
|
|
|
|
*
|
|
|
|
* <p>Normally, parser writers will not use this class, since it
|
|
|
|
* is more efficient to provide location information only when
|
|
|
|
* requested, rather than constantly updating a Locator object.</p>
|
|
|
|
*
|
|
|
|
* @since SAX 1.0
|
|
|
|
* @author Jez Higgins,
|
|
|
|
* <a href="mailto:jez@jezuk.co.uk">jez@jezuk.co.uk</a>
|
|
|
|
* @version 2.0
|
2007-09-05 14:57:07 +02:00
|
|
|
* @see Locator Locator
|
2002-06-21 13:16:28 +02:00
|
|
|
*/
|
2007-09-06 00:08:51 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
|
|
|
class LocatorImpl : public Locator<string_type, string_adaptor>
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
public:
|
2007-09-06 00:08:51 +02:00
|
|
|
typedef Locator<string_type, string_adaptor> LocatorT;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 14:57:07 +02:00
|
|
|
LocatorImpl() :
|
2002-06-21 13:16:28 +02:00
|
|
|
publicId_(),
|
|
|
|
systemId_(),
|
|
|
|
lineNumber_(-1),
|
|
|
|
columnNumber_(-1)
|
|
|
|
{
|
2007-09-05 14:57:07 +02:00
|
|
|
} // LocatorImpl
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 14:57:07 +02:00
|
|
|
LocatorImpl(const LocatorT& rhs) :
|
2002-06-21 13:16:28 +02:00
|
|
|
publicId_(rhs.getPublicId()),
|
|
|
|
systemId_(rhs.getSystemId()),
|
|
|
|
lineNumber_(rhs.getLineNumber()),
|
|
|
|
columnNumber_(rhs.getColumnNumber())
|
|
|
|
{
|
2007-09-05 14:57:07 +02:00
|
|
|
} // LocatorImpl
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 14:57:07 +02:00
|
|
|
virtual ~LocatorImpl() { }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 14:57:07 +02:00
|
|
|
LocatorImpl& operator=(const LocatorT& rhs)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2007-09-06 00:08:51 +02:00
|
|
|
publicId_ = rhs.getPublicId();
|
|
|
|
systemId_ = rhs.getSystemId();
|
|
|
|
lineNumber_ = rhs.getLineNumber();
|
|
|
|
columnNumber_ = rhs.getColumnNumber();
|
2002-06-21 13:16:28 +02:00
|
|
|
} // operator=
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation of Locator
|
|
|
|
/**
|
|
|
|
* Return the saved public identifier.
|
|
|
|
*
|
2002-10-08 03:00:22 +02:00
|
|
|
* @return The public identifier as a string, or an empty string if none
|
2002-06-21 13:16:28 +02:00
|
|
|
* is available.
|
2007-09-05 14:57:07 +02:00
|
|
|
* @see Locator#getPublicId
|
2002-06-21 13:16:28 +02:00
|
|
|
* @see #setPublicId
|
|
|
|
*/
|
2007-09-06 00:08:51 +02:00
|
|
|
virtual string_type getPublicId() const { return publicId_; }
|
2002-06-21 13:16:28 +02:00
|
|
|
/**
|
|
|
|
* Return the saved system identifier.
|
|
|
|
*
|
2002-10-08 03:00:22 +02:00
|
|
|
* @return The system identifier as a string, or an empty string if none
|
2002-06-21 13:16:28 +02:00
|
|
|
* is available.
|
2007-09-05 14:57:07 +02:00
|
|
|
* @see Locator#getSystemId
|
2002-06-21 13:16:28 +02:00
|
|
|
* @see #setSystemId
|
|
|
|
*/
|
2007-09-06 00:08:51 +02:00
|
|
|
virtual string_type getSystemId() const { return systemId_; }
|
2002-06-21 13:16:28 +02:00
|
|
|
/**
|
|
|
|
* Return the saved line number (1-based).
|
|
|
|
*
|
|
|
|
* @return The line number as an integer, or -1 if none is available.
|
2007-09-05 14:57:07 +02:00
|
|
|
* @see Locator#getLineNumber
|
2002-06-21 13:16:28 +02:00
|
|
|
* @see #setLineNumber
|
|
|
|
*/
|
|
|
|
virtual int getLineNumber() const { return lineNumber_; }
|
|
|
|
/**
|
|
|
|
* Return the saved column number (1-based).
|
|
|
|
*
|
|
|
|
* @return The column number as an integer, or -1 if none is available.
|
2007-09-05 14:57:07 +02:00
|
|
|
* @see Locator#getColumnNumber
|
2002-06-21 13:16:28 +02:00
|
|
|
* @see #setColumnNumber
|
|
|
|
*/
|
|
|
|
virtual int getColumnNumber() const { return columnNumber_; }
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Setters for the properties (not in Locator)
|
|
|
|
/**
|
|
|
|
* Set the public identifier for this locator.
|
|
|
|
*
|
2002-10-08 03:00:22 +02:00
|
|
|
* @param publicId The new public identifier, or an empty string
|
2002-06-21 13:16:28 +02:00
|
|
|
* if none is available.
|
|
|
|
* @see #getPublicId
|
|
|
|
*/
|
2007-09-06 00:08:51 +02:00
|
|
|
void setPublicId(const string_type& publicId) { publicId_ = publicId; }
|
2002-06-21 13:16:28 +02:00
|
|
|
/**
|
|
|
|
* Set the system identifier for this locator.
|
|
|
|
*
|
2002-10-08 03:00:22 +02:00
|
|
|
* @param systemId The new system identifier, or an empty string
|
2002-06-21 13:16:28 +02:00
|
|
|
* if none is available.
|
|
|
|
* @see #getSystemId
|
|
|
|
*/
|
2007-09-06 00:08:51 +02:00
|
|
|
void setSystemId(const string_type& systemId) { systemId_ = systemId; }
|
2002-06-21 13:16:28 +02:00
|
|
|
/**
|
|
|
|
* Set the line number for this locator (1-based).
|
|
|
|
*
|
|
|
|
* @param lineNumber The line number, or -1 if none is available.
|
|
|
|
* @see #getLineNumber
|
|
|
|
*/
|
|
|
|
void setLineNumber(int lineNumber) { lineNumber_ = lineNumber; }
|
|
|
|
/**
|
|
|
|
* Set the column number for this locator (1-based).
|
|
|
|
*
|
|
|
|
* @param columnNumber The column number, or -1 if none is available.
|
|
|
|
* @see #getColumnNumber
|
|
|
|
*/
|
|
|
|
void setColumnNumber(int columnNumber) { columnNumber_ = columnNumber; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Internal state.
|
2007-09-06 00:08:51 +02:00
|
|
|
string_type publicId_;
|
|
|
|
string_type systemId_;
|
2002-06-21 13:16:28 +02:00
|
|
|
int lineNumber_;
|
|
|
|
int columnNumber_;
|
|
|
|
|
|
|
|
bool operator==(const LocatorT& rhs) const;
|
|
|
|
}; // class LocatorImpl
|
|
|
|
|
2007-09-05 11:49:18 +02:00
|
|
|
} // namespace SAX
|
|
|
|
} // namespace Arabica
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
//end of file
|