merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / valuetypeconverter.hxx
blob097f1a6c3f5b661e544ffa089c05e3b343ba9f0c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valuetypeconverter.hxx,v $
10 * $Revision: 1.4 $
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
40 #include <vector>
41 #define INCLUDED_VECTOR
42 #endif
44 namespace configmgr
46 namespace uno = ::com::sun::star::uno;
47 namespace script = ::com::sun::star::script;
49 // -----------------------------------------------------------------------------
50 class ValueConverter
52 /// TypeConverter is used for converting type from string values
53 uno::Reference< script::XTypeConverter > m_xTypeConverter;
54 /// Value info
55 uno::Type m_aType;
56 rtl::OUString m_sSeparator;
57 bool m_bNull;
58 public:
59 /// construct a value converter with no initial type info
60 ValueConverter(const uno::Reference< script::XTypeConverter > & _xTC)
61 : m_xTypeConverter(_xTC)
62 , m_aType()
64 implReset();
67 /// construct a value converter with a type
68 ValueConverter(uno::Type const& _aType, const uno::Reference< script::XTypeConverter > & _xTC)
69 : m_xTypeConverter(_xTC)
70 , m_aType(_aType)
72 implReset();
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
82 void restart()
84 implReset();
87 /// (re)start the converter with a new type info (or none)
88 void reset(uno::Type const & _aType = uno::Type())
90 m_aType = _aType;
91 implReset();
94 /// set the NULL state of this converter
95 void setIsNull(bool bNull = true)
97 m_bNull = bNull;
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
116 bool isList() const;
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;
135 private:
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
146 SAL_THROW(());
147 private:
148 void implReset() SAL_THROW(())
150 m_sSeparator = rtl::OUString();
151 m_bNull = false;
154 // -----------------------------------------------------------------------------
155 // -----------------------------------------------------------------------------
156 } // namespace
158 #endif