Developer documentation

assign.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * This file is part of the source code of realroot library. *
3 * Author(s): B. Mourrain, GALAAD, INRIA *
4 **********************************************************************
5 History:
6 $Id: let.hpp,v 1.3 2005/09/28 06:40:43 mourrain Exp $
7 **********************************************************************/
8 #ifndef mmx_assign_hpp
9 #define mmx_assign_hpp
10 //--------------------------------------------------------------------
11 #include <cstdlib>
12 #include <complex>
13 #include <stdio.h>
14 #include <iostream>
15 
16 #include <sstream>
17 //====================================================================
18 //namespace std {template<class C> struct complex;}
19 //--------------------------------------------------------------------
20 namespace mmx {
21 
24 inline std::string to_string(int x) {
25  int sz=1,m=1;
26  while(m<x) {m*=10; sz++;} sz++;
27  char str[sz];
28  sprintf(str,"%i",x);
29  return std::string(str);
30  //return std::to_string(x);
31 }
32 //inline std::string to_string(unsigned x) { return std::to_string(x);}
33 
34 
37 inline std::string to_string(double x) {
38  char str[20];
39  sprintf(str,"%f",x);
40  return std::string(str);
41  // return std::to_string(x);
42 }
43 
44 #ifndef WITH_AS
45 #define WITH_AS
46 
47 
48 template<typename T,typename F> struct as_helper {
49  static inline T cv (const F& x) { return T(x); }
50 };
51 template<typename T,typename F> inline T as (const F& x) {
52  return as_helper<T,F>::cv (x);
53 }
54 
55 template<typename T,typename F, class U> inline T
56 as (const F& x, const U& u) {
57  return as_helper<T,F>::cv (x,u);
58 }
59 
60 template<typename T,typename F, class U, class V> inline T
61 as (const F& x, const U& u, const V& v) {
62  return as_helper<T,F>::cv (x,u,v);
63 }
64 #endif
65 
66 template<> struct as_helper<double,char*> {
67  static inline double cv (char* x) {
68  double r;
69  //std::istringstream in(x); in>>r;
70  r=atof(x);
71  return r;
72  }
73 };
74 
75 template<> struct as_helper<double,const char*> {
76  static inline double cv (const char* x) {
77  double r;
78  //std::istringstream in(x); in>>r;
79  r = atof(x);
80  return r;
81  }
82 };
83 
84 //====================================================================
86 
92 namespace let {
93 //--------------------------------------------------------------------
94 // template<class A, class B> inline void assign(A& a, const B& b);
95 //--------------------------------------------------------------------
97 template<class A, class B> inline void assign(A& a, const B & b) {
98  a=as<A>(b);
99 }
100 inline void assign( int & a, double d ) { if( ceil(d)==floor(d) ){int numb = (int)ceil(d);if(numb%2==0){a = (int)ceil(d);}else{a = (int)floor(d);}}else{a = (int)floor(d+0.5);} };
101 //--------------------------------------------------------------------
102 inline void assign(double & d, int i) {d = double(i);}
103 inline void assign(double & d, unsigned i) {d = double(i);}
104 inline void assign(double & d, double z) {d = z;}
105 //--------------------------------------------------------------------
106 template<class C> inline void
107 assign(std::complex<C> & z, const C& x) { z= std::complex<C>(x);}
108 //--------------------------------------------------------------------
109 template<class X> inline void assign(X & a, const char *s) { std::istringstream in(s); in >>a; }
110 //----------------------------------------------------------------------
111 //template<> inline void assign(int &i, const char *s) {i = atoi(s);}
112 //template<> inline void assign(long int &i, const char *s) {i = atol(s);}
113 //----------------------------------------------------------------------
114 #ifndef __CYGWIN__
115 template<> inline void assign(long long int &i, const char *s){std::istringstream in(s); in >>i;}
116 #endif //__CYGWIN__
117 //----------------------------------------------------------------------
118 // template<>
119 //inline void assign(float & d, char* s) {d = atof(s);}
120 // template<>
121 //inline void assign(double & d, char* s) {d = atof(s);}
122 //template<> inline void assign(double & d, const char* s) {d = atof(s);}
123 
124 // template<>
125 //inline void assign(long double & d, char *s) {d = atof(s);}
126 //--------------------------------------------------------------------
127 template<> inline void
128 assign(std::complex<double> & z, const char* s) {
129  z = std::complex<double>(atof(s),0);
130 }
131 //--------------------------------------------------------------------
132 }
133 //========================================================================
134 } //namespace mmx
135 //========================================================================
136 #endif // realroot_assign_hpp
137 
const C & b
Definition: Interval_glue.hpp:25
TMPL X
Definition: polynomial_operators.hpp:148
Definition: assign.hpp:48
static double cv(const char *x)
Definition: assign.hpp:76
static T cv(const F &x)
Definition: assign.hpp:49
std::string to_string(int x)
to_string convert int to std::string In C++11, it should use std::to_string
Definition: assign.hpp:24
T as(const F &x)
Definition: assign.hpp:51
bool in(const T &x, const Interval< T, r > &y)
Definition: Interval_fcts.hpp:100
static double cv(char *x)
Definition: assign.hpp:67
double C
Definition: solver_mv_fatarcs.cpp:16
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Definition: array.hpp:12
Home