Boost logo

Boost Users :

Subject: [Boost-users] Is there any Template [Meta] Programming Technique available to achieve this?
From: A L (alapex0310_at_[hidden])
Date: 2010-07-12 06:42:22


I am working on a UI system. I have created a prototype factory using the
regular pattern. The abstract "product" class (each product class takes only
the "name" of the product as the parameter) which is the parent of all the
product classes that the proto-factory creates, contains a lonnnnnng
enumeration - each product class uses some of the enumerators contained
inside the enumeration. Having developed the factory, I have realized that
there are various other "thing" that I can "manufacture" using the same
approach. So, I want to re-use the proto-factory. For that I need to
templatize the product classes and the factory class and need to
"manufacture" the proto-factory itself from a proto-factory generator class
(another factory, that is). The problem is, the different
enumerators/constants required by each product class don't allow me
genericize the design. For example, I have an Align class which uses the
following enumeration:

    enum text_align_type
        text_align_not_set = -1,
        text_align_left = align_left_key,
        text_align_center = align_center_key,
        text_align_right = align_right_key,
        text_align_justified = align_just_key

Now the Align class takes the string "Align" as its constructor parameter
and sets one of its values to text_align_not_set using the initialization
list. It makes use of all of the above enumeration constants in its
validation and so on. Since the proto-factory is creating the products by
cloning using the copy constructors of the registered objects, I think a
solution would be to pass all these enumeration constants in the constructor
of each product class (besides the productName argument which is already
being passed to each product class constructor). This way, I will need to
create/registered these products only once in the proto-factory registry and
subsequent products will then be generated/manufactured (i.e.
copy-constructed) from the registered products.

Passing enumeration constants in constructors for the sole purpose of
validation, etc. seems to be a bit inefficient to me. Yet I also want to
re-use the design. I wonder if I could use Boost and its
template/meta-programming magic to somehow pass these enumeration constants
to each product class without having to pass them in product class
constructors. Any ideas?


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at