Boost logo

Boost Users :

Subject: Re: [Boost-users] Needs advices on design ( mpl or processor )
From: Allan Nielsen (a_at_[hidden])
Date: 2012-01-10 12:43:59


Hi

Just for the record, here is the souce code I ended up using.

It is quite different from the compressed-tuple source, and the source
code Larry suggested. It is most likely not as generric as these
alternativies and it will only work with simple types as
storege-buffer.

But it has some features which is important for me:

- Struct like groups
EXAMPLE:
    CompressedEnums<
        unsigned,
        CompressedEnum<e1>,
        EnumStruct<e2,
            CompressedEnum<e1>,
            CompressedEnum<e2>,
            CompressedEnum<e3>
>,
        CompressedEnum<e3>,
        CompressedEnum<e4>
> ce2;

    ce2.set<e1>(e1::E1);
    std::cout << ce2.get<e1>() << std::endl;

    ce2.set<e2, e1>(e1::E1);
    std::cout << ce2.get<e2, e1>() << std::endl;

- Unions like groups
    CompressedEnums<
        unsigned,
        CompressedEnum<e1>,

        EnumUnion<e2,
            CompressedEnum<e1>,
            CompressedEnum<Abc>,
            CompressedEnum<YesNoMaby>
>,
        CompressedEnum<e3>
> ce7;

    ce7.set<e2, Abc>(Abc::B);
    cout << ce7.get<e2, e1>() << " " <<
            ce7.get<e2, Abc>() << " " <<
            ce7.get<e2, YesNoMaby>() << endl;
    ce7.set<e2, Abc>(Abc::A);
    cout << ce7.get<e2, e1>() << " " <<
            ce7.get<e2, Abc>() << " " <<
            ce7.get<e2, YesNoMaby>() << endl;
    ce7.set<e2, YesNoMaby>(YesNoMaby::Maby);
    cout << ce7.get<e2, e1>() << " " <<
            ce7.get<e2, Abc>() << " " <<
            ce7.get<e2, YesNoMaby>() << endl;

- Arrays (of leafs only)
    CompressedEnums<
        unsigned,
        CompressedEnum<e1>,
        CompressedEnumArray<Abc, 5>,
        CompressedEnum<e3>
> ce6;

    ce6.data = 0;
    for (int i = 0; i < ce6.get_size<Abc>(); i++) {
        std::cout << ce6.get<4, Abc>() <<
                     ce6.get<3, Abc>() <<
                     ce6.get<2, Abc>() <<
                     ce6.get<1, Abc>() <<
                     ce6.get<0, Abc>() <<
                     std::endl;
        ce6.next<0, Abc>();
    }

Comments are always appreciated, but before you dive into the code, I
should warn you that this is the first time I have tried to sue the
boost::mpl for something ( other than playing around ).

Thanks for all the help and inputs.

Best regards
Allan W. Nielsen




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net