bitWord
. At present, a bitWord is represented as an unsigned long, which restricts the number of distinct attributes to 32; this may be changed in future releases. An Attribute object represents a request to turn certain attributes of an object off, and to turn other attributes on. As a rule, constants of class Attribute are used to represent attributes, and users have no need to know whether a given property is represented by a true or false bit in the bitWord. Although we would prefer to have a constructor for Attribute objects of the form
Attribute(bitWord bitsOn, bitWord bitsOff);it has turned out that doing so presents severe problems with order of construction, since a number of global Attribute objects are used and there is no simple, portable way of guaranteeing that these objects are constructed before any use. As a result, the
bitsOn
and bitsOff
members are public, but we forbid use of that fact except in one place: constant Attribute objects can be initialized by the C "aggregate form", as in the following example:
extern const Attribute P_HIDDEN = {PB_HIDDEN, 0};(This particular attribute is used by Porthole to indicate that a port should not be visible to the user, i.e. should not appear on an icon.) The first word specified is the
bitsOn
field, PB_HIDDEN, and the second word specified is the bitsOff
field. Other than to initialize objects, we pretend that these data members are private.
Attribute& operator |= (const Attribute& arg);These operations combine attributes, by applying the
Attribute& operator &= (const Attribute& arg);
|=
and &=
operators to the bitsOn and bitsOff fields. The first operation, as attributes are commonly used, represents a requirement that two sets of attributes be met, so it has been argued that it really should be the "and" operation. However, the current scheme has the virtue of consistency.
bitWord eval(bitWord defaultVal) const;Evaluate an attribute given a default value. Essentially, bits corresponding to bitsOn are turned on, and then bits corresponding to bitsOff are turned off.
bitWord clearAttribs(bitWord defaultVal) const;This method essentially applies the attribute backwards, reversing the roles of bitsOn and bitsOff in
eval.
bitWord on() const;Retrieve the bitsOn and bitsOff values, respectively. Inline definitions of operators
bitWord off() const;
&
and |
are also defined to implement nondestructive forms of the &=
and |=
operations.