xref: /AOO41X/main/svx/inc/svx/svdsob.hxx (revision 3334a7e6acdae9820fa1a6f556bb10129a8de6b2)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVDSOB_HXX
25 #define _SVDSOB_HXX
26 
27 #include <com/sun/star/uno/Any.hxx>
28 #include <tools/stream.hxx>
29 
30 #ifndef _STRING_H
31 #include <tools/string.hxx> //wg. memset
32 #define _STRING_H
33 #endif
34 #include "svx/svxdllapi.h"
35 
36 ////////////////////////////////////////////////////////////////////////////////////////////////////
37 /*
38   Deklaration eines statischen Mengentyps. Die Menge kann die Elemente
39   0..255 aufnehmen und verbraucht stets 32 Bytes.
40 */
41 
42 class SVX_DLLPUBLIC SetOfByte
43 {
44 protected:
45     sal_uInt8 aData[32];
46 
47 public:
SetOfByte(sal_Bool bInitVal=sal_False)48     SetOfByte(sal_Bool bInitVal = sal_False)
49     {
50         memset(aData, bInitVal ? 0xFF : 0x00, sizeof(aData));
51     }
52 
operator ==(const SetOfByte & rCmpSet) const53     sal_Bool operator==(const SetOfByte& rCmpSet) const
54     {
55         return (memcmp(aData, rCmpSet.aData, sizeof(aData)) == 0);
56     }
57 
operator !=(const SetOfByte & rCmpSet) const58     sal_Bool operator!=(const SetOfByte& rCmpSet) const
59     {
60         return (memcmp(aData, rCmpSet.aData, sizeof(aData))!=0);
61     }
62 
Set(sal_uInt8 a)63     void Set(sal_uInt8 a)
64     {
65         aData[a/8] |= 1<<a%8;
66     }
67 
Clear(sal_uInt8 a)68     void Clear(sal_uInt8 a)
69     {
70         aData[a/8] &= ~(1<<a%8);
71     }
72 
Set(sal_uInt8 a,sal_Bool b)73     void Set(sal_uInt8 a, sal_Bool b)
74     {
75         if(b)
76             Set(a);
77         else
78             Clear(a);
79     }
80 
IsSet(sal_uInt8 a) const81     sal_Bool IsSet(sal_uInt8 a) const
82     {
83         return (aData[a/8] & 1<<a%8) != 0;
84     }
85 
SetAll()86     void SetAll()
87     {
88         memset(aData, 0xFF, sizeof(aData));
89     }
90 
ClearAll()91     void ClearAll()
92     {
93         memset(aData, 0x00, sizeof(aData));
94     }
95 
96     sal_Bool IsEmpty() const;
97     sal_Bool IsFull() const;
98 
99     sal_uInt16 GetSetCount() const;
100     sal_uInt8 GetSetBit(sal_uInt16 nNum) const;
101     sal_uInt16 GetClearCount() const;
102     sal_uInt8 GetClearBit(sal_uInt16 nNum) const;
103     void operator&=(const SetOfByte& r2ndSet);
104     void operator|=(const SetOfByte& r2ndSet);
105 
106     friend inline SvStream& operator<<(SvStream& rOut, const SetOfByte& rSet);
107     friend inline SvStream& operator>>(SvStream& rIn, SetOfByte& rSet);
108 
109     // initialize this set with a uno sequence of sal_Int8
110     void PutValue(const com::sun::star::uno::Any & rAny);
111 
112     // returns a uno sequence of sal_Int8
113     void QueryValue(com::sun::star::uno::Any & rAny) const;
114 };
115 
operator <<(SvStream & rOut,const SetOfByte & rSet)116 inline SvStream& operator<<(SvStream& rOut, const SetOfByte& rSet)
117 {
118     rOut.Write((char*)rSet.aData,32);
119     return rOut;
120 }
121 
operator >>(SvStream & rIn,SetOfByte & rSet)122 inline SvStream& operator>>(SvStream& rIn, SetOfByte& rSet)
123 {
124     rIn.Read((char*)rSet.aData,32);
125     return rIn;
126 }
127 
128 #endif // _SVDSOB_HXX
129 
130