Rogue Wave banner
Previous fileTop of DocumentContentsNext file

5.3 A Phone Number Formatting Facet Class

Now that we have locales and facets in C++, we can encapsulate the locale-dependent parsing and formatting of telephone numbers into a new facet class. Let's focus on formatting in this example. We will call the new facet class phone_put, analogous to time_put, money_put, etc.

The phone_put facet class serves solely as a base class for facet classes that actually implement the locale-dependent formatting. The relationship of class phone_put to the other facet classes is illustrated in Figure 13:

Figure 13 -- The relationship of the phone_put facet to the implementing facets

Diagram showing the relationship of the phone_put facet to the implementing facets.

Here is a first tentative declaration of the new facet class phone_put:

//1Derive from the base class locale::facet, so that a locale object will be able to maintain instances of our new phone facet class.
//2New base facet classes need to define a static data member id of type locale::id.
//3Define a constructor that takes the reference count that will be handed over to the base class.
//4Define a function put() that does the actual formatting.

Previous fileTop of DocumentContentsNext file

©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.


OEM Release, June 1998