Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

nodeoutputstrategy.h

Go to the documentation of this file.
00001 /***************************************************************************
00002 *  @file    outputstrategy.h
00003 *  @version 1.0
00004 *
00005 *  @author  Ingo Herwig, TU Darmstadt, FG Regelsystemtheorie und Robotik
00006 *  @author  Eva Brucherseifer, TU Darmstadt, FG Regelsystemtheorie und Robotik
00007 *  @date    2001
00008 *
00009 ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Library Public License as       *
00015  *   published by the Free Software Foundation; either version 2 of the    *
00016  *   License, or (at your option) any later version.                       *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 #ifndef NODEOUTPUTSTRATEGY_H
00021 #define NODEOUTPUTSTRATEGY_H
00022 
00023 #include <iostream>
00024 #include <string>
00025 #include "node.h"
00026 #include "nodeutil.h"
00027 
00028 namespace treecomp
00029 {
00030 
00031 
00032 
00033 template<class _TContent>
00034 class NormalNode;
00035 template<class _TContent>
00036 class RootNode;
00037 
00038 // ======================
00039 // === OutputStrategy ===
00040 // ======================
00041 /**
00042  * @interface OutputStrategy
00043  * @ingroup outputstrategy
00044  *
00045  * @brief OutputStrategies are used to define the output-format of the tree.
00046  * They are used together with an OutputVisitor which calls their methods
00047  * appropriately.
00048  */
00049 template<class _TContent>
00050 class OutputStrategy
00051 {
00052 public:
00053     virtual OutputStrategy<_TContent>* clone() const {return 0;}
00054     virtual ~OutputStrategy() {}
00055 
00056     virtual void writeHeader() = 0;
00057     virtual void writeFooter() = 0;
00058     virtual void writeString(std::string& str) = 0;
00059     virtual void writeNormalNode(const NormalNode<_TContent>* node) = 0;
00060     virtual void writeRootNode(const RootNode<_TContent>* node) = 0;
00061 
00062     virtual bool isNull() {return false;}
00063 };
00064 
00065 
00066 
00067 // ============================
00068 // === StreamOutputStrategy ===
00069 // ============================
00070 /**
00071  * @class StreamOutputStrategy
00072  * @ingroup outputstrategy
00073  *
00074  * @brief This OutputStrategy is used as base-class for all OutputStrategies which write to a stream.
00075  */
00076 template<class _TContent>
00077 class StreamOutputStrategy
00078     : public OutputStrategy<_TContent>, public StreamOut
00079 {
00080 public:
00081     explicit StreamOutputStrategy(std::ostream* out=&cout) : StreamOut(out) {}
00082     virtual StreamOutputStrategy<_TContent>* clone() const { return 0;}
00083     virtual ~StreamOutputStrategy() {}
00084 
00085     virtual void writeHeader() = 0;
00086     virtual void writeFooter() = 0;
00087     virtual void writeString(std::string& str) { *m_out << str; }
00088     virtual void writeNormalNode(const NormalNode<_TContent>* node) = 0;
00089     virtual void writeRootNode(const RootNode<_TContent>* node) = 0;
00090 };
00091 
00092 
00093 // ======================
00094 // === NullOutputStrategy ===
00095 // ======================
00096 /**
00097  * @class NullOutputStrategy
00098  * @ingroup outputstrategy
00099  *
00100  * @brief NullOutputStrategies are used to define the output-format of the tree
00101  * - this one is a placeholder, which doesn't produce any output.
00102  */
00103 template<class _TContent>
00104 class NullOutputStrategy : public StreamOutputStrategy<_TContent>
00105 {
00106 public:
00107     explicit NullOutputStrategy(std::ostream* out=&cout) : StreamOutputStrategy<_TContent>(out) {}
00108     virtual NullOutputStrategy<_TContent>* clone() const { return new NullOutputStrategy<_TContent>(*this);}
00109     virtual ~NullOutputStrategy() {}
00110 
00111     virtual void writeHeader() {}
00112     virtual void writeFooter() {}
00113     virtual void writeString(std::string&) {}
00114     virtual void writeNormalNode(const NormalNode<_TContent>*) {}
00115     virtual void writeRootNode(const RootNode<_TContent>*) {}
00116 
00117     virtual bool isNull() {return true;}
00118 };
00119 
00120 
00121 // ============================
00122 // === DefaultOutputStrategy ===
00123 // ============================
00124 /**
00125  * @class DefaultOutputStrategy
00126  * @ingroup outputstrategy
00127  *
00128  * @brief This OutputStrategy writes the node-type and name to 'cout.'
00129  */
00130 template<class _TContent>
00131 class DefaultOutputStrategy : public StreamOutputStrategy<_TContent>
00132 {
00133 public:
00134     explicit DefaultOutputStrategy(std::ostream* out=&cout) : StreamOutputStrategy<_TContent>(out) {}
00135     virtual DefaultOutputStrategy<_TContent>* construct()
00136             { return new DefaultOutputStrategy<_TContent>(); }
00137     virtual DefaultOutputStrategy<_TContent>* clone() const
00138             { return new DefaultOutputStrategy<_TContent>(*this); }
00139     virtual ~DefaultOutputStrategy() {}
00140 
00141     virtual void writeHeader() {}
00142     virtual void writeFooter() {}
00143     virtual void writeNormalNode(const NormalNode<_TContent>* node);
00144     virtual void writeRootNode(const RootNode<_TContent>* node);
00145 };
00146 
00147 
00148 // =================== Template definition =================================
00149 
00150 // =============================
00151 // === DefaultOutputStrategy ===
00152 // =============================
00153 /**
00154  * Write the normalNode content
00155  */
00156 template<class _TContent>
00157 void DefaultOutputStrategy<_TContent>::writeNormalNode(const NormalNode<_TContent>* node)
00158 {
00159     *m_out << "......NN: " << node->getName() << endl;
00160 }
00161 
00162 /**
00163  * Write the RootNode content
00164  */
00165 template<class _TContent>
00166 void DefaultOutputStrategy<_TContent>::writeRootNode(const RootNode<_TContent>* node)
00167 {
00168     *m_out << "......SN: " << node->getName() << endl;
00169 }
00170 
00171 
00172 } //namespace treecomp
00173 
00174 #endif //OUTPUTSTRATEGY_H

Generated on Mon Jan 6 12:02:08 2003 for TreeComp by doxygen1.2.17