1 // Created on: 1995-09-01
2 // Created by: Christian CAILLET
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Interface_BitMap_HeaderFile
18 #define _Interface_BitMap_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Integer.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColStd_HSequenceOfAsciiString.hxx>
27 #include <Standard_Boolean.hxx>
28 #include <Standard_CString.hxx>
31 //! A bit map simply allows to associate a boolean flag to each
32 //! item of a list, such as a list of entities, etc... numbered
33 //! between 1 and a positive count nbitems
35 //! The BitMap class allows to associate several binary flags,
36 //! each of one is identified by a number from 0 to a count
37 //! which can remain at zero or be positive : nbflags
39 //! Flags lists over than numflag=0 are added after creation
40 //! Each of one can be named, hence the user can identify it
41 //! either by its flag number or by a name which gives a flag n0
42 //! (flag n0 0 has no name)
43 class Interface_BitMap
50 //! Creates a empty BitMap
51 Standard_EXPORT Interface_BitMap();
53 //! Creates a BitMap for <nbitems> items
54 //! One flag is defined, n0 0
55 //! <resflags> prepares allocation for <resflags> more flags
56 //! Flags values start at false
57 Standard_EXPORT Interface_BitMap(const Standard_Integer nbitems, const Standard_Integer resflags = 0);
59 //! Initialize empty bit by <nbitems> items
60 //! One flag is defined, n0 0
61 //! <resflags> prepares allocation for <resflags> more flags
62 //! Flags values start at false
63 Standard_EXPORT void Initialize (const Standard_Integer nbitems, const Standard_Integer resflags = 0);
65 //! Creates a BitMap from another one
66 //! if <copied> is True, copies data
67 //! else, data are not copied, only the header object is
68 Standard_EXPORT Interface_BitMap(const Interface_BitMap& other, const Standard_Boolean copied = Standard_False);
70 //! Initialize a BitMap from another one
71 Standard_EXPORT void Initialize (const Interface_BitMap& other, const Standard_Boolean copied = Standard_False);
73 //! Returns internal values, used for copying
74 //! Flags values start at false
75 Standard_EXPORT void Internals (Standard_Integer& nbitems, Standard_Integer& nbwords, Standard_Integer& nbflags, Handle(TColStd_HArray1OfInteger)& flags, Handle(TColStd_HSequenceOfAsciiString)& names) const;
77 //! Reservates for a count of more flags
78 Standard_EXPORT void Reservate (const Standard_Integer moreflags);
80 //! Sets for a new count of items, which can be either less or
81 //! greater than the former one
82 //! For new items, their flags start at false
83 Standard_EXPORT void SetLength (const Standard_Integer nbitems);
85 //! Adds a flag, a name can be attached to it
86 //! Returns its flag number
87 //! Makes required reservation
88 Standard_EXPORT Standard_Integer AddFlag (const Standard_CString name = "");
90 //! Adds several flags (<more>) with no name
91 //! Returns the number of last added flag
92 Standard_EXPORT Standard_Integer AddSomeFlags (const Standard_Integer more);
94 //! Removes a flag given its number.
95 //! Returns True if done, false if num is out of range
96 Standard_EXPORT Standard_Boolean RemoveFlag (const Standard_Integer num);
98 //! Sets a name for a flag, given its number
99 //! name can be empty (to erase the name of a flag)
100 //! Returns True if done, false if : num is out of range, or
101 //! name non-empty already set to another flag
102 Standard_EXPORT Standard_Boolean SetFlagName (const Standard_Integer num, const Standard_CString name);
104 //! Returns the count of flags (flag 0 not included)
105 Standard_EXPORT Standard_Integer NbFlags() const;
107 //! Returns the count of items (i.e. the length of the bitmap)
108 Standard_EXPORT Standard_Integer Length() const;
110 //! Returns the name recorded for a flag, or an empty string
111 Standard_EXPORT Standard_CString FlagName (const Standard_Integer num) const;
113 //! Returns the number or a flag given its name, or zero
114 Standard_EXPORT Standard_Integer FlagNumber (const Standard_CString name) const;
116 //! Returns the value (true/false) of a flag, from :
117 //! - the number of the item
118 //! - the flag number, by default 0
119 Standard_EXPORT Standard_Boolean Value (const Standard_Integer item, const Standard_Integer flag = 0) const;
121 //! Sets a new value for a flag
122 Standard_EXPORT void SetValue (const Standard_Integer item, const Standard_Boolean val, const Standard_Integer flag = 0) const;
124 //! Sets a flag to True
125 Standard_EXPORT void SetTrue (const Standard_Integer item, const Standard_Integer flag = 0) const;
127 //! Sets a flag to False
128 Standard_EXPORT void SetFalse (const Standard_Integer item, const Standard_Integer flag = 0) const;
130 //! Returns the former value for a flag and sets it to True
131 //! (before : value returned; after : True)
132 Standard_EXPORT Standard_Boolean CTrue (const Standard_Integer item, const Standard_Integer flag = 0) const;
134 //! Returns the former value for a flag and sets it to False
135 //! (before : value returned; after : False)
136 Standard_EXPORT Standard_Boolean CFalse (const Standard_Integer item, const Standard_Integer flag = 0) const;
138 //! Initialises all the values of Flag Number <flag> to a given
140 Standard_EXPORT void Init (const Standard_Boolean val, const Standard_Integer flag = 0) const;
142 //! Clear all field of bit map
143 Standard_EXPORT void Clear();
158 Standard_Integer thenbitems;
159 Standard_Integer thenbwords;
160 Standard_Integer thenbflags;
161 Handle(TColStd_HArray1OfInteger) theflags;
162 Handle(TColStd_HSequenceOfAsciiString) thenames;
173 #endif // _Interface_BitMap_HeaderFile