// $Id: RosPrintfS.cpp 25 2013-08-14 19:10:24Z mueller $ // // Copyright 2000-2011 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free // Software Foundation, either version 2, 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 complete details. // // Imported Rev 488/364 1.0 from Retro -> CbmNet // --------------------------------------------------------------------------- /*! \file \version $Id: RosPrintfS.cpp 25 2013-08-14 19:10:24Z mueller $ \brief Implemenation of RosPrintfS . */ #include #include "RiosState.hpp" #include "RosPrintfS.hpp" using namespace std; /*! \class RosPrintfS \brief Print object for scalar values . ** */ // all method definitions in namespace CbmNet namespace CbmNet { //------------------------------------------+----------------------------------- /*! \brief Constructor. \param value value to be printed \param form format descriptor string \param width field width \param prec precision */ template RosPrintfS::RosPrintfS(T value, const char* form, int width, int prec) : RosPrintfBase(form, width, prec), fValue(value) {} //------------------------------------------+----------------------------------- template void RosPrintfS::ToStream(std::ostream& os) const { RiosState iostate(os, fForm, fPrec); os << setw(fWidth) << fValue; } //------------------------------------------+----------------------------------- template <> void RosPrintfS::ToStream(std::ostream& os) const { RiosState iostate(os, fForm, fPrec); char ctype = iostate.Ctype(); os.width(fWidth); if (ctype == 0 || ctype == 'c') { os << fValue; } else { os << (int) fValue; } } //------------------------------------------+----------------------------------- template <> void RosPrintfS::ToStream(std::ostream& os) const { RiosState iostate(os, fForm, fPrec); char ctype = iostate.Ctype(); os.width(fWidth); if (ctype == 'c') { os << (char) fValue; } else { os << fValue; } } //------------------------------------------+----------------------------------- template <> void RosPrintfS::ToStream(std::ostream& os) const { RiosState iostate(os, fForm, fPrec); char ctype = iostate.Ctype(); os.width(fWidth); if (ctype == 'p') { os << (const void*) fValue; } else { os << (fValue?fValue:""); } } //------------------------------------------+----------------------------------- template <> void RosPrintfS::ToStream(std::ostream& os) const { RiosState iostate(os, fForm, fPrec); char ctype = iostate.Ctype(); os.width(fWidth); if (ctype == 0 || ctype == 'p') { os << fValue; } else { os << (unsigned long) fValue; } } //!! Note: //!! 1. This specialization is printing signed and unsigned char types and //!! implements the `c' conversion format, // finally do an explicit instantiation of the required RosPrintfS template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; template class RosPrintfS; } // end namespace CbmNet