source: issm/trunk/src/c/shared/Numerics/recast.h

Last change on this file was 23394, checked in by Mathieu Morlighem, 6 years ago

merged trunk-jpl and trunk for revision 23392

File size: 1.4 KB
Line 
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
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
16
17#if !defined(_HAVE_AD_) || defined(_WRAPPERS_)
18
19template<class To, class From> To reCast(const From& from) {
20 return (To)from;
21}
22
23#else
24#include "./types.h"
25
26template<class To, class From> struct ForPartialSpecialization {
27 static To reCast(const From& from ) { return (To) from;}
28};
29
30template<class To, class From> To reCast(const From& from) {
31 return ForPartialSpecialization<To,From>::reCast(from);
32}
33/**
34 * partial specialization
35 */
36#ifdef _HAVE_ADOLC_
37template<class To> struct ForPartialSpecialization<To,adouble> {
38 static To reCast(const adouble& from ) { return (To) (from.getValue());}
39};
40#endif
41#ifdef _HAVE_CODIPACK_
42template<class To> struct ForPartialSpecialization<To,IssmDouble> {
43 static To reCast(const IssmDouble& from ) { return (To) (from.getValue());}
44};
45#endif
46
47#endif
48
49/*Morlighem's change: we do not want dynamic_casts because of performance
50 * issue, so for now, we just use C-like cast*/
51template<class To,class From> To xDynamicCast(const From& from) {
52
53 /*C-like cast (fast but not safe)*/
54 return (To) from;
55
56 /*C++ dynamic_cast, poor performance but safer*/
57 //return dynamic_cast<To>(from);
58}
59
60#endif
Note: See TracBrowser for help on using the repository browser.