Xalan-C++ API Reference  1.12.0
XalanLocator.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XALANLOCATOR_HEADER_GUARD_1357924680)
19 #define XALANLOCATOR_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
28 #include <xercesc/sax/Locator.hpp>
29 
30 
31 
32 namespace XALAN_CPP_NAMESPACE {
33 
34 
35 
36 using xercesc::Locator;
37 
38 
39 
40 /**
41  * This class defines a base class for Locator derivations in Xalan. It was defined
42  * because Xerces made changes in their Locator class which caused turbulence.
43  */
45 {
46 public:
47 
48  typedef Locator ParentType;
49 
51 
52  virtual
54 
55  virtual const XMLCh*
56  getPublicId() const = 0;
57 
58  virtual const XMLCh*
59  getSystemId() const = 0;
60 
61  virtual XalanFileLoc
62  getLineNumber() const = 0;
63 
64  virtual XalanFileLoc
65  getColumnNumber() const = 0;
66 
67  /**
68  * Get the public identifier from a locator object.
69  * @param theLocator A locator object inherited from Xerces.
70  * @param theAlternateId A default name for a public identifier.
71  * @return a null terminated XalanDOMChar string.
72  */
73  static const XalanDOMChar*
75  const Locator* theLocator,
76  const XalanDOMChar* theAlternateId = getEmptyPtr())
77  {
78  return theLocator == 0 ? theAlternateId : (theLocator->getPublicId() ?
79  theLocator->getPublicId() : theAlternateId);
80  }
81 
82  /**
83  * Get the system identifier from a locator object.
84  * @param theLocator A locator object inherited from Xerces.
85  * @param theAlternateId A default name for a public identifier.
86  * @return a null terminated XalanDOMChar string.
87  */
88  static const XalanDOMChar*
90  const Locator* theLocator,
91  const XalanDOMChar* theAlternateId = getEmptyPtr())
92  {
93  return theLocator == 0 ? theAlternateId : (theLocator->getSystemId() ?
94  theLocator->getSystemId() : theAlternateId);
95  }
96 
97  /**
98  * Get the line number from a locator object.
99  */
100  static XalanFileLoc
101  getLineNumber(const ParentType* theLocator)
102  {
103  return theLocator == 0 ? getUnknownValue() : theLocator->getLineNumber();
104  }
105 
106  /**
107  * Get the column number from a locator object.
108  */
109  static XalanFileLoc
110  getColumnNumber(const ParentType* theLocator)
111  {
112  return theLocator == 0 ? getUnknownValue() : theLocator->getColumnNumber();
113  }
114 
115  static XalanFileLoc
117  {
118  // The parser reports the maximum value of the XalanFileLoc
119  // type for an unknown value.
120  return ~static_cast<XalanFileLoc>(0);
121  }
122 
123  static XalanFileLoc
125  {
126  // The parser reports the maximum value of the XalanFileLoc
127  // type for an unknown value, but that is really non-sensical
128  // for display purposes, so we use 0 instead.
129  return static_cast<XalanFileLoc>(0);
130  }
131 
132  static bool
133  isUnknownValue(XalanFileLoc theLocation)
134  {
135  return theLocation == getUnknownValue();
136  }
137 
138 private:
139 
140  // Not defined...
141  XalanLocator(const XalanLocator&);
142 
143  XalanLocator&
144  operator=(const XalanLocator&);
145 
146  /**
147  * Return static pointer to null XalanDOMChar.
148  * This is crafted to overcome issues with compilers/linkers that
149  * have problems initializing static integer members within a class.
150  *
151  * Replaces: static const int s_zero = 0;
152  * Reference: &s_zero;
153  */
154  static const XalanDOMChar * getEmptyPtr()
155  {
156  static const XalanDOMChar theZero = 0;
157  static const XalanDOMChar * theEmpty = &theZero;
158  return theEmpty;
159  }
160 };
161 
162 }
163 
164 
165 
166 #endif // PREFIXRESOLVER_HEADER_GUARD_1357924680
xalanc::XalanLocator::isUnknownValue
static bool isUnknownValue(XalanFileLoc theLocation)
Definition: XalanLocator.hpp:133
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanLocator::getUnknownDisplayValue
static XalanFileLoc getUnknownDisplayValue()
Definition: XalanLocator.hpp:124
xalanc::XalanLocator::~XalanLocator
virtual ~XalanLocator()
Definition: XalanLocator.hpp:53
xalanc::XalanLocator::getUnknownValue
static XalanFileLoc getUnknownValue()
Definition: XalanLocator.hpp:116
xalanc::XalanLocator::getColumnNumber
static XalanFileLoc getColumnNumber(const ParentType *theLocator)
Get the column number from a locator object.
Definition: XalanLocator.hpp:110
xalanc::XalanLocator::getLineNumber
static XalanFileLoc getLineNumber(const ParentType *theLocator)
Get the line number from a locator object.
Definition: XalanLocator.hpp:101
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::XalanLocator::getPublicId
static const XalanDOMChar * getPublicId(const Locator *theLocator, const XalanDOMChar *theAlternateId=getEmptyPtr())
Get the public identifier from a locator object.
Definition: XalanLocator.hpp:74
xalanc::XalanLocator::getSystemId
static const XalanDOMChar * getSystemId(const Locator *theLocator, const XalanDOMChar *theAlternateId=getEmptyPtr())
Get the system identifier from a locator object.
Definition: XalanLocator.hpp:89
xalanc::XalanLocator::ParentType
Locator ParentType
Definition: XalanLocator.hpp:48
xalanc::XalanLocator::XalanLocator
XalanLocator()
Definition: XalanLocator.hpp:50
xalanc::XalanLocator
This class defines a base class for Locator derivations in Xalan.
Definition: XalanLocator.hpp:44