Class: TStyleSet

Declaration: StyleSet.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

MReferencedCollectible

Inherited By:

None.

Purpose:

TStyleSet, derived from MReferencedCollectible, encapsulates a collection of text styles that can be applied to a range of characters. Although style sets are not immutable, the styles they contain are. You change a style set by adding and/or removing styles.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

Although value semantics are used externally, derived classes must take into account the fact that copy-on-write semantics are used internally. The internal storage for style sets can be shared across multiple style sets with reference counting. However, modifications to one style set should never affect another one. Therefore, the implementation of member functions that change the contents of a style set must call CopySharedDataBeforeWrite before making changes. Derived classes must preserve the value semantics presented to clients of class TStyleSet. Reference counting is used with style sets at two levels. Internal storage is reference counted. Externally, the style sets as a whole can be reference counted too. The Unreachable member function is inherited from the mixin class, MReferenceCounted. As defined for class MReferenceCounted, Unreachable is called when the reference count on an object reaches zero. Normally, all that is necessary is to override the inherited version with one that deletes an instance of your derived class.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TStyleSet::MemberByValue

  1. virtual bool MemberByValue (const TStyle & style) const
  2. virtual bool MemberByValue (const TStyleSet & set) const
  3. virtual bool MemberByValue (const TStyleSet & set, TStyleSet & members) const

Interface Category:

API.

Purpose:

Compares, by value, one or more styles against the contents of this style set. Two styles are equal when compared by value if the styles have the same category, name, and internal values.

Calling Context:

  1. Called when checking a single style for membership in this style set.
  2. Called when checking multiple styles for membership in this style set.
  3. Called when checking multiple styles for membership in this style set and you want to know which styles were found when one or more of the styles being searched for were not found.

Parameters:

Return Value:

Returns true if all styles being checked for membership by value were found.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::MemberByName

  1. virtual bool MemberByName (const TStyle & style) const
  2. virtual bool MemberByName (const TStyleSet & set) const
  3. virtual bool MemberByName (const TStyleCategory & category, const TStyleName & name) const
  4. virtual bool MemberByName (const TStyle & style, const TStyle * & member) const
  5. virtual bool MemberByName (const TStyleSet & set, TStyleSet & members) const
  6. virtual bool MemberByName (const TStyleCategory & category, const TStyleName & name, const TStyle * & member) const

Interface Category:

API.

Purpose:

Compares, by name, one or more styles against the contents of this style set. Two styles are equal when compared by name if the styles have the same category and name. The internal values do not have to be the same to produce a match by name.

Calling Context:

  1. Called when checking a single style for membership in this style set.
  2. Called when checking multiple styles for membership in this style set.
  3. Called when checking by style category and style name for a matching style in this style set.
  4. Called when checking a single style for membership in this style set and you want to know the value of the matching style when one is found in this style set.
  5. Called when checking multiple styles for membership in this style set and you want to know the value of the matching styles when one or more matches are found in this style set.
  6. Called when checking by style category and style name for a matching style in this style set and you want to know the value of the matching style when one is found in this style set.

Parameters:

Return Value:

Returns true if all styles being checked for membership are found.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::Add

  1. virtual void Add (const TStyle & style)
  2. virtual void Add (const TStyleSet & set)

Interface Category:

API.

Purpose:

Adds one or more styles to this style set.

Calling Context:

  1. Called when adding a single style to this style set.
  2. Called when adding multiple styles to this style set.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Due to the invariant of style sets that there can never be two styles with the same category and name in the same style set, adding a style can effectively replace one style with another. This happens when the style being added is already represented in this style set by another style with the same category and name.

Member Function: TStyleSet::Remove

  1. virtual void Remove (const TStyleCategory & category, const TStyleName & name)
  2. virtual void Remove (const TStyle & style)
  3. virtual void Remove (const TStyleSet & set)

Interface Category:

API.

Purpose:

Removes one or more styles from this style set.

Calling Context:

  1. Called when removing the style with the specified category and specified name from this style set.
  2. Called when removing a single style from this style set.
  3. Called when removing multiple styles from this style set.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::RemoveAll

virtual void RemoveAll ()

Interface Category:

API.

Purpose:

Removes all styles from this style set.

Calling Context:

Called when you want to remove all styles from a style set.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::RemoveNonPropagatingStyles

virtual void RemoveNonPropagatingStyles ()

Interface Category:

API.

Purpose:

Removes all nonpropagating styles from this style set.

Calling Context:

Called in word-processing software that wants to ignore the nonpropagating styles in a style set.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::Count

  1. virtual long Count () const
  2. virtual long Count (const TStyleCategory & category) const

Interface Category:

API.

Purpose:

  1. Gets the total number of styles in this style set.
  2. Gets the number of styles in the specified style category.

Calling Context:

  1. Called when you need to know the total number of styles in a style set.
  2. Called when you need to know the number of styles in a style set that are part of one particular category.

Parameters:

Return Value:

The number of styles for the entire style set or in the specified category only.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::CreateIterator

  1. virtual TStyleSetIterator * CreateIterator () const
  2. virtual TStyleSetIterator * CreateIterator (const TStyleCategory & category) const

Interface Category:

API.

Purpose:

  1. Returns an iterator for the entire style set. Used to iterate over all the styles in a style set regardless of the category for each style.
  2. Returns an iterator for the specified style category. Used to iterate over only the styles in the specified category.

Calling Context:

  1. Called when iteration over all the styles is required.
  2. Called when iteration over the styles in a single category is required.

Parameters:

Return Value:

The newly created TStyleSetIterator is returned and ownership of the storage for this new object is passed to the caller.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::operator==

virtual bool operator ==(const TStyleSet & that) const

Interface Category:

API.

Purpose:

Compares two objects for equality. Two style sets are equal when they have exactly the same number of styles with the same values for each style in both sets.

Calling Context:

Called to compare two style sets for equality.

Parameters:

Return Value:

Returns true if the two style sets are equivalent. This does not mean they have to be the exact same style set though. It merely means that the contents of the two sets are the same.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::CopySharedDataBeforeWrite

virtual void CopySharedDataBeforeWrite ()

Interface Category:

API.

Purpose:

Makes a copy of internal data so that this style set has a reference count of one. Derived classes that add new member functions that modify the style set must call this member function to preserve the internal implementation of copy-on-write semantics.

Calling Context:

Called in a new member function added to a derived class of TStyleSet that changes the contents of the style set.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This is only of concern to implementors of derived classes.

Member Function: TStyleSet::Unreachable

virtual void Unreachable ()

Interface Category:

API.

Purpose:

Deletes this object. Derived classes must override this member function to do the same thing for their derived classes.

Calling Context:

Not intended to be called directly by clients. Rather, the manager classes that keep track of reference counting on style sets call this member function when the reference count of a style set has reached zero.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::Hash

virtual long Hash () const

Interface Category:

API.

Purpose:

Generates a hash value.

Calling Context:

Called to generate a hash value.

Parameters:

Return Value:

The numeric value of the hash.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::operator!=

bool operator != (const TStyleSet & that) const

Interface Category:

API.

Purpose:

Determines if two objects are not equal.

Calling Context:

Called to compare two objects.

Parameters:

Return Value:

Returns true if the objects are not equal.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

This function is implemented in terms of the operator ==function, and therefore does not need to be overridden by derived classes.

Member Function: TStyleSet::operator<<=

virtual TStream & operator <<= (TStream & fromStream)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Throws the exception TTextException::kInvalidVersionNumber when the streamed in version number cannot be handled.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::operator>>=

virtual TStream & operator >>=(TStream & toStream) const

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

Called to stream out data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::operator=

TStyleSet & operator =(const TStyleSet & set)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::~TStyleSet

virtual ~ TStyleSet ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::TStyleSet

  1. TStyleSet ()
  2. TStyleSet (const TStyle & style)
  3. TStyleSet (const TStyleSet & set)

Interface Category:

API.

Purpose:

  1. Default constructor. Constructs an empty style set.
  2. Constructs a style set containing the specified style object.
  3. Copy constructor.

Calling Context:

  1. Called by the stream-in operators.
  2. Called to construct a style set containing a single specified style object.
  3. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::GetEmptyStyleSet

static const TStyleSet & GetEmptyStyleSet ()

Interface Category:

API.

Purpose:

Returns an empty style set.

Calling Context:

Called when you need to return an empty style set.

Parameters:

Return Value:

An empty style set.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TStyleSet::GetStamp

TPseudoTimeStamp GetStamp () const

Interface Category:

API.

Purpose:

Returns a TPseudoTimeStamp that is used as a unique identifier for style sets. Style sets with the same stamp values are guaranteed to be equal. Style sets with different stamp values are not guaranteed to be different. The only way that two style sets can have the same stamp is if one is a copy, created using the copy constructor or operator=, of the other. The stamp value is not maintained across streaming. Note: According to the definition of Hash, two unequal style sets can have the same value returned by Hash. On the other hand, two unequal style sets will never have the same values returned by GetStamp.

Calling Context:

Called to compare the time stamps of two style sets. If the two time stamps are equal, then the two style sets are equal.

Parameters:

Return Value:

Returns a TPseudoTimeStamp that is used as a unique identifier for style sets.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The stamp value is not maintained across streaming.

Member Function: TStyleSet::IsEmpty

virtual bool IsEmpty () const

Interface Category:

API.

Purpose:

Determines if the style set contains any styles. IsEmpty returns false as soon as the first style is encountered. For performance, it is better to use this member function than the Count member function to determine if there are any styles in the set. The Count member function iterates through all of the styles in the set, so using the count to determine if the style set is empty can be time consuming if there are several styles in the set.

Calling Context:

Called to determine if there are any styles in a given style set.

Parameters:

Return Value:

Returns true if there are no styles in the set, false otherwise.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.