Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_safe_cast 4 #ifndef tools_safe_cast 5 #define tools_safe_cast 5 #define tools_safe_cast 6 6 7 #include "cid" 7 #include "cid" 8 8 9 namespace tools { 9 namespace tools { 10 10 11 template <class FROM,class TO> 11 template <class FROM,class TO> 12 inline TO* safe_cast(FROM& a_o) { 12 inline TO* safe_cast(FROM& a_o) { 13 return (TO*)a_o.cast(TO::s_class()); 13 return (TO*)a_o.cast(TO::s_class()); 14 } 14 } 15 15 16 template <class FROM,class TO> 16 template <class FROM,class TO> 17 inline const TO* safe_cast(const FROM& a_o) { 17 inline const TO* safe_cast(const FROM& a_o) { 18 return (const TO*)a_o.cast(TO::s_class()); 18 return (const TO*)a_o.cast(TO::s_class()); 19 } 19 } 20 20 21 template <class FROM,class TO> 21 template <class FROM,class TO> 22 inline TO* id_cast(FROM& a_o) { 22 inline TO* id_cast(FROM& a_o) { 23 return (TO*)a_o.cast(TO::id_class()); 23 return (TO*)a_o.cast(TO::id_class()); 24 } 24 } 25 25 26 template <class FROM,class TO> 26 template <class FROM,class TO> 27 inline const TO* id_cast(const FROM& a_o) { 27 inline const TO* id_cast(const FROM& a_o) { 28 return (const TO*)a_o.cast(TO::id_class()); 28 return (const TO*)a_o.cast(TO::id_class()); 29 } 29 } 30 30 31 } 31 } 32 32 33 #endif 33 #endif