|
Last change
on this file since 20021 was 18521, checked in by Mathieu Morlighem, 11 years ago |
|
CHG: removed ALL dynamic casts, now change the template shared/Numerics/recast.h to change back to dynamic_casts
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [12546] | 1 | /*
|
|---|
| 2 | * recast.h
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jun 26, 2012
|
|---|
| 5 | * Author: utke
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef _RECAST_H_
|
|---|
| 9 | #define _RECAST_H_
|
|---|
| 10 |
|
|---|
| [13767] | 11 | #ifdef HAVE_CONFIG_H
|
|---|
| 12 | #include <config.h>
|
|---|
| 13 | #else
|
|---|
| 14 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 15 | #endif
|
|---|
| [12546] | 16 |
|
|---|
| [13767] | 17 | #if !defined(_HAVE_ADOLC_) || defined(_WRAPPERS_)
|
|---|
| 18 |
|
|---|
| [14975] | 19 | template<class To, class From> To reCast(const From& from) {
|
|---|
| [12546] | 20 | return (To)from;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | #else
|
|---|
| [14927] | 24 | #include "./types.h"
|
|---|
| [12546] | 25 |
|
|---|
| [14975] | 26 | template<class To, class From> struct ForPartialSpecialization {
|
|---|
| [12546] | 27 | static To reCast(const From& from ) { return (To) from;}
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| [14975] | 30 | template<class To, class From> To reCast(const From& from) {
|
|---|
| [12546] | 31 | return ForPartialSpecialization<To,From>::reCast(from);
|
|---|
| 32 | }
|
|---|
| 33 | /**
|
|---|
| 34 | * partial specialization
|
|---|
| 35 | */
|
|---|
| [14975] | 36 | template<class To> struct ForPartialSpecialization<To,adouble> {
|
|---|
| [12546] | 37 | static To reCast(const adouble& from ) { return (To) (from.getValue());}
|
|---|
| 38 | };
|
|---|
| 39 |
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| [18521] | 42 | /*Morlighem's change: we do not want dynamic_casts because of performance
|
|---|
| 43 | * issue, so for now, we just use C-like cast*/
|
|---|
| 44 | template<class To,class From> To xDynamicCast(const From& from) {
|
|---|
| 45 |
|
|---|
| 46 | /*C-like cast (fast but not safe)*/
|
|---|
| 47 | return (To) from;
|
|---|
| 48 |
|
|---|
| 49 | /*C++ dynamic_cast, poor performance but safer*/
|
|---|
| 50 | //return dynamic_cast<To>(from);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| [12546] | 53 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.