Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cmessage30.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Andras Varga
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef __CMESSAGE30_H
00020 #define __CMESSAGE30_H
00021 
00022 #include <omnetpp.h>
00023 
00024 #if OMNETPP_VERSION>0x0230
00025 #define OPP3
00026 #endif
00027 
00028 
00029 #ifdef OPP3
00030 
00031 typedef cMessage cMessage30;
00032 #define M30(p)  (p)
00033 
00034 #else
00035 
00039 class cPolymorphic
00040 {
00041   public:
00042     virtual ~cPolymorphic() {}
00043     virtual const char *className() const  {return opp_typename(typeid(*this));}
00044     virtual const char *fullName() const  {return "";}
00045     virtual const char *fullPath() const {return fullName();}
00046 };
00047 
00048 template<class T>
00049 T check_and_cast(cPolymorphic *p)
00050 {
00051     if (!p)
00052         throw new cException("check_and_cast(): cannot cast NULL pointer to type '%s'",opp_typename(typeid(T)));
00053     T ret = dynamic_cast<T>(p);
00054     if (!ret)
00055         throw new cException("check_and_cast(): cannot cast (%s *)%s to type '%s'",p->className(),p->fullPath(),opp_typename(typeid(T)));
00056     return ret;
00057 }
00058 
00062 class cMessage30 : public cMessage
00063 {
00064   protected:
00065     cPolymorphic *ctrlp;
00066   public:
00067     explicit cMessage30(const char *name=NULL, int kind=0) : cMessage(name,kind) {ctrlp=NULL;}
00068     cMessage30(const cMessage30& m) : cMessage() {setName(m.name());ctrlp=NULL;operator=(m);}
00069     cMessage30& operator=(const cMessage30& m)  {if(this==&m) return *this; ASSERT(!ctrlp); cMessage::operator=(m); return *this;}
00070     virtual cObject *dup() const {return new cMessage30(*this);}
00071     cPolymorphic *controlInfo() const {return ctrlp;}
00072     cPolymorphic *removeControlInfo() {cPolymorphic *p=ctrlp;ctrlp=NULL; return p;}
00073     void setControlInfo(cPolymorphic *p)  {ASSERT(p&&!ctrlp);ctrlp=p;}
00074 };
00075 
00076 #define M30(p)  check_and_cast<cMessage30*>(p)
00077 
00078 #endif
00079 
00080 #endif
00081 
00082 

Generated on Sat May 15 20:30:42 2004 for Ethernet by doxygen1.2.17