Bump version to 21.06.18.1
[LibreOffice.git] / unoxml / source / xpath / xpathobject.cxx
blobb71f8b80d5cfb95d8193033e92aa901f8ee885d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xpathobject.hxx"
22 #include <string.h>
24 #include "../dom/document.hxx"
25 #include "nodelist.hxx"
27 using namespace css::uno;
28 using namespace css::xml::dom;
29 using namespace css::xml::xpath;
31 namespace XPath
33 static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
35 switch (pXPathObj->type)
37 case XPATH_UNDEFINED:
38 return XPathObjectType_XPATH_UNDEFINED;
39 case XPATH_NODESET:
40 return XPathObjectType_XPATH_NODESET;
41 case XPATH_BOOLEAN:
42 return XPathObjectType_XPATH_BOOLEAN;
43 case XPATH_NUMBER:
44 return XPathObjectType_XPATH_NUMBER;
45 case XPATH_STRING:
46 return XPathObjectType_XPATH_STRING;
47 case XPATH_POINT:
48 return XPathObjectType_XPATH_POINT;
49 case XPATH_RANGE:
50 return XPathObjectType_XPATH_RANGE;
51 case XPATH_LOCATIONSET:
52 return XPathObjectType_XPATH_LOCATIONSET;
53 case XPATH_USERS:
54 return XPathObjectType_XPATH_USERS;
55 case XPATH_XSLT_TREE:
56 return XPathObjectType_XPATH_XSLT_TREE;
57 default:
58 return XPathObjectType_XPATH_UNDEFINED;
62 CXPathObject::CXPathObject(
63 ::rtl::Reference<DOM::CDocument> const& pDocument,
64 ::osl::Mutex & rMutex,
65 std::shared_ptr<xmlXPathObject> const& pXPathObj)
66 : m_pDocument(pDocument)
67 , m_rMutex(rMutex)
68 , m_pXPathObj(pXPathObj)
69 , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
73 /**
74 get object type
76 XPathObjectType CXPathObject::getObjectType()
78 return m_XPathObjectType;
81 /**
82 get the nodes from a nodelist type object
84 Reference< XNodeList > SAL_CALL
85 CXPathObject::getNodeList()
87 ::osl::MutexGuard const g(m_rMutex);
89 Reference< XNodeList > const xRet(
90 new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
91 return xRet;
94 /**
95 get value of a boolean object
97 sal_Bool SAL_CALL CXPathObject::getBoolean()
99 ::osl::MutexGuard const g(m_rMutex);
101 return xmlXPathCastToBoolean(m_pXPathObj.get()) != 0;
105 get number as byte
107 sal_Int8 SAL_CALL CXPathObject::getByte()
109 ::osl::MutexGuard const g(m_rMutex);
111 return static_cast<sal_Int8>(xmlXPathCastToNumber(m_pXPathObj.get()));
115 get number as short
117 sal_Int16 SAL_CALL CXPathObject::getShort()
119 ::osl::MutexGuard const g(m_rMutex);
121 return static_cast<sal_Int16>(xmlXPathCastToNumber(m_pXPathObj.get()));
125 get number as long
127 sal_Int32 SAL_CALL CXPathObject::getLong()
129 ::osl::MutexGuard const g(m_rMutex);
131 return static_cast<sal_Int32>(xmlXPathCastToNumber(m_pXPathObj.get()));
135 get number as hyper
137 sal_Int64 SAL_CALL CXPathObject::getHyper()
139 ::osl::MutexGuard const g(m_rMutex);
141 return static_cast<sal_Int64>(xmlXPathCastToNumber(m_pXPathObj.get()));
145 get number as float
147 float SAL_CALL CXPathObject::getFloat()
149 ::osl::MutexGuard const g(m_rMutex);
151 return static_cast<float>(xmlXPathCastToNumber(m_pXPathObj.get()));
155 get number as double
157 double SAL_CALL CXPathObject::getDouble()
159 ::osl::MutexGuard const g(m_rMutex);
161 return xmlXPathCastToNumber(m_pXPathObj.get());
165 get string value
167 OUString SAL_CALL CXPathObject::getString()
169 ::osl::MutexGuard const g(m_rMutex);
171 std::shared_ptr<xmlChar const> str(
172 xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
173 char const*const pS(reinterpret_cast<char const*>(str.get()));
174 return OUString(pS, strlen(pS), RTL_TEXTENCODING_UTF8);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */