1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/log.hxx>
21 #include <sal/types.h>
27 // creates the asymmetric difference with another bitset
29 IndexBitSet
& IndexBitSet::operator-=(sal_uInt16 nBit
)
31 sal_uInt16 nBlock
= nBit
/ 32;
32 sal_uInt32 nBitVal
= 1U << (nBit
% 32);
34 if ( nBlock
>= nBlocks
)
37 if ( pBitmap
[nBlock
] & nBitVal
)
39 pBitmap
[nBlock
] &= ~nBitVal
;
45 // unify with a single bit
47 IndexBitSet
& IndexBitSet::operator|=( sal_uInt16 nBit
)
49 sal_uInt16 nBlock
= nBit
/ 32;
50 sal_uInt32 nBitVal
= 1U << (nBit
% 32);
52 if ( nBlock
>= nBlocks
)
54 sal_uInt32
*pNewMap
= new sal_uInt32
[nBlock
+1];
55 memset( pNewMap
+ nBlocks
, 0, 4 * (nBlock
- nBlocks
+ 1) );
59 memcpy( pNewMap
, pBitmap
.get(), 4 * nBlocks
);
61 pBitmap
.reset(pNewMap
);
65 if ( (pBitmap
[nBlock
] & nBitVal
) == 0 )
67 pBitmap
[nBlock
] |= nBitVal
;
74 // determines if the bit is set (may be the only one)
76 bool IndexBitSet::Contains( sal_uInt16 nBit
) const
78 sal_uInt16 nBlock
= nBit
/ 32;
79 sal_uInt32 nBitVal
= 1U << (nBit
% 32);
81 if ( nBlock
>= nBlocks
)
83 return ( nBitVal
& pBitmap
[nBlock
] ) == nBitVal
;
86 IndexBitSet::IndexBitSet()
91 IndexBitSet::~IndexBitSet()
95 sal_uInt16
IndexBitSet::GetFreeIndex()
97 for(sal_uInt16 i
=0;i
<SAL_MAX_UINT16
;i
++)
103 SAL_WARN( "sfx", "IndexBitSet contains more than SAL_MAX_UINT16 entries");
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */