merge the formfield patch from ooo-build
[ooovba.git] / forms / source / xforms / convert.hxx
blobd65fc03718fe93e033b69e9ba54ec9a77ac57862
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: convert.hxx,v $
10 * $Revision: 1.5 $
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 _CONVERT_HXX
32 #define _CONVERT_HXX
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <map>
37 namespace com { namespace sun { namespace star { namespace uno
39 class Any;
40 class Type;
41 } } } }
42 namespace rtl { class OUString; }
43 class ConvertImpl;
45 namespace xforms
48 struct TypeLess
50 bool operator()( const com::sun::star::uno::Type& rType1,
51 const com::sun::star::uno::Type& rType2 ) const
52 { return rType1.getTypeName() < rType2.getTypeName(); }
55 class Convert
57 typedef com::sun::star::uno::Type Type_t;
58 typedef com::sun::star::uno::Sequence<com::sun::star::uno::Type> Types_t;
59 typedef com::sun::star::uno::Any Any_t;
61 // hold conversion objects
62 typedef rtl::OUString (*fn_toXSD)( const Any_t& );
63 typedef Any_t (*fn_toAny)( const rtl::OUString& );
64 typedef std::pair<fn_toXSD,fn_toAny> Convert_t;
65 typedef std::map<Type_t,Convert_t,TypeLess> Map_t;
66 Map_t maMap;
68 Convert();
70 void init();
72 public:
73 /** get/create Singleton class */
74 static Convert& get();
76 /// can we convert this type?
77 bool hasType( const Type_t& );
79 /// get list of convertable types
80 Types_t getTypes();
82 /// convert any to XML representation
83 rtl::OUString toXSD( const Any_t& rAny );
85 /// convert XML representation to Any of given type
86 Any_t toAny( const rtl::OUString&, const Type_t& );
88 /** translates the whitespaces in a given string, according
89 to a given <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type>.
91 @param _rString
92 the string to convert
93 @param _nWhitespaceTreatment
94 a constant from the <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type> group, specifying
95 how to handle whitespaces
96 @return
97 the converted string
99 static ::rtl::OUString convertWhitespace(
100 const ::rtl::OUString& _rString,
101 sal_Int16 _nWhitespaceTreatment
104 /** replace all occurences 0x08, 0x0A, 0x0D with 0x20
106 static ::rtl::OUString replaceWhitespace( const ::rtl::OUString& _rString );
108 /** replace all sequences of 0x08, 0x0A, 0x0D, 0x20 with a single 0x20.
109 also strip leading/trailing whitespace.
111 static ::rtl::OUString collapseWhitespace( const ::rtl::OUString& _rString );
114 } // namespace xforms
116 #endif