c++ - Meaning of Macro definition of the code below -
in header file code is:
#define classtp(tnm, pnm) \ class tnm; \ typedef tpt<tnm> pnm; \ class tnm{ \ private: \ tcref cref; \ public: \ friend class tpt<tnm>;
why there tnm{
there without }
following form pair, legal? , have no idea what's meaning of piece os code.
then in other files, macro definition used follows:
classtp(tnotify, pnotify)//{ private: tnotify(const tnotify&); tnotify& operator=(const tnotify&); public: tnotify(){} virtual ~tnotify(){} virtual void onnotify(const tnotifytype& /*type*/, const tstr& /*msgstr*/){} virtual void onstatus(const tstr& /*msgstr*/){} virtual void onln(const tstr& /*msgstr*/){} virtual void ontxt(const tstr& /*msgstr*/){} // shortcuts easier formationg void onnotifyfmt(const tnotifytype& type, const char *fmtstr, ...); void onstatusfmt(const char *fmtstr, ...); void onlnfmt(const char *fmtstr, ...); void ontxtfmt(const char *fmtstr, ...); static tstr gettypestr( const tnotifytype& type, const bool& brief=true); static void onnotify(const pnotify& notify, const tnotifytype& type, const tstr& msgstr){ if (!notify.empty()){notify->onnotify(type, msgstr);}} static void onstatus(const pnotify& notify, const tstr& msgstr){ if (!notify.empty()){notify->onstatus(msgstr);}} static void onln(const pnotify& notify, const tstr& msgstr){ if (!notify.empty()){notify->onln(msgstr);}} static void ontxt(const pnotify& notify, const tstr& msgstr){ if (!notify.empty()){notify->ontxt(msgstr);}} static void dfonnotify(const tnotifytype& type, const tstr& msgstr); static const pnotify nullnotify; static const pnotify stdnotify; static const pnotify stderrnotify; };
in first line of one, there classtp(tnotify, pnotify)//{
curious why bracelet commented out original programmer , no code can still work normal.
the c++ preprocessor performs dummy text replacement before compiling code , expands macro classtp(tnm, pnm)
into
class tnm; typedef tpt<tnm> pnm; class tnm{ private: tcref cref; public: friend class tpt<tnm>;
which represents forward declaration followed typedef
followed beginning of class declaration. need manually close brace };
after end class declaration, i.e. after you're done adding member functions/variables following macro. that's why in example posted there no need opening brace (as macro expansion opens it), need close it. brace commented out otherwise syntax invalid. comment there make aware that's place class definition begins (excluding typedef , forward declaration).
as code represents, cannot sure. looks kind of observer pattern.
Comments
Post a Comment