~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/qdune/qdtl/boolarray.h

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// simple bool array, boolean values set as individual bits in int array.
 
3
//-----------------------------------------------------------------------------
 
4
 
 
5
#ifndef _BOOLARRAY_H
 
6
#define _BOOLARRAY_H
 
7
 
 
8
//#include <cassert>
 
9
 
 
10
#include "QDRender.h"
 
11
__BEGIN_QDRENDER
 
12
 
 
13
class boolarray_t
 
14
{
 
15
private:
 
16
        boolarray_t(const boolarray_t&);
 
17
public:
 
18
        boolarray_t() : ba(NULL), _size(0), _numbits(0) {}
 
19
        boolarray_t(unsigned int numbits) : ba(NULL), _size(0), _numbits(0) { resize(numbits); }
 
20
        ~boolarray_t() { if (ba) delete[] ba;  ba = NULL; }
 
21
        boolarray_t& operator=(const boolarray_t& ba2)
 
22
        {
 
23
                if (ba2._size != _size) {
 
24
                        if (ba) delete[] ba;
 
25
                        _size = ba2._size;
 
26
                        _numbits = ba2._numbits;
 
27
                        ba = new unsigned int[_size];
 
28
                }
 
29
                memcpy(ba, ba2.ba, _size*sizeof(unsigned int));
 
30
                return *this;
 
31
        }
 
32
        void resize(unsigned int numbits)
 
33
        {
 
34
                _numbits = numbits;
 
35
                _size = ((numbits ? numbits : 1) + 31) >> 5;
 
36
                if (ba) delete[] ba;
 
37
                ba = new unsigned int[_size];
 
38
                memset(ba, 0, _size*sizeof(unsigned int));
 
39
        }
 
40
        bool operator[](unsigned int i)
 
41
        {
 
42
                const unsigned int b = 1 << (i & 31);
 
43
                i >>= 5;
 
44
                //assert(i < _size);
 
45
                return (ba[i] & b);
 
46
        }
 
47
        void operator()(unsigned int i, bool bl)
 
48
        {
 
49
                const unsigned int b = 1 << (i & 31);
 
50
                i >>= 5;
 
51
                //assert(i < _size);
 
52
                if (bl)
 
53
                        ba[i] |= b;
 
54
                else
 
55
                        ba[i] &= ~b;
 
56
        }
 
57
        boolarray_t& operator|=(const boolarray_t& ba2)
 
58
        {
 
59
                //assert(ba2._size == _size);
 
60
                for (size_t i=0; i<_size; ++i)
 
61
                        ba[i] |= ba2.ba[i];
 
62
                return *this;
 
63
        }
 
64
        boolarray_t& operator&=(const boolarray_t& ba2)
 
65
        {
 
66
                //assert(ba2._size == _size);
 
67
                for (size_t i=0; i<_size; ++i)
 
68
                        ba[i] &= ba2.ba[i];
 
69
                return *this;
 
70
        }
 
71
        size_t size() const { return _numbits; }
 
72
protected:
 
73
        unsigned int *ba;
 
74
        size_t _size, _numbits;
 
75
};
 
76
 
 
77
__END_QDRENDER
 
78
 
 
79
#endif  // _BOOLARRAY_H