summaryrefslogtreecommitdiff
path: root/configmgr/source/inc/anypair.hxx
blob: 0ce5c962817941571ac52f39c81c99b71f036f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef CFGMGR_ANYPAIR_HXX
#define CFGMGR_ANYPAIR_HXX

#include <uno/any2.h>
#include <com/sun/star/uno/Any.h>
#include <com/sun/star/lang/IllegalArgumentException.hpp>

namespace configmgr
{
    namespace css  = com::sun::star;
    namespace uno  = css::uno;
    namespace lang = css::lang;

    //==========================================================================
    //= flags for handling the state of an Anypair
    //==========================================================================
    enum {
        cfgmgr_SELECT_FIRST  = 0x01,
        cfgmgr_SELECT_SECOND = 0x02,
        cfgmgr_SELECT_BOTH = cfgmgr_SELECT_FIRST | cfgmgr_SELECT_SECOND
    };

    //==========================================================================
    //= data structure for descriptive data for an AnyPair
    //==========================================================================
    struct cfgmgr_AnyPair_Desc
    {
        typelib_TypeDescriptionReference *  pType;
        sal_uInt8 nState;
    };

    inline bool cfgmgr_AnyPair_isNull(cfgmgr_AnyPair_Desc const* _pDesc, sal_uInt8 nSelect)
    { return (_pDesc->nState & nSelect) == 0; }

    inline bool cfgmgr_AnyPair_isEmpty(cfgmgr_AnyPair_Desc const* _pDesc)
    { return (typelib_TypeClass_VOID == _pDesc->pType->eTypeClass); }

    //==========================================================================
    //= cfgmgr_AnyPair Basic (POD) data structure for a nullable pair of Anys
    //==========================================================================

    struct cfgmgr_AnyPair
    {
        cfgmgr_AnyPair_Desc                desc;
        const void * first;
        const void * second;
    };

// -----------------------------------------------------------------------------
    //==========================================================================
    //= AnyPair
    //==========================================================================
    // this AnyPair holds 2 nullable Any's which have to have the same type.

    class AnyPair
    {
        cfgmgr_AnyPair m_aAnyPair;

    public:
        enum SelectMember
        {
           SELECT_FIRST   = cfgmgr_SELECT_FIRST,
           SELECT_SECOND  = cfgmgr_SELECT_SECOND,
           SELECT_BOTH    = cfgmgr_SELECT_BOTH
        };
    public:
        explicit AnyPair(uno::Type const& _aType); // one Type, any's are null
        explicit AnyPair(uno::Any const& _aAny, SelectMember _select); // one selected any

        explicit AnyPair(uno::Any const& _aAny, uno::Any const& _aAny2) SAL_THROW((lang::IllegalArgumentException));

        // copy
        AnyPair(AnyPair const& _aAny);
        AnyPair& operator=(AnyPair const& _aAny);

        // d-tor
        ~AnyPair();

        // elementwise setters
        sal_Bool setFirst(uno::Any const& _aAny);
        sal_Bool setSecond(uno::Any const& _aAny);

        // clear data (but not type)
        void clear(SelectMember _select = SELECT_BOTH);


        // checking state and availablity of values
        bool isEmpty()   const { return cfgmgr_AnyPair_isEmpty(&m_aAnyPair.desc); }

        bool isNull  ()  const { return ! hasValue(); }

        bool hasValue(SelectMember _select = SELECT_BOTH)  const
        {
            return !cfgmgr_AnyPair_isNull(&m_aAnyPair.desc, (sal_uInt8)_select);
        }
        bool hasFirst()  const
        {
            return hasValue(SELECT_FIRST);
        }
        bool hasSecond() const
        {
            return hasValue(SELECT_SECOND);
        }

        // elementwise getters
        uno::Type getValueType() const;
        uno::Any getFirst() const;
        uno::Any getSecond() const;
        uno::Any getValue(SelectMember _select) const;

    };




} // namespace

#endif