Xalan-C++ API Reference  1.12.0
XToken.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(XTOKEN_HEADER_GUARD_1357924680)
19 #define XTOKEN_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base header file. Must be first.
25 
26 
27 
28 // Base class...
29 #include <xalanc/XPath/XObject.hpp>
30 
31 
32 
34 
35 
36 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
42 {
43 public:
44 
45  /**
46  * Create an XToken.
47  *
48  * @param theMemoryManager The MemoryManager instance.
49  */
50  XToken(MemoryManager& theMemoryManager);
51 
52  /**
53  * Create an XToken for string in the token queue.
54  *
55  * @param theString The string data for the token. The instance will keep a point to this string, so it must be persistent.
56  * @param theNumber The numeric data for the token. This must be consistent with the lexical value in theString.
57  * @param theMemoryManager The MemoryManager instance.
58  */
59  XToken(
60  const XalanDOMString& theString,
61  double theNumber,
62  MemoryManager& theMemoryManager);
63 
64  /**
65  * Create an XToken for number in the token queue.
66  *
67  * @param theNumber The numeric data for the token. This must be consistent with the lexical value in theString.
68  * @param theString The string data for the token. The instance will keep a point to this string, so it must be persistent.
69  * @param theMemoryManager The MemoryManager instance.
70  */
71  XToken(
72  double theNumber,
73  const XalanDOMString& theString,
74  MemoryManager& theMemoryManager);
75 
76  /**
77  * Create an XToken from another one.
78  *
79  * In most cases, the following copy constructor,
80  * which accepts an explicit MemoryManager instance,
81  * is recommended.
82  *
83  * @param theSource The source XToken instance.
84  */
85  XToken(const XToken& theSource);
86 
87  /**
88  * Create an XToken from another one.
89  *
90  * @param theSource The source XToken instance.
91  * @param theMemoryManager The MemoryManager instance.
92  */
93  XToken(
94  const XToken& theSource,
95  MemoryManager& theMemoryManager);
96 
97  virtual
98  ~XToken();
99 
100  virtual const XalanDOMString&
101  getTypeString() const;
102 
103  virtual double
104  num(XPathExecutionContext& executionContext) const;
105 
106  virtual bool
107  boolean(XPathExecutionContext& executionContext) const;
108 
109  virtual const XalanDOMString&
110  str(XPathExecutionContext& executionContext) const;
111 
112  virtual const XalanDOMString&
113  str() const;
114 
115  virtual void
116  str(
117  XPathExecutionContext& executionContext,
118  FormatterListener& formatterListener,
119  MemberFunctionPtr function) const;
120 
121  virtual void
122  str(
123  FormatterListener& formatterListener,
124  MemberFunctionPtr function) const;
125 
126  virtual void
127  str(
128  XPathExecutionContext& executionContext,
129  XalanDOMString& theBuffer) const;
130 
131  virtual void
132  str(XalanDOMString& theBuffer) const;
133 
134  virtual double
135  stringLength(XPathExecutionContext& executionContext) const;
136 
137  virtual void
138  ProcessXObjectTypeCallback(XObjectTypeCallback& theCallbackObject);
139 
140  virtual void
141  ProcessXObjectTypeCallback(XObjectTypeCallback& theCallbackObject) const;
142 
143  XToken&
144  operator=(const XToken& theRHS)
145  {
146  m_stringValue = theRHS.m_stringValue;
147 
148  m_numberValue = theRHS.m_numberValue;
149 
150  return *this;
151  }
152 
153  bool
154  boolean() const
155  {
156  assert(m_stringValue != 0);
157 
158  return m_isString == true ? XObject::boolean(*m_stringValue) : XObject::boolean(m_numberValue);
159  }
160 
161  double
162  num() const
163  {
164  assert(m_stringValue != 0);
165 
166  return m_numberValue;
167  }
168 
169  double
170  stringLength() const
171  {
172  assert(m_stringValue != 0);
173 
174  return static_cast<double>(m_stringValue->length());
175  }
176 
177  /**
178  * Set the instance as a string in the token queue.
179  *
180  * @param theString The string data for the token. XToken will keep a point to this string, so it must be persistent.
181  * @param theNumber The numeric data for the token. This must be consistent with the lexical value in theString.
182  */
183  void
184  set(
185  const XalanDOMString& theString,
186  double theNumber);
187 
188  /**
189  * Set the instance as a number in the token queue.
190  *
191  * @param theNumber The numeric data for the token. This must be consistent with the lexical value in theString.
192  * @param theString The string data for the token. XToken will keep a point to this string, so it must be persistent.
193  */
194  void
195  set(
196  double theNumber,
197  const XalanDOMString& theString);
198 
199 protected:
200 
201  virtual void
202  referenced();
203 
204  virtual void
205  dereferenced();
206 
207 private:
208 
209  // Not defined...
210  bool
211  operator==(const XToken&) const;
212 
213  // Data members...
214  const XalanDOMString* m_stringValue;
215 
216  double m_numberValue;
217 
218  bool m_isString;
219 };
220 
221 
222 
224 
225 
226 
227 }
228 
229 
230 
231 #endif // XTOKEN_HEADER_GUARD_1357924680
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
XalanDOMString.hpp
XALAN_USES_MEMORY_MANAGER
#define XALAN_USES_MEMORY_MANAGER(Type)
Definition: XalanMemoryManagement.hpp:589
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
XALAN_XPATH_EXPORT
#define XALAN_XPATH_EXPORT
Definition: XPathDefinitions.hpp:35
xalanc::XObjectTypeCallback
The purpose of this class is to provide a way to get the "preferred" or closest matching type for XOb...
Definition: XObjectTypeCallback.hpp:54
xalanc::XToken
Definition: XToken.hpp:41
xalanc::XToken::operator=
XToken & operator=(const XToken &theRHS)
Definition: XToken.hpp:144
xalanc::XObject
Class to hold XPath return types.
Definition: XObject.hpp:63
xalanc::XToken::num
double num() const
Cast result object to a number.
Definition: XToken.hpp:162
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
xalanc::XPathExecutionContext
Definition: XPathExecutionContext.hpp:82
xalanc::XToken::boolean
bool boolean() const
Definition: XToken.hpp:154
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XToken::stringLength
double stringLength() const
Definition: XToken.hpp:170
XObject.hpp
XPathDefinitions.hpp