Boost logo

Boost :

From: Maksym Motornyy (mmotorny_at_[hidden])
Date: 2005-06-20 02:50:42


Sebastien Martel wrote:
> Is there a way to integrate a solution to this problem :
>
> [google groups] http://tinyurl.com/dtnx3
>
> -seb

Yes, that's actually enumerator-specific methods are what for. Here is
an example how it can be done with my library.

class part_of_speech_policy
{
public:
     class base_enumerator
     {
     public:
         virtual const char *get_encoding() const = 0;
     };

     class coordinating_conjunction: public base_enumerator
     {
     public:
         const char *get_encoding() const
         {
             return "CC";
         }
     };

     class cardinal_number: public base_enumerator
     {
     public:
         const char *get_encoding() const
         {
             return "CD";
         }
     };

     class determiner: public base_enumerator
     {
     public:
         const char *get_encoding() const
         {
             return "DT";
         }
     };

     typedef boost::mpl::vector<
           coordinating_conjunction
         , cardinal_number
         , determiner
> enumerators;
};

typedef boost::enumeration< part_of_speech_policy > part_of_speech;

// somewhere in other place

BOOST_STATIC_ASSERT( part_of_speech::size == 3 );
part_of_speech foo = part_of_speech::coordinating_conjunction();
BOOST_CHECK_EQUAL( foo->get_encoding(), "CC" );

Hope it does what you expected.

Sincerely yours,
Maksym Motornyy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk