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/RuntimeException.hpp>
26 #include <com/sun/star/uno/Type.hxx>
27 #include <com/sun/star/uno/TypeClass.hpp>
28 #include <cppu/unotype.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
36 bool isListType(Type type
) {
37 return type
>= TYPE_BOOLEAN_LIST
;
40 Type
elementType(Type type
) {
42 case TYPE_BOOLEAN_LIST
:
50 case TYPE_DOUBLE_LIST
:
52 case TYPE_STRING_LIST
:
54 case TYPE_HEXBINARY_LIST
:
55 return TYPE_HEXBINARY
;
58 throw css::uno::RuntimeException(u
"this cannot happen"_ustr
);
62 css::uno::Type
const & mapType(Type type
) {
65 return cppu::UnoType
< css::uno::Any
>::get();
67 return cppu::UnoType
< sal_Bool
>::get();
69 return cppu::UnoType
< sal_Int16
>::get();
71 return cppu::UnoType
< sal_Int32
>::get();
73 return cppu::UnoType
< sal_Int64
>::get();
75 return cppu::UnoType
< double >::get();
77 return cppu::UnoType
< OUString
>::get();
79 return cppu::UnoType
< css::uno::Sequence
< sal_Int8
> >::get();
80 case TYPE_BOOLEAN_LIST
:
81 return cppu::UnoType
< css::uno::Sequence
< sal_Bool
> >::get();
83 return cppu::UnoType
< css::uno::Sequence
< sal_Int16
> >::get();
85 return cppu::UnoType
< css::uno::Sequence
< sal_Int32
> >::get();
87 return cppu::UnoType
< css::uno::Sequence
< sal_Int64
> >::get();
88 case TYPE_DOUBLE_LIST
:
89 return cppu::UnoType
< css::uno::Sequence
< double > >::get();
90 case TYPE_STRING_LIST
:
91 return cppu::UnoType
< css::uno::Sequence
< OUString
> >::get();
92 case TYPE_HEXBINARY_LIST
:
94 css::uno::Sequence
< css::uno::Sequence
< sal_Int8
> > >::get();
97 throw css::uno::RuntimeException(u
"this cannot happen"_ustr
);
101 Type
getDynamicType(css::uno::Any
const & value
) {
102 switch (value
.getValueTypeClass()) {
103 case css::uno::TypeClass_VOID
:
105 case css::uno::TypeClass_BOOLEAN
:
107 case css::uno::TypeClass_BYTE
:
109 case css::uno::TypeClass_SHORT
:
111 case css::uno::TypeClass_UNSIGNED_SHORT
:
112 return value
.has
< sal_Int16
>() ? TYPE_SHORT
: TYPE_INT
;
113 case css::uno::TypeClass_LONG
:
115 case css::uno::TypeClass_UNSIGNED_LONG
:
116 return value
.has
< sal_Int32
>() ? TYPE_INT
: TYPE_LONG
;
117 case css::uno::TypeClass_HYPER
:
119 case css::uno::TypeClass_UNSIGNED_HYPER
:
120 return value
.has
< sal_Int64
>() ? TYPE_LONG
: TYPE_ERROR
;
121 case css::uno::TypeClass_FLOAT
:
122 case css::uno::TypeClass_DOUBLE
:
124 case css::uno::TypeClass_STRING
:
126 case css::uno::TypeClass_SEQUENCE
: //TODO
128 OUString
name(value
.getValueTypeName());
129 if ( name
== "[]byte" ) {
130 return TYPE_HEXBINARY
;
131 } else if (name
== "[]boolean")
133 return TYPE_BOOLEAN_LIST
;
134 } else if ( name
== "[]short" )
136 return TYPE_SHORT_LIST
;
137 } else if ( name
== "[]long" )
139 return TYPE_INT_LIST
;
140 } else if ( name
== "[]hyper" )
142 return TYPE_LONG_LIST
;
143 } else if (name
== "[]double")
145 return TYPE_DOUBLE_LIST
;
146 } else if (name
== "[]string")
148 return TYPE_STRING_LIST
;
149 } else if (name
== "[][]byte")
151 return TYPE_HEXBINARY_LIST
;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */