// logger_ram.cc // marvin - programme du robot 2006. {{{ // // Copyright (C) 2006 Dufour Jérémy // // Robot APB Team/Efrei 2004. // Web: http://assos.efrei.fr/robot/ // Email: robot AT efrei DOT fr // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} #include "logger_ram.hh" #include #include // Convertion from num to string /// Default constructor. LoggerRam::LoggerRam (void) : buffer_ (bufferFactory_.getDataCircularBuffer ()) { } /// Called at the begining of a message. void LoggerRam::start (const Log &log, const char *msg, Log::Level level) { strTmp_ = log.getModule (); strTmp_.append (":"); const char *instance = log.getInstance (); if (instance) { strTmp_.append (" "); strTmp_.append (instance); strTmp_.append (":"); } strTmp_.append (" ("); strTmp_.append (msg); strTmp_.append (")"); buffer_.write (reinterpret_cast (strTmp_.data ()), strTmp_.size ()); } /// Output a string or a variable name. LoggerRam & LoggerRam::operator<< (const char *s) { strTmp_ = " "; strTmp_.append (s); buffer_.write (reinterpret_cast (strTmp_.data ()), strTmp_.size ()); return *this; } /// Output a string or a variable name. LoggerRam & LoggerRam::operator<< (const std::string &s) { strTmp_ = " " + s; buffer_.write (reinterpret_cast (strTmp_.data ()), strTmp_.size ()); return *this; } /// Output a integer. LoggerRam & LoggerRam::operator<< (int i) { strTmp_ = " "; std::ostringstream oStr; oStr << i; strTmp_.append (oStr.str ()); buffer_.write (reinterpret_cast (strTmp_.data ()), strTmp_.size ()); return *this; } /// Output a double. LoggerRam & LoggerRam::operator<< (double d) { strTmp_ = " "; std::ostringstream oStr; oStr << d; strTmp_.append (oStr.str ()); buffer_.write (reinterpret_cast (strTmp_.data ()), strTmp_.size ()); return *this; }