merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / anypair.hxx
blob369407638560fbb4d20755754f55a174aa129ea6
1 #ifndef CFGMGR_ANYPAIR_HXX
2 #define CFGMGR_ANYPAIR_HXX
4 #include <uno/any2.h>
5 #include <com/sun/star/uno/Any.h>
6 #include <com/sun/star/lang/IllegalArgumentException.hpp>
8 namespace configmgr
10 namespace css = com::sun::star;
11 namespace uno = css::uno;
12 namespace lang = css::lang;
14 //==========================================================================
15 //= flags for handling the state of an Anypair
16 //==========================================================================
17 enum {
18 cfgmgr_SELECT_FIRST = 0x01,
19 cfgmgr_SELECT_SECOND = 0x02,
20 cfgmgr_SELECT_BOTH = cfgmgr_SELECT_FIRST | cfgmgr_SELECT_SECOND
23 //==========================================================================
24 //= data structure for descriptive data for an AnyPair
25 //==========================================================================
26 struct cfgmgr_AnyPair_Desc
28 typelib_TypeDescriptionReference * pType;
29 sal_uInt8 nState;
32 inline bool cfgmgr_AnyPair_isNull(cfgmgr_AnyPair_Desc const* _pDesc, sal_uInt8 nSelect)
33 { return (_pDesc->nState & nSelect) == 0; }
35 inline bool cfgmgr_AnyPair_isEmpty(cfgmgr_AnyPair_Desc const* _pDesc)
36 { return (typelib_TypeClass_VOID == _pDesc->pType->eTypeClass); }
38 //==========================================================================
39 //= cfgmgr_AnyPair Basic (POD) data structure for a nullable pair of Anys
40 //==========================================================================
42 struct cfgmgr_AnyPair
44 cfgmgr_AnyPair_Desc desc;
45 const void * first;
46 const void * second;
49 // -----------------------------------------------------------------------------
50 //==========================================================================
51 //= AnyPair
52 //==========================================================================
53 // this AnyPair holds 2 nullable Any's which have to have the same type.
55 class AnyPair
57 cfgmgr_AnyPair m_aAnyPair;
59 public:
60 enum SelectMember
62 SELECT_FIRST = cfgmgr_SELECT_FIRST,
63 SELECT_SECOND = cfgmgr_SELECT_SECOND,
64 SELECT_BOTH = cfgmgr_SELECT_BOTH
66 public:
67 explicit AnyPair(uno::Type const& _aType); // one Type, any's are null
68 explicit AnyPair(uno::Any const& _aAny, SelectMember _select); // one selected any
70 explicit AnyPair(uno::Any const& _aAny, uno::Any const& _aAny2) SAL_THROW((lang::IllegalArgumentException));
72 // copy
73 AnyPair(AnyPair const& _aAny);
74 AnyPair& operator=(AnyPair const& _aAny);
76 // d-tor
77 ~AnyPair();
79 // elementwise setters
80 sal_Bool setFirst(uno::Any const& _aAny);
81 sal_Bool setSecond(uno::Any const& _aAny);
83 // clear data (but not type)
84 void clear(SelectMember _select = SELECT_BOTH);
87 // checking state and availablity of values
88 bool isEmpty() const { return cfgmgr_AnyPair_isEmpty(&m_aAnyPair.desc); }
90 bool isNull () const { return ! hasValue(); }
92 bool hasValue(SelectMember _select = SELECT_BOTH) const
94 return !cfgmgr_AnyPair_isNull(&m_aAnyPair.desc, (sal_uInt8)_select);
96 bool hasFirst() const
98 return hasValue(SELECT_FIRST);
100 bool hasSecond() const
102 return hasValue(SELECT_SECOND);
105 // elementwise getters
106 uno::Type getValueType() const;
107 uno::Any getFirst() const;
108 uno::Any getSecond() const;
109 uno::Any getValue(SelectMember _select) const;
116 } // namespace
118 #endif