From: <sv...@ww...> - 2004-07-25 18:50:50
|
Author: mkrose Date: 2004-07-25 11:50:43 -0700 (Sun, 25 Jul 2004) New Revision: 1180 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/TaggedRecord.h Log: Add a fast typecast operator to TaggedRecord, which checks record ids and performs a static cast if the ids match. This is much faster (and just as safe) as using implicit dynamic_casts via Ref assignments. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1180 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-07-25 03:01:25 UTC (rev 1179) +++ trunk/CSP/SimData/CHANGES.current 2004-07-25 18:50:43 UTC (rev 1180) @@ -1,5 +1,11 @@ Version 0.4.0 (in progress) =========================== +2004-07-25: onsight + * Add a fast typecast operator to TaggedRecord, which checks record + ids and performs a static cast if the ids match. This is much + faster (and just as safe) as using implicit dynamic_casts via + Ref assignments. + 2004-07-21: onsight * Add missing include. Modified: trunk/CSP/SimData/Include/SimData/TaggedRecord.h =================================================================== --- trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-07-25 03:01:25 UTC (rev 1179) +++ trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-07-25 18:50:43 UTC (rev 1180) @@ -444,6 +444,10 @@ virtual std::string getName() const=0; virtual void dump(std::ostream &, int indent=0) const=0; virtual int getCustomId() const=0; + template <class TR> + static inline Ref<TR> FastCast(Ref const &record) { + return (record->getId() == TR::_getId() ? static_cast<TR*>(record.get()) : 0); + } protected: virtual ~TaggedRecord() {} }; |