CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Utilities/General/src/ioutils.cc

Go to the documentation of this file.
00001 #include "Utilities/General/interface/ioutils.h"
00002 #include "Utilities/General/interface/MutexUtils.h"
00003 
00004 #include <iostream>
00005 #include <iomanip>
00006 #include <algorithm>
00007 
00008 bool  ato<bool>::operator () (const std::string &c) const {
00009   bool ret;
00010   std::string loc = c;
00011   std::transform(loc.begin(),loc.end(),loc.begin(),::tolower);
00012   std::stringstream in(loc.c_str());
00013   in >> ret;;
00014   if (in.fail()) {
00015     in.clear();
00016     in >> std::setiosflags(std::ios::boolalpha) >> ret;
00017   }
00018   return ret;
00019 }
00020 
00021 #ifndef CMS_CHAR_STREAM
00022 #define CSTR .c_str()
00023 #else
00024 #define CSTR
00025 #endif
00026 
00027 #ifdef CMS_CHAR_STREAM //linux
00028 toa::~toa() {
00029   oss().rdbuf()->freeze(0);
00030 }
00031 #else
00032 toa::~toa() {
00033 }
00034 #endif
00035 
00036 std::string & toa::localS() {
00037   static boost::thread_specific_ptr<std::string> local_s;
00038   if (!local_s.get()) local_s.reset(new std::string);
00039   return *local_s;
00040 }
00041 
00042 const char * toa::operator () (const int&c) const {
00043   oss() << c;
00044 #ifdef CMS_CHAR_STREAM
00045   oss() << ends;
00046 #endif
00047   localS() = oss().str();
00048   return localS().c_str();
00049 }
00050 
00051 const char * toa::operator () (bool c) const {
00052   oss() << std::setiosflags(std::ios::boolalpha) << c;
00053 #ifdef CMS_CHAR_STREAM
00054   oss() << ends;
00055 #endif
00056   localS() = oss().str();
00057   return localS().c_str();
00058 }
00059 
00060 
00061 const char * toa::operator () (const double&c) const {
00062   oss() << c;
00063 #ifdef CMS_CHAR_STREAM
00064   oss() << ends;
00065 #endif
00066   localS() = oss().str();
00067   return localS().c_str();
00068 }
00069 
00070 const char * toa::operator () (const char c[], int n) const {
00071   localS().assign(c,n);
00072   return localS().c_str();
00073 }