diff --git a/CMakeLists.txt b/CMakeLists.txt index 0117c94ade85e2201ae903d8a2de20f6e201f0f6..73fcc539a5d704f129bb780b9b66d293ef3b4579 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,10 @@ IF (HPP_DEBUG) ENDIF() SET (${PROJECT_NAME}_HEADERS + include/hpp/statistics/fwd.hh include/hpp/statistics/bin.hh include/hpp/statistics/success-bin.hh + include/hpp/statistics/operators.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 index aa40be13fbc7c122a0f4cd7f3cfe4882d791c480..58fbf3a645b8f3145d96e6fc27eb7398c5198c20 100644 --- a/include/hpp/statistics/bin.hh +++ b/include/hpp/statistics/bin.hh @@ -21,19 +21,8 @@ # include <ostream> # include <set> -# include <hpp/statistics/config.hh> - -namespace hpp { - namespace statistics { - class Bin; - template < typename T > - class Statistics; - } // namespace statistics -} // namespace hpp - -std::ostream& operator<< (std::ostream&, const hpp::statistics::Bin&); -template < typename T > -std::ostream& operator<< (std::ostream&, const hpp::statistics::Statistics <T>&); +# include "hpp/statistics/config.hh" +# include "hpp/statistics/fwd.hh" namespace hpp { namespace statistics { @@ -94,8 +83,9 @@ namespace hpp { /// Return the number of occurence of a Bin virtual size_t freq (const T& bin) const; - /// Return the total number of occurence. - unsigned int numberOfOccurence () const + /// Return the number of times a observation has recorded. It is the + /// total number of observations. + unsigned int numberOfObservations () const { return counts_; } @@ -171,17 +161,12 @@ namespace hpp { std::ostream& Statistics<T>::print (std::ostream& os) const { const_iterator it; - for (it = begin(); it != end(); it++) - os << (*it) << std::endl; + for (it = begin(); it != end(); it++) { + it->print (os) << std::endl; + } return os; } } // namespace statistics } // namespace hpp - template < typename T > -std::ostream& operator<< (std::ostream& os, const hpp::statistics::Statistics <T>& ss) -{ - return ss.print (os); -} - #endif // HPP_STATISTICS_HH diff --git a/include/hpp/statistics/operators.hh b/include/hpp/statistics/operators.hh new file mode 100644 index 0000000000000000000000000000000000000000..e1862373703ccefca4cd6c9916fed708a597e6ac --- /dev/null +++ b/include/hpp/statistics/operators.hh @@ -0,0 +1,37 @@ +// 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_OPERATORS_HH +# define HPP_STATISTICS_OPERATORS_HH + +# include <iosfwd> + +# include "hpp/statistics/bin.hh" +# include "hpp/statistics/success-bin.hh" +# include "hpp/statistics/config.hh" + +namespace hpp { + HPP_STATISTICS_DLLAPI std::ostream& + operator<< (std::ostream& os, const hpp::statistics::Bin& b); + HPP_STATISTICS_DLLAPI std::ostream& + operator<< (std::ostream& os, const hpp::statistics::SuccessBin& b); + template < typename T > HPP_STATISTICS_DLLAPI std::ostream& + operator<< (std::ostream& os, const hpp::statistics::Statistics <T>& ss); + HPP_STATISTICS_DLLAPI std::ostream& + operator<< (std::ostream& os, const hpp::statistics::SuccessStatistics& ss); +} // namespace hpp + +#endif // HPP_STATISTICS_OPERATORS_HH diff --git a/include/hpp/statistics/success-bin.hh b/include/hpp/statistics/success-bin.hh index 57fa4f8aa81854468769d449a8575eb28f0a61dc..292e1248cf4d7a32a4a87e5d9a16959636d2573f 100644 --- a/include/hpp/statistics/success-bin.hh +++ b/include/hpp/statistics/success-bin.hh @@ -23,6 +23,7 @@ # include "hpp/statistics/config.hh" # include "hpp/statistics/bin.hh" +# include "hpp/statistics/fwd.hh" # define HPP_DEFINE_REASON_FAILURE(ID, STRING) \ const ::hpp::statistics::SuccessBin::Reason ID = \ @@ -122,9 +123,4 @@ namespace hpp { } // namespace statistics } // namespace hpp -std::ostream& operator<< (std::ostream& os, const hpp::statistics::SuccessStatistics& ss) -{ - return ss.print (os); -} - #endif // HPP_STATISTICS_SUCCESSBIN_HH diff --git a/src/bin.cc b/src/bin.cc index b983780bcb82e4b4ac5ede1400e64216676c8a95..a26513e2b2eaa283c8e1485fe2a1f5d64c5d80b4 100644 --- a/src/bin.cc +++ b/src/bin.cc @@ -15,6 +15,7 @@ // hpp-statistics. If not, see <http://www.gnu.org/licenses/>. #include "hpp/statistics/bin.hh" +#include "hpp/statistics/operators.hh" namespace hpp { namespace statistics { @@ -24,7 +25,3 @@ namespace hpp { } } // namespace statistics } // namespace hpp -std::ostream& operator<< (std::ostream& os, const hpp::statistics::Bin& b) -{ - return b.print (os); -} diff --git a/src/success-bin.cc b/src/success-bin.cc index 1e29da983f05e21ba560d598498a6ba232c05010..a9af296dd36eae1b07655ef73104699eb82164f1 100644 --- a/src/success-bin.cc +++ b/src/success-bin.cc @@ -17,6 +17,7 @@ #include <limits.h> #include "hpp/statistics/success-bin.hh" +#include "hpp/statistics/operators.hh" namespace hpp { namespace statistics { @@ -86,7 +87,7 @@ namespace hpp { unsigned int SuccessStatistics::nbFailure () const { - return numberOfOccurence() - nbSuccess(); + return numberOfObservations() - nbSuccess(); } unsigned int SuccessStatistics::nbFailure (const SuccessBin::Reason& r) const diff --git a/tests/test-successstatistics.cc b/tests/test-successstatistics.cc index f9dfe2ff1d43486fbf21235dde09d533c6e9d223..594cb5964af780c74e8ab4a44f41eed80914efb6 100644 --- a/tests/test-successstatistics.cc +++ b/tests/test-successstatistics.cc @@ -19,9 +19,12 @@ #include <iostream> #include "hpp/statistics/success-bin.hh" +#include "hpp/statistics/operators.hh" HPP_DEFINE_REASON_FAILURE (REASON_TEST, "Fake reason for testing purpose"); +using namespace hpp; + int main () { /* initialize random seed: */