Marsyas  0.2
/home/gperciva/src/marsyas/src/marsyas/ExCommon.cpp
00001 #include "ExCommon.h"
00002 
00003 using namespace Marsyas;
00004 
00005 unsigned int
00006 ex_string_to_typeid(std::string tp)
00007 {
00008     if (tp=="mrs_unit") return ExT_mrs_unit;
00009     if (tp=="mrs_bool") return ExT_mrs_bool;
00010     if (tp=="mrs_natural") return ExT_mrs_natural;
00011     if (tp=="mrs_real") return ExT_mrs_real;
00012     if (tp=="mrs_string") return ExT_mrs_string;
00013     if (tp=="mrs_timer") return ExT_mrs_timer;
00014     if (tp=="mrs_scheduler") return ExT_mrs_scheduler;
00015     return 0;
00016 }
00017 
00018 std::string
00019 ex_typeid_to_string(unsigned int tp)
00020 {
00021     if (tp==ExT_mrs_unit) return "mrs_unit";
00022     if (tp==ExT_mrs_bool) return "mrs_bool";
00023     if (tp==ExT_mrs_natural) return "mrs_natural";
00024     if (tp==ExT_mrs_real) return "mrs_real";
00025     if (tp==ExT_mrs_string) return "mrs_string";
00026     if (tp==ExT_mrs_timer) return "mrs_timer";
00027     if (tp==ExT_mrs_scheduler) return "mrs_scheduler";
00028     return 0;
00029 }
00030 
00031 std::string
00032 Marsyas::dtos(double d)
00033 {
00034     std::ostringstream oss;
00035     oss << d;
00036     return oss.str();
00037 
00038 }
00039 
00040 std::string
00041 Marsyas::dtos(float d)
00042 {
00043     std::ostringstream oss;
00044     oss << d;
00045     return oss.str();
00046 }
00047 
00048 std::string
00049 Marsyas::ltos(mrs_natural l)
00050 {
00051     std::ostringstream oss;
00052     oss << l;
00053     return oss.str();
00054 }
00055 
00056 std::string
00057 Marsyas::btos(mrs_bool b)
00058 {
00059     return (b) ? "true" : "false";
00060 }
00061 
00062 mrs_natural
00063 Marsyas::stol(std::string n)
00064 {
00065     long num=0; unsigned int i=0; bool neg=false;
00066     if (n[0]=='-') { neg=true; i=1; }
00067     for (;i<n.length();++i) {
00068         num = (num*10) + (n[i] - '0');
00069     }
00070     return (neg) ? -num : num;
00071 }
00072