From 3a28c5ef8eec1fb4095670e1962efc8ad717743c Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 22 Aug 2014 13:07:12 +0200 Subject: [PATCH] Add abstract class Bin --- CMakeLists.txt | 1 + include/hpp/statistics/bin.hh | 48 +++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/bin.cc | 26 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 include/hpp/statistics/bin.hh create mode 100644 src/bin.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index ab3505c..ac43f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ IF (HPP_DEBUG) ENDIF() SET (${PROJECT_NAME}_HEADERS + include/hpp/statistics/bin.hh ) # Add dependency toward hpp-model library in pkg-config file. diff --git a/include/hpp/statistics/bin.hh b/include/hpp/statistics/bin.hh new file mode 100644 index 0000000..507200b --- /dev/null +++ b/include/hpp/statistics/bin.hh @@ -0,0 +1,48 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-statistics. +// hpp-statistics is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-statistics 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 Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-statistics. If not, see <http://www.gnu.org/licenses/>. + + +#ifndef HPP_STATISTICS_HH +# define HPP_STATISTICS_HH + +# include <ostream> + +# include <hpp/statistics/config.hh> + +namespace hpp { + namespace statistics { + /// Abstract class representing a bin. + /// + /// Bins are use for statistics. They keep the number of + /// of apparition of a given value. + class HPP_STATISTICS_DLLAPI Bin + { + public: + /// Return the number of element in the bin. + virtual size_t freq () const = 0; + + private: + /// Print the inner value of the bin. + virtual std::ostream& printValue (std::ostream& os) const = 0; + + friend std::ostream& operator<< (std::ostream&, const Bin&); + }; + + std::ostream& operator<< (std::ostream& os, const Bin& b); + } // namespace statistics +} // namespace hpp + +#endif // HPP_STATISTICS_HH diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83e7ec0..70f4e3f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ SET(LIBRARY_NAME ${PROJECT_NAME}) ADD_LIBRARY(${LIBRARY_NAME} SHARED + bin.cc ) INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION lib) diff --git a/src/bin.cc b/src/bin.cc new file mode 100644 index 0000000..e25a377 --- /dev/null +++ b/src/bin.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-statistics. +// hpp-statistics is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-statistics 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 Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-statistics. If not, see <http://www.gnu.org/licenses/>. + +#include "hpp/statistics/bin.hh" + +namespace hpp { + namespace statistics { + std::ostream& operator<< (std::ostream& os, const Bin& b) + { + return b.printValue (os) << " seen " << b.freq() << " time(s)." << std::endl; + } + } // namespace statistics +} // namespace hpp -- GitLab