LibreOffice Module configmgr (master) 1
type.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <cassert>
23
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>
31
32#include "type.hxx"
33
34namespace configmgr {
35
36bool isListType(Type type) {
37 return type >= TYPE_BOOLEAN_LIST;
38}
39
41 switch (type) {
43 return TYPE_BOOLEAN;
44 case TYPE_SHORT_LIST:
45 return TYPE_SHORT;
46 case TYPE_INT_LIST:
47 return TYPE_INT;
48 case TYPE_LONG_LIST:
49 return TYPE_LONG;
51 return TYPE_DOUBLE;
53 return TYPE_STRING;
55 return TYPE_HEXBINARY;
56 default:
57 assert(false);
58 throw css::uno::RuntimeException("this cannot happen");
59 }
60}
61
63 switch (type) {
64 case TYPE_ANY:
66 case TYPE_BOOLEAN:
68 case TYPE_SHORT:
70 case TYPE_INT:
72 case TYPE_LONG:
74 case TYPE_DOUBLE:
76 case TYPE_STRING:
78 case TYPE_HEXBINARY:
82 case TYPE_SHORT_LIST:
84 case TYPE_INT_LIST:
86 case TYPE_LONG_LIST:
93 return cppu::UnoType<
94 css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
95 default:
96 assert(false);
97 throw css::uno::RuntimeException("this cannot happen");
98 }
99}
100
101Type getDynamicType(css::uno::Any const & value) {
102 switch (value.getValueType().getTypeClass()) {
103 case css::uno::TypeClass_VOID:
104 return TYPE_NIL;
105 case css::uno::TypeClass_BOOLEAN:
106 return TYPE_BOOLEAN;
107 case css::uno::TypeClass_BYTE:
108 return TYPE_SHORT;
109 case css::uno::TypeClass_SHORT:
110 return TYPE_SHORT;
111 case css::uno::TypeClass_UNSIGNED_SHORT:
112 return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
113 case css::uno::TypeClass_LONG:
114 return TYPE_INT;
115 case css::uno::TypeClass_UNSIGNED_LONG:
116 return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
117 case css::uno::TypeClass_HYPER:
118 return TYPE_LONG;
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:
123 return TYPE_DOUBLE;
124 case css::uno::TypeClass_STRING:
125 return TYPE_STRING;
126 case css::uno::TypeClass_SEQUENCE: //TODO
127 {
128 OUString name(value.getValueType().getTypeName());
129 if ( name == "[]byte" ) {
130 return TYPE_HEXBINARY;
131 } else if (name == "[]boolean")
132 {
133 return TYPE_BOOLEAN_LIST;
134 } else if ( name == "[]short" )
135 {
136 return TYPE_SHORT_LIST;
137 } else if ( name == "[]long" )
138 {
139 return TYPE_INT_LIST;
140 } else if ( name == "[]hyper" )
141 {
142 return TYPE_LONG_LIST;
143 } else if (name == "[]double")
144 {
145 return TYPE_DOUBLE_LIST;
146 } else if (name == "[]string")
147 {
148 return TYPE_STRING_LIST;
149 } else if (name == "[][]byte")
150 {
151 return TYPE_HEXBINARY_LIST;
152 }
153 }
154 [[fallthrough]];
155 default:
156 return TYPE_ERROR;
157 }
158}
159
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Type const & get()
Any value
OUString name
Definition: components.cxx:85
@ TYPE_HEXBINARY_LIST
Definition: type.hxx:36
@ TYPE_HEXBINARY
Definition: type.hxx:34
@ TYPE_BOOLEAN
Definition: type.hxx:33
@ TYPE_STRING_LIST
Definition: type.hxx:36
@ TYPE_INT_LIST
Definition: type.hxx:35
@ TYPE_NIL
Definition: type.hxx:33
@ TYPE_ANY
Definition: type.hxx:33
@ TYPE_DOUBLE
Definition: type.hxx:34
@ TYPE_LONG
Definition: type.hxx:34
@ TYPE_BOOLEAN_LIST
Definition: type.hxx:34
@ TYPE_SHORT
Definition: type.hxx:33
@ TYPE_INT
Definition: type.hxx:33
@ TYPE_DOUBLE_LIST
Definition: type.hxx:35
@ TYPE_STRING
Definition: type.hxx:34
@ TYPE_ERROR
Definition: type.hxx:33
@ TYPE_LONG_LIST
Definition: type.hxx:35
@ TYPE_SHORT_LIST
Definition: type.hxx:35
bool isListType(Type type)
Definition: type.cxx:36
css::uno::Type const & mapType(Type type)
Definition: type.cxx:62
Type getDynamicType(css::uno::Any const &value)
Definition: type.cxx:101
Type elementType(Type type)
Definition: type.cxx:40
ResultType type