/* gs_message.cc - Définition de la classe des grosses string */ /* Simulotron - Programme de simulation de robot {{{ * * Copyright (C) 2005 Nicolas Haller * * Robot APB Team/Efrei 2005. * 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 "gs/gs_message.hh" #include "gs/gs_transmitter.hh" #include "utils/simulotron_exception.hh" #include GSMessage::GSMessage(void) :igs_(gs_.begin()) { } GSMessage::GSMessage(GSTransmitter & gst, bool bloquant) { gst.getGS(*this, bloquant); } const std::string & GSMessage::getGS(void) const { return gs_; } void GSMessage::readGS(void * data, size_t size) { std::string str; str.assign(igs_, gs_.end()); if (size > str.size()) throw simulotron_exception("GSMessage:", "CHIER!!! La size dans readGS est trop grande!!"); memcpy(data, str.data(), size); igs_ += size; } void GSMessage::getString(std::string & str) { std::string tmp (igs_, gs_.end()); str.assign(tmp.c_str()); igs_ += str.size() + 1; } void GSMessage::getString(std::string & str, size_t size) { unsigned int pos0; str.assign(igs_, igs_ + size); pos0 = str.find('\0'); if (pos0 != std::string::npos) str.erase(pos0); igs_ += size; } ///\todo Est-ce vraiment bien ca? et pourquoi une fct templaté? void GSMessage::appendGS (const void * data, size_t size) { gs_.append(static_cast (data), size); setIteratorBegin(); } void GSMessage::insertFrontGS(const void * data, size_t size) { gs_.insert(0, static_cast (data), size); setIteratorBegin(); } void GSMessage::setIteratorBegin(void) { igs_ = gs_.begin(); } void GSMessage::clear(void) { gs_.clear(); setIteratorBegin(); } void GSMessage::delBeforeIt(void) { gs_.erase(gs_.begin(), igs_); setIteratorBegin(); }