User Manual, Developers Guide and API Documentation

OutputFormatter.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_PROBE_BUS_DETAIL_OUTPUTFORMATTER_HPP
00029 #define WNS_PROBE_BUS_DETAIL_OUTPUTFORMATTER_HPP
00030 
00031 #include <WNS/StaticFactory.hpp>
00032 #include <WNS/probe/bus/detail/StatEvalTable.hpp>
00033 
00034 namespace wns { namespace probe { namespace bus { namespace detail {
00035 
00039     template <typename T, typename KIND = T>
00040     struct StatEvalTableCreator :
00041         public StatEvalTableCreator<KIND, KIND>
00042     {
00043         virtual KIND*
00044         create(const StatEvalTable& data)
00045             {
00046                 return new T(data);
00047             }
00048 
00049         virtual ~StatEvalTableCreator()
00050             {};
00051     };
00052 
00053     template <typename KIND>
00054     struct StatEvalTableCreator<KIND, KIND>
00055     {
00056     public:
00057         virtual KIND*
00058         create(const StatEvalTable& data) = 0;
00059 
00060         virtual ~StatEvalTableCreator()
00061             {};
00062     };
00063 
00070     class OutputFormatter
00071     {
00077         virtual
00078         void doPrint(std::ostream& strm,
00079                      std::list<int> fixedIndices,
00080                      int dim,
00081                      std::string valueType) const = 0;
00082     protected:
00084         const StatEvalTable& data;
00085 
00090         const std::vector<Sorter>&
00091         sorters() const
00092             {
00093                 return data.sorters;
00094             }
00095     public:
00100         OutputFormatter(const StatEvalTable& table) :
00101             data(table)
00102             {}
00103 
00104         virtual
00105         ~OutputFormatter(){}
00106 
00110         virtual void
00111         print(std::ostream& strm, std::string valueType) const;
00112 
00116         virtual std::string
00117         getPrefix() const { return ""; }
00118 
00122         virtual std::string
00123         getFilenameSuffix() const { return ""; }
00124     };
00125 
00127     class HumanReadable :
00128         public OutputFormatter
00129     {
00130         virtual
00131         void doPrint(std::ostream& strm,
00132                      std::list<int> fixedIndices,
00133                      int dim,
00134                      std::string valueType) const;
00135 
00136     public:
00137         HumanReadable(const StatEvalTable& table) :
00138             OutputFormatter(table)
00139             {}
00140 
00141         virtual
00142         ~HumanReadable(){}
00143     };
00144 
00146     class PythonReadable :
00147         public OutputFormatter
00148     {
00149         virtual
00150         void doPrint(std::ostream& strm,
00151                      std::list<int> fixedIndices,
00152                      int dim,
00153                      std::string valueType) const;
00154 
00155     public:
00156         PythonReadable(const StatEvalTable& table) :
00157             OutputFormatter(table)
00158             {}
00159 
00160         virtual
00161         ~PythonReadable(){}
00162 
00163         virtual void
00164         print(std::ostream& strm, std::string valueType) const;
00165 
00166         virtual std::string
00167         getPrefix() const { return "# "; };
00168 
00169         virtual std::string
00170         getFilenameSuffix() const { return ".py"; }
00171     };
00172 
00174     class MatlabReadable :
00175         public OutputFormatter
00176     {
00177         virtual
00178         void doPrint(std::ostream& strm,
00179                      std::list<int> fixedIndices,
00180                      int dim,
00181                      std::string valueType) const;
00182 
00183     public:
00184         MatlabReadable(const StatEvalTable& table) :
00185             OutputFormatter(table)
00186             {}
00187 
00188         virtual
00189         ~MatlabReadable(){}
00190 
00191         virtual void
00192         print(std::ostream& strm, std::string valueType) const;
00193 
00194         virtual std::string
00195         getPrefix() const { return "% "; };
00196 
00197         virtual std::string
00198         getFilenameSuffix() const { return ".m"; }
00199     };
00200 
00202     class MatlabReadableSparse :
00203         public MatlabReadable
00204     {
00205         virtual
00206         void doPrint(std::ostream& strm,
00207                      std::list<int> fixedIndices,
00208                      int dim,
00209                      std::string valueType) const;
00210 
00211     public:
00212         MatlabReadableSparse(const StatEvalTable& table) :
00213             MatlabReadable(table)
00214             {}
00215 
00216         virtual
00217         ~MatlabReadableSparse(){}
00218     };
00219 
00221     class LogEvalReadable :
00222         public OutputFormatter
00223     {
00224         virtual
00225         void doPrint(std::ostream& strm,
00226                      std::list<int> fixedIndices,
00227                      int dim,
00228                      std::string valueType) const;
00229 
00230         public:
00231             LogEvalReadable(const StatEvalTable& table) :
00232                 OutputFormatter(table)
00233                 {}
00234     
00235             virtual
00236             ~LogEvalReadable(){}
00237 
00238             virtual std::string
00239             getPrefix() const { return "# "; };
00240     
00241             virtual std::string
00242             getFilenameSuffix() const { return "_Log.log.dat"; }
00243     };
00244 
00246     class Plain :
00247         public MatlabReadable
00248     {
00249         public:
00250             Plain(const StatEvalTable& table) :
00251                 MatlabReadable(table)
00252                 {}
00253 
00254             virtual
00255             ~Plain(){}
00256 
00257             virtual std::string
00258             getFilenameSuffix() const { return ".dat"; }
00259     };
00260 
00261     typedef StatEvalTableCreator<OutputFormatter, OutputFormatter> FormatterCreator;
00262     typedef StaticFactory<FormatterCreator> FormatterFactory;
00263 
00264 }}}}
00265 
00266 #endif // not defined WNS_PROBE_BUS_DETAIL_OUTPUTFORMATTER_HPP
00267 

Generated on Fri May 25 03:31:49 2012 for openWNS by  doxygen 1.5.5