From 40e1bf3960c6c51e9b594dfbb348f5f3051ce0c4 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Wed, 27 Aug 2014 19:18:17 +0200
Subject: [PATCH] Change numberOfOccurence to numberOfObservations. Modify
 operator<<

---
 CMakeLists.txt                        |  2 ++
 include/hpp/statistics/bin.hh         | 31 ++++++----------------
 include/hpp/statistics/operators.hh   | 37 +++++++++++++++++++++++++++
 include/hpp/statistics/success-bin.hh |  6 +----
 src/bin.cc                            |  5 +---
 src/success-bin.cc                    |  3 ++-
 tests/test-successstatistics.cc       |  3 +++
 7 files changed, 54 insertions(+), 33 deletions(-)
 create mode 100644 include/hpp/statistics/operators.hh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0117c94..73fcc53 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 aa40be1..58fbf3a 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 0000000..e186237
--- /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 57fa4f8..292e124 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 b983780..a26513e 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 1e29da9..a9af296 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 f9dfe2f..594cb59 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: */
-- 
GitLab