User Manual, Developers Guide and API Documentation

StatEvalTable.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_STATEVALTABLE_HPP
00029 #define WNS_PROBE_BUS_DETAIL_STATEVALTABLE_HPP
00030 
00031 #include <WNS/container/DynamicMatrix.hpp>
00032 #include <WNS/evaluation/statistics/stateval.hpp>
00033 #include <WNS/probe/bus/detail/Sorter.hpp>
00034 
00035 #include <vector>
00036 #include <list>
00037 #include <iostream>
00038 
00039 
00040 namespace wns { namespace probe { namespace bus { namespace detail {
00041 
00043         class Storage
00044         {
00045                     wns::evaluation::statistics::StatEval se;
00046         public:
00047             Storage();
00048 
00049             ~Storage();
00050 
00051             void
00052             put(double);
00053 
00054             double
00055             get(const std::string& valueType) const;
00056         };
00057 
00058         class OutputFormatter;
00059 
00061         template <typename T>
00062         class Table
00063         {
00064             friend class OutputFormatter;
00065 
00066         protected:
00067             typedef T ValueType;
00068 
00069             class OutOfRange :
00070                 public wns::Exception
00071             {
00072             public:
00073                 ~OutOfRange() throw() {}
00074             };
00075 
00076             std::vector<detail::Sorter> sorters;
00077             wns::container::DynamicMatrix<ValueType>* root;
00078 
00079         public:
00080             Table(std::vector<detail::Sorter> config) :
00081                 sorters(config),
00082                 root(NULL)
00083                 {
00084                     std::list<int> dimensions;
00085                     for (size_t ii = 0; ii<sorters.size(); ++ii)
00086                     {
00087                         dimensions.push_back(sorters.at(ii).getResolution());
00088                     }
00089                     root = new wns::container::DynamicMatrix<ValueType>(dimensions);
00090                 }
00091 
00092             ~Table()
00093                 {
00094                     delete root;
00095                 }
00096 
00097             T&
00098             get(const std::list<IDType>& ids)
00099                 {
00100                     return root->getValue( this->getCoords(ids) );
00101                 }
00102 
00103             const T&
00104             get(const std::list<IDType>& ids) const
00105                 {
00106                     return root->getValue( this->getCoords(ids) );
00107                 }
00108 
00109             const T&
00110             getByIndex(const std::list<int>& indices) const
00111                 {
00112                     return root->getValue(indices);
00113                 }
00114 
00115             void
00116             set(const std::list<IDType>& ids, ValueType value)
00117                 {
00118                     return root->setValue( this->getCoords(ids),value );
00119                 }
00120 
00121         private:
00122             std::list<int>
00123             getCoords(const std::list<IDType>& ids) const
00124                 {
00125                     assure(ids.size() == sorters.size(), "ID/Sorter Mismatch");
00126                     std::list<IDType>::const_iterator iter = ids.begin();
00127                     std::list<IDType>::const_iterator end  = ids.end();
00128 
00129                     std::vector<detail::Sorter>::const_iterator siter = sorters.begin();
00130                     std::vector<detail::Sorter>::const_iterator send  = sorters.end();
00131 
00132                     std::list<int> coords;
00133 
00134                     while(iter != end && siter != send)
00135                     {
00136                         const Sorter& sorter = *siter;
00137                         if (sorter.checkIndex(*iter) == true)
00138                         {
00139                             coords.push_back(sorter.getIndex(*iter));
00140                         }
00141                         else
00142                         {
00143                             OutOfRange up;
00144                             throw(up);
00145                         }
00146                         ++iter;
00147                         ++siter;
00148                     }
00149                     return coords;
00150                 }
00151         };
00152 
00153         typedef Table<Storage> StatEvalTable;
00154 }}}}
00155 
00156 #endif // not defined WNS_PROBE_BUS_DETAIL_STATEVALTABLE_HPP

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