Boost logo

Boost Users :

Subject: [Boost-users] Boost preprocessor question
From: Michiel Helvensteijn (m.helvensteijn_at_[hidden])
Date: 2009-01-04 16:53:58


I'm looking for a way to write certain kinds of classes without duplication
or unnecessary verbosity. Because there will be many of them in a single
file and I want them to be readable.

I'm trying to decide if I should use the preprocessor or if I should write a
script to do the translation before compilation. I would like something
like this (how I think it might look):

CLASS(Foo, FROM(Bar))
    CONSTRUCT()
    CONSTRUCT(PAR(int, a, A), PAR(bool, b, B))
    int A;
    bool B;
END_CLASS

to automatically become something like this:

class Foo : public Bar, public shared_from_this<Foo> {
    private: Foo() {}
    public: static shared_ptr<Foo> construct() {
        return shared_ptr<Foo>(new Foo());
    }
    private: Foo(int a, bool b) : A(a), B(b) {}
    public: static shared_ptr<Foo> construct(int a, bool b) {
        return shared_ptr<Foo>(new Foo(a, b));
    }
    int A;
    bool B;
};

Is such a thing possible? You see, there are a few things happening there:

* Variable length list, reproduced more than once in different ways.
* Foo is remembered to use in the constructor name.

What would the original code look like if we could make this work? And is
there something in the boost preprocessor library that can help me?

Thanks in advance!

-- 
Michiel Helvensteijn

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