liang brain / Mbed 2 deprecated EX_encoder_PID_QianYuyangV3

Dependencies:   mbed QEI-1 nRF24L01P xiugai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers converters.h Source File

converters.h

00001 #pragma once
00002 
00003 #include <cstdlib>
00004 #include <string>
00005 
00006 namespace std{
00007 static inline int stoi(const string &s) {
00008     return atoi(s.c_str());
00009 }
00010 static inline long stol(const string &s) {
00011     return atol(s.c_str());
00012 }
00013 static inline float stof(const string &s) {
00014     return float(atof(s.c_str()));
00015 }
00016 #define _c_to_string(fmt,val) { \
00017     char buf[16];\
00018     snprintf(buf, sizeof(buf), fmt, val);\
00019     return string(buf);\
00020 }
00021 static inline string to_string(bool v) {
00022     _c_to_string("%d", (int)v);
00023 }
00024 static inline string to_string(char v) {
00025     _c_to_string("%c", v);
00026 }
00027 static inline string to_string(int v) {
00028     _c_to_string("%d", v);
00029 }
00030 static inline string to_string(long v) {
00031     _c_to_string("%ld", v);
00032 }
00033 static inline string to_string(float v) {
00034     _c_to_string("%f", v);
00035 }
00036 }
00037 
00038 inline bool  _p(bool x) { return x; }
00039 inline char  _p(char x) { return x; }
00040 inline int   _p(int x) { return x; }
00041 inline long  _p(long x) { return x; }
00042 inline float _p(float x) { return x; }
00043 inline void* _p(void* x) { return x; }
00044 inline const char* _p(const std::string &x) { return x.c_str(); }
00045