Libbarrett  1.2.4
include/barrett/systems/print_to_stream.h
00001 /*
00002         Copyright 2009, 2010 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020         Further, non-binding information about licensing is available at:
00021         <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00022 */
00023 
00024 /*
00025  * print_to_screen.h
00026  *
00027  *  Created on: Sep 4, 2009
00028  *      Author: dc
00029  */
00030 
00031 #ifndef BARRETT_SYSTEMS_PRINT_TO_STREAM_H_
00032 #define BARRETT_SYSTEMS_PRINT_TO_STREAM_H_
00033 
00034 
00035 #include <iostream>
00036 #include <string>
00037 
00038 #include <barrett/detail/ca_macro.h>
00039 #include <barrett/systems/abstract/system.h>
00040 #include <barrett/systems/abstract/single_io.h>
00041 
00042 
00043 namespace barrett {
00044 namespace systems {
00045 
00046 
00047 template<typename T>
00048 class PrintToStream : public System, public SingleInput<T> {
00049 public:
00050         explicit PrintToStream(ExecutionManager* em, const std::string& prependedLabel = "",
00051                         std::ostream& ostream = std::cout, const std::string& sysName = "PrintToStream") :
00052                 System(sysName), SingleInput<T>(this), label(prependedLabel), os(ostream)
00053         {
00054                 if (em != NULL) {
00055                         em->startManaging(*this);
00056                 }
00057         }
00058         virtual ~PrintToStream() {
00059                 mandatoryCleanUp();
00060         }
00061 
00062 protected:
00063         std::string label;
00064         std::ostream& os;
00065 
00066         virtual void operate() {
00067                 os << label << this->input.getValue() << std::endl;
00068         }
00069 
00070 private:
00071         DISALLOW_COPY_AND_ASSIGN(PrintToStream);
00072 };
00073 
00074 
00075 }
00076 }
00077 
00078 
00079 #endif /* BARRETT_SYSTEMS_PRINT_TO_STREAM_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines