1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valuetypeconverter.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_VALUECONVERTER_HXX
32 #define CONFIGMGR_VALUECONVERTER_HXX
34 #include "utility.hxx"
35 #include <com/sun/star/script/XTypeConverter.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/uno/Type.hxx>
39 #ifndef INCLUDED_VECTOR
41 #define INCLUDED_VECTOR
46 namespace uno
= ::com::sun::star::uno
;
47 namespace script
= ::com::sun::star::script
;
49 // -----------------------------------------------------------------------------
52 /// TypeConverter is used for converting type from string values
53 uno::Reference
< script::XTypeConverter
> m_xTypeConverter
;
56 rtl::OUString m_sSeparator
;
59 /// construct a value converter with no initial type info
60 ValueConverter(const uno::Reference
< script::XTypeConverter
> & _xTC
)
61 : m_xTypeConverter(_xTC
)
67 /// construct a value converter with a type
68 ValueConverter(uno::Type
const& _aType
, const uno::Reference
< script::XTypeConverter
> & _xTC
)
69 : m_xTypeConverter(_xTC
)
75 /// provide access to the TypeConverter that is used for converting string format
76 uno::Reference
< script::XTypeConverter
> const& getTypeConverter() const SAL_THROW(())
78 return m_xTypeConverter
;
81 /// (re)start the converter with the current type
87 /// (re)start the converter with a new type info (or none)
88 void reset(uno::Type
const & _aType
= uno::Type())
94 /// set the NULL state of this converter
95 void setIsNull(bool bNull
= true)
100 /// set the separator of this converter
101 void setSeparator(rtl::OUString
const & _aSeparator
)
103 m_sSeparator
= _aSeparator
;
106 /// get the (UNO) type
107 bool isTypeSet() const { return m_aType
.getTypeClass() != uno::TypeClass_VOID
; }
109 /// get the (UNO) type
110 uno::Type
getType() const { return m_aType
; }
112 /// is this marked null
113 bool isNull() const { return m_bNull
; }
115 /// does this have a list type
118 /// does this have a separator set
119 bool hasSeparator() const { return m_sSeparator
.getLength() != 0; }
121 /// converting a value
122 uno::Any
convertToAny(rtl::OUString
const& aContent
) const
123 SAL_THROW((script::CannotConvertException
, com::sun::star::uno::RuntimeException
));
125 /// converting a list
126 uno::Any
convertListToAny(uno::Sequence
< rtl::OUString
> const& aContentList
) const
127 SAL_THROW((script::CannotConvertException
, com::sun::star::uno::RuntimeException
));
129 /// converting a binary value
130 uno::Sequence
<sal_Int8
> parseBinary(rtl::OUString
const& aBinaryString
) const
131 SAL_THROW((script::CannotConvertException
, com::sun::star::uno::RuntimeException
));
133 /// splits a string list
134 uno::Sequence
< rtl::OUString
> splitStringList(rtl::OUString
const& aContent
) const;
136 /// converting a list
137 bool convertListToAny(std::vector
< rtl::OUString
> const& aContentList
, uno::Any
& rValue
) const
138 SAL_THROW((script::CannotConvertException
, com::sun::star::uno::RuntimeException
));
140 /// converting a scalar value
141 bool convertScalarToAny(rtl::OUString
const& aContent
, uno::Any
& rValue
) const
142 SAL_THROW((script::CannotConvertException
, com::sun::star::uno::RuntimeException
));
144 /// splitting a string list
145 void splitListData(rtl::OUString
const& aContent
, std::vector
< rtl::OUString
>& rContentList
) const
148 void implReset() SAL_THROW(())
150 m_sSeparator
= rtl::OUString();
154 // -----------------------------------------------------------------------------
155 // -----------------------------------------------------------------------------