better proceed c++ named parameter idiom?
i've building gui library windows (as personal side project, aspirations usefulness). sure window class, i've set adult hierarchy choice classes (using ), since options common others specific sole forms windows (like dialogs).
the proceed named parameter jargon works, functions parameter category have relapse vigilant they're called on. problem that, hierarchy, any different category -- createwindowopts category customary windows, createdialogopts category dialogs, like. i've dealt origination choice classes templates. here's an example:
template <class t>
class _sharedwindowopts: open detail::_basecreatewindowopts {
public: ///////////////////////////////////////////////////////////////
// mandatory parameters case.
_sharedwindowopts() { };
typedef t opttype;
// ordinarily used options
opttype& at(int x, int y) { mx=x; my=y; relapse static_cast<opttype&>(*this); }; // where put upper-left dilemma window; specified, component sets default position
opttype& at(int x, int y, int width, int height) { mx=x; my=y; mwidth=width; mheight=height; relapse static_cast<opttype&>(*this); }; // sets position distance window unparalleled call
opttype& background(hbrush b) { mbackground=b; relapse static_cast<opttype&>(*this); }; // sets default credentials brush
opttype& background(int_ptr b) { mbackground=hbrush(b+1); relapse static_cast<opttype&>(*this); }; // sets default credentials color_* colors; defaults color_window
opttype& cursor(hcursor c) { mcursor=c; relapse static_cast<opttype&>(*this); }; // sets default rodent cursor window; defaults customary arrow
opttype& hidden() { mstyle&=~ws_visible; relapse static_cast<opttype&>(*this); }; // windows manifest default
opttype& icon(hicon iconlarge, hicon iconsmall=0) { micon=iconlarge; msmallicon=iconsmall; relapse static_cast<opttype&>(*this); }; // specifies icon, optionally little icon
// ...many others removed...
};
template <class t>
class _createwindowopts: open _sharedwindowopts<t> {
public: ///////////////////////////////////////////////////////////////
_createwindowopts() { };
// can't used child windows, aren't needed
opttype& menu(hmenu m) { mmenuorid=m; relapse static_cast<opttype&>(*this); }; // gives window menu
opttype& owner(hwnd hwnd) { mparentorowner=hwnd; relapse static_cast<opttype&>(*this); }; // sets discretionary parent/owner
};
class createwindowopts: open _createwindowopts<createwindowopts> {
public: ///////////////////////////////////////////////////////////////
createwindowopts() { };
};
it works, nonetheless see, requires conspicuous volume additional work: type-cast relapse form any function, additional template classes, etcetera.
my doubt is, there an easier proceed exercise named parameter jargon case, doesn't need additional stuff?
Comments
Post a Comment