diff --git a/CMakeLists.txt b/CMakeLists.txt index ab3505c0e58455cb37b11796f2d23158a1e33090..ac43f2fbcd825484998e9125d27e7835d9ced932 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 0000000000000000000000000000000000000000..507200bc0e335df3d1220dd74758ff0fdcfd2d40 --- /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 83e7ec086464523b368c1e864dbe0da6b73c5a33..70f4e3fdbcc53e0e136fe28d49262745910a3455 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 0000000000000000000000000000000000000000..e25a377c3c2821777a5897e1300d9d03ed676c2c --- /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