1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "sal/config.h"
24 #include "com/sun/star/uno/Any.hxx"
25 #include "com/sun/star/uno/Reference.hxx"
26 #include "com/sun/star/uno/RuntimeException.hpp"
27 #include "com/sun/star/uno/Sequence.hxx"
28 #include "com/sun/star/uno/Type.hxx"
29 #include "com/sun/star/uno/TypeClass.hpp"
30 #include "com/sun/star/uno/XInterface.hpp"
31 #include "cppu/unotype.hxx"
32 #include "rtl/string.h"
33 #include "rtl/ustring.h"
34 #include "rtl/ustring.hxx"
35 #include "sal/types.h"
41 bool isListType(Type type
) {
42 return type
>= TYPE_BOOLEAN_LIST
;
45 Type
elementType(Type type
) {
47 case TYPE_BOOLEAN_LIST
:
55 case TYPE_DOUBLE_LIST
:
57 case TYPE_STRING_LIST
:
59 case TYPE_HEXBINARY_LIST
:
60 return TYPE_HEXBINARY
;
63 throw css::uno::RuntimeException(
64 OUString("this cannot happen"),
65 css::uno::Reference
< css::uno::XInterface
>());
69 css::uno::Type
mapType(Type type
) {
72 return cppu::UnoType
< css::uno::Any
>::get();
74 return cppu::UnoType
< sal_Bool
>::get();
76 return cppu::UnoType
< sal_Int16
>::get();
78 return cppu::UnoType
< sal_Int32
>::get();
80 return cppu::UnoType
< sal_Int64
>::get();
82 return cppu::UnoType
< double >::get();
84 return cppu::UnoType
< OUString
>::get();
86 return cppu::UnoType
< css::uno::Sequence
< sal_Int8
> >::get();
87 case TYPE_BOOLEAN_LIST
:
88 return cppu::UnoType
< css::uno::Sequence
< sal_Bool
> >::get();
90 return cppu::UnoType
< css::uno::Sequence
< sal_Int16
> >::get();
92 return cppu::UnoType
< css::uno::Sequence
< sal_Int32
> >::get();
94 return cppu::UnoType
< css::uno::Sequence
< sal_Int64
> >::get();
95 case TYPE_DOUBLE_LIST
:
96 return cppu::UnoType
< css::uno::Sequence
< double > >::get();
97 case TYPE_STRING_LIST
:
98 return cppu::UnoType
< css::uno::Sequence
< OUString
> >::get();
99 case TYPE_HEXBINARY_LIST
:
100 return cppu::UnoType
<
101 css::uno::Sequence
< css::uno::Sequence
< sal_Int8
> > >::get();
104 throw css::uno::RuntimeException(
105 OUString("this cannot happen"),
106 css::uno::Reference
< css::uno::XInterface
>());
110 Type
getDynamicType(css::uno::Any
const & value
) {
111 switch (value
.getValueType().getTypeClass()) {
112 case css::uno::TypeClass_VOID
:
114 case css::uno::TypeClass_BOOLEAN
:
116 case css::uno::TypeClass_BYTE
:
118 case css::uno::TypeClass_SHORT
:
120 case css::uno::TypeClass_UNSIGNED_SHORT
:
121 return value
.has
< sal_Int16
>() ? TYPE_SHORT
: TYPE_INT
;
122 case css::uno::TypeClass_LONG
:
124 case css::uno::TypeClass_UNSIGNED_LONG
:
125 return value
.has
< sal_Int32
>() ? TYPE_INT
: TYPE_LONG
;
126 case css::uno::TypeClass_HYPER
:
128 case css::uno::TypeClass_UNSIGNED_HYPER
:
129 return value
.has
< sal_Int64
>() ? TYPE_LONG
: TYPE_ERROR
;
130 case css::uno::TypeClass_FLOAT
:
131 case css::uno::TypeClass_DOUBLE
:
133 case css::uno::TypeClass_STRING
:
135 case css::uno::TypeClass_SEQUENCE
: //TODO
137 OUString
name(value
.getValueType().getTypeName());
138 if ( name
== "[]byte" ) {
139 return TYPE_HEXBINARY
;
140 } else if (name
.equalsAsciiL(
141 RTL_CONSTASCII_STRINGPARAM("[]boolean")))
143 return TYPE_BOOLEAN_LIST
;
144 } else if ( name
== "[]short" )
146 return TYPE_SHORT_LIST
;
147 } else if ( name
== "[]long" )
149 return TYPE_INT_LIST
;
150 } else if ( name
== "[]hyper" )
152 return TYPE_LONG_LIST
;
153 } else if (name
.equalsAsciiL(
154 RTL_CONSTASCII_STRINGPARAM("[]double")))
156 return TYPE_DOUBLE_LIST
;
157 } else if (name
.equalsAsciiL(
158 RTL_CONSTASCII_STRINGPARAM("[]string")))
160 return TYPE_STRING_LIST
;
161 } else if (name
.equalsAsciiL(
162 RTL_CONSTASCII_STRINGPARAM("[][]byte")))
164 return TYPE_HEXBINARY_LIST
;
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */