From 24e67b2a30c9563dfefc8fcba3563af64e4040be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9o=20Gillot-Lamure?= <leo.gillot@navaati.net>
Date: Mon, 23 Jan 2012 19:52:47 +0100
Subject: [PATCH 2/2] Moved JackGnuPlotMonitor into a file of his own

---
 common/JackGnuPlotMonitor.cpp |  147 +++++++++++++++++++++++++++++++++++++++++
 common/JackGnuPlotMonitor.h   |   89 +++++++++++++++++++++++++
 common/JackNetDriver.h        |    1 +
 common/JackNetManager.h       |    1 +
 common/JackTools.cpp          |  118 ---------------------------------
 common/JackTools.h            |   57 ----------------
 common/wscript                |    1 +
 7 files changed, 239 insertions(+), 175 deletions(-)
 create mode 100644 common/JackGnuPlotMonitor.cpp
 create mode 100644 common/JackGnuPlotMonitor.h

diff --git a/common/JackGnuPlotMonitor.cpp b/common/JackGnuPlotMonitor.cpp
new file mode 100644
index 0000000..d7fd4b4
--- /dev/null
+++ b/common/JackGnuPlotMonitor.cpp
@@ -0,0 +1,147 @@
+/*
+  Copyright (C) 2006-2008 Grame
+
+  This program 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 2.1 of the License, or
+  (at your option) any later version.
+
+  This program 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 Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#include "JackGnuPlotMonitor.h"
+#include "JackError.h"
+
+using namespace std;
+
+namespace Jack {
+
+template <class T>
+JackGnuPlotMonitor<T>::JackGnuPlotMonitor(uint32_t measure_cnt, uint32_t measure_points, std::string name)
+{
+    jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points, measure_cnt );
+
+    fMeasureCnt = measure_cnt;
+    fMeasurePoints = measure_points;
+    fTablePos = 0;
+    fName = name;
+    fCurrentMeasure = new T[fMeasurePoints];
+    fMeasureTable = new T*[fMeasureCnt];
+    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
+    {
+        fMeasureTable[cnt] = new T[fMeasurePoints];
+        fill_n ( fMeasureTable[cnt], fMeasurePoints, 0 );
+    }
+}
+
+template <class T>
+JackGnuPlotMonitor<T>::~JackGnuPlotMonitor()
+{
+    jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );
+
+    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
+        delete[] fMeasureTable[cnt];
+    delete[] fMeasureTable;
+    delete[] fCurrentMeasure;
+}
+
+template <class T>
+T JackGnuPlotMonitor<T>::AddNew(T measure_point)
+{
+    fMeasureId = 0;
+    return fCurrentMeasure[fMeasureId++] = measure_point;
+}
+
+template <class T>
+uint32_t JackGnuPlotMonitor<T>::New()
+{
+    return fMeasureId = 0;
+}
+
+template <class T>
+T JackGnuPlotMonitor<T>::Add(T measure_point)
+{
+    return fCurrentMeasure[fMeasureId++] = measure_point;
+}
+
+template <class T>
+uint32_t JackGnuPlotMonitor<T>::AddLast(T measure_point)
+{
+    fCurrentMeasure[fMeasureId] = measure_point;
+    fMeasureId = 0;
+    return Write();
+}
+
+template <class T>
+uint32_t JackGnuPlotMonitor<T>::Write()
+{
+    for ( uint32_t point = 0; point < fMeasurePoints; point++ )
+        fMeasureTable[fTablePos][point] = fCurrentMeasure[point];
+    if ( ++fTablePos == fMeasureCnt )
+        fTablePos = 0;
+    return fTablePos;
+}
+
+template <class T>
+int JackGnuPlotMonitor<T>::Save(std::string name)
+{
+    std::string filename = ( name.empty() ) ? fName : name;
+    filename += ".log";
+
+    jack_log ( "JackGnuPlotMonitor::Save filename %s", filename.c_str() );
+
+    std::ofstream file ( filename.c_str() );
+
+    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
+    {
+        for ( uint32_t point = 0; point < fMeasurePoints; point++ )
+            file << fMeasureTable[cnt][point] << " \t";
+        file << std::endl;
+    }
+
+    file.close();
+    return 0;
+}
+
+template <class T>
+int JackGnuPlotMonitor<T>::SetPlotFile(std::string* options_list, uint32_t options_number,
+                std::string* field_names, uint32_t field_number,
+                std::string name)
+{
+    std::string title = ( name.empty() ) ? fName : name;
+    std::string plot_filename = title + ".plt";
+    std::string data_filename = title + ".log";
+
+    std::ofstream file ( plot_filename.c_str() );
+
+    file << "set multiplot" << std::endl;
+    file << "set grid" << std::endl;
+    file << "set title \"" << title << "\"" << std::endl;
+
+    for ( uint32_t i = 0; i < options_number; i++ )
+        file << options_list[i] << std::endl;
+
+    file << "plot ";
+    for ( uint32_t row = 1; row <= field_number; row++ )
+    {
+        file << "\"" << data_filename << "\" using " << row << " title \"" << field_names[row-1] << "\" with lines";
+        file << ( ( row < field_number ) ? ", " : "\n" );
+    }
+
+    jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename.c_str() );
+
+    file.close();
+    return 0;
+}
+
+}  // end of namespace
+
+
diff --git a/common/JackGnuPlotMonitor.h b/common/JackGnuPlotMonitor.h
new file mode 100644
index 0000000..3d8e2f4
--- /dev/null
+++ b/common/JackGnuPlotMonitor.h
@@ -0,0 +1,89 @@
+/*
+  Copyright (C) 2006-2008 Grame
+
+  This program 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 2.1 of the License, or
+  (at your option) any later version.
+
+  This program 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 Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef __JackGnuPlotMonitor__
+#define __JackGnuPlotMonitor__
+
+#include <stdlib.h>
+#include <jack/systemdeps.h>
+
+#include <string>
+#include <algorithm>
+#include <vector>
+#include <iostream>
+#include <fstream>
+
+namespace Jack
+{
+
+    /*!
+    \brief Generic monitoring class. Saves data to GnuPlot files ('.plt' and '.log' datafile)
+
+    This template class allows to manipulate monitoring records, and automatically generate the GnuPlot config and data files.
+    Operations are RT safe because it uses fixed size data buffers.
+    You can set the number of measure points, and the number of records.
+
+    To use it :
+    - create a JackGnuPlotMonitor, you can use the data type you want.
+    - create a temporary array for your measure
+    - once you have filled this array with 'measure points' value, call write() to add it to the record
+    - once you've done with your measurment, just call save() to save your data file
+
+    You can also call SetPlotFile() to automatically generate '.plt' file from an options list.
+
+    */
+
+    template <class T> class JackGnuPlotMonitor
+    {
+        private:
+            uint32_t fMeasureCnt;
+            uint32_t fMeasurePoints;
+            uint32_t fMeasureId;
+            T* fCurrentMeasure;
+            T** fMeasureTable;
+            uint32_t fTablePos;
+            std::string fName;
+
+        public:
+
+            JackGnuPlotMonitor(uint32_t measure_cnt = 512, uint32_t measure_points = 5, std::string name = std::string("default"));
+
+            ~JackGnuPlotMonitor();
+
+            T AddNew(T measure_point);
+
+			uint32_t New();
+
+            T Add(T measure_point);
+
+            uint32_t AddLast(T measure_point);
+
+            uint32_t Write();
+
+            int Save(std::string name = std::string(""));
+
+            int SetPlotFile(std::string* options_list = NULL, uint32_t options_number = 0,
+                            std::string* field_names = NULL, uint32_t field_number = 0,
+                            std::string name = std::string(""));
+    };
+
+}
+
+#endif
+
diff --git a/common/JackNetDriver.h b/common/JackNetDriver.h
index 48a733b..663e93c 100644
--- a/common/JackNetDriver.h
+++ b/common/JackNetDriver.h
@@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 #include "JackTimedDriver.h"
 #include "JackNetInterface.h"
+#include "JackGnuPlotMonitor.h"
 
 //#define JACK_MONITOR
 
diff --git a/common/JackNetManager.h b/common/JackNetManager.h
index c88a09b..af35130 100644
--- a/common/JackNetManager.h
+++ b/common/JackNetManager.h
@@ -21,6 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #define __JACKNETMANAGER_H__
 
 #include "JackNetInterface.h"
+#include "JackGnuPlotMonitor.h"
 #include "thread.h"
 #include "jack.h"
 #include "jslist.h"
diff --git a/common/JackTools.cpp b/common/JackTools.cpp
index a00e164..444e28c 100644
--- a/common/JackTools.cpp
+++ b/common/JackTools.cpp
@@ -290,123 +290,5 @@ namespace Jack {
     }
 #endif
 
-template <class T>
-JackGnuPlotMonitor<T>::JackGnuPlotMonitor(uint32_t measure_cnt, uint32_t measure_points, std::string name)
-{
-    jack_log ( "JackGnuPlotMonitor::JackGnuPlotMonitor %u measure points - %u measures", measure_points, measure_cnt );
-
-    fMeasureCnt = measure_cnt;
-    fMeasurePoints = measure_points;
-    fTablePos = 0;
-    fName = name;
-    fCurrentMeasure = new T[fMeasurePoints];
-    fMeasureTable = new T*[fMeasureCnt];
-    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
-    {
-        fMeasureTable[cnt] = new T[fMeasurePoints];
-        fill_n ( fMeasureTable[cnt], fMeasurePoints, 0 );
-    }
-}
-
-template <class T>
-JackGnuPlotMonitor<T>::~JackGnuPlotMonitor()
-{
-    jack_log ( "JackGnuPlotMonitor::~JackGnuPlotMonitor" );
-
-    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
-        delete[] fMeasureTable[cnt];
-    delete[] fMeasureTable;
-    delete[] fCurrentMeasure;
-}
-
-template <class T>
-T JackGnuPlotMonitor<T>::AddNew(T measure_point)
-{
-    fMeasureId = 0;
-    return fCurrentMeasure[fMeasureId++] = measure_point;
-}
-
-template <class T>
-uint32_t JackGnuPlotMonitor<T>::New()
-{
-    return fMeasureId = 0;
-}
-
-template <class T>
-T JackGnuPlotMonitor<T>::Add(T measure_point)
-{
-    return fCurrentMeasure[fMeasureId++] = measure_point;
-}
-
-template <class T>
-uint32_t JackGnuPlotMonitor<T>::AddLast(T measure_point)
-{
-    fCurrentMeasure[fMeasureId] = measure_point;
-    fMeasureId = 0;
-    return Write();
-}
-
-template <class T>
-uint32_t JackGnuPlotMonitor<T>::Write()
-{
-    for ( uint32_t point = 0; point < fMeasurePoints; point++ )
-        fMeasureTable[fTablePos][point] = fCurrentMeasure[point];
-    if ( ++fTablePos == fMeasureCnt )
-        fTablePos = 0;
-    return fTablePos;
-}
-
-template <class T>
-int JackGnuPlotMonitor<T>::Save(std::string name)
-{
-    std::string filename = ( name.empty() ) ? fName : name;
-    filename += ".log";
-
-    jack_log ( "JackGnuPlotMonitor::Save filename %s", filename.c_str() );
-
-    std::ofstream file ( filename.c_str() );
-
-    for ( uint32_t cnt = 0; cnt < fMeasureCnt; cnt++ )
-    {
-        for ( uint32_t point = 0; point < fMeasurePoints; point++ )
-            file << fMeasureTable[cnt][point] << " \t";
-        file << std::endl;
-    }
-
-    file.close();
-    return 0;
-}
-
-template <class T>
-int JackGnuPlotMonitor<T>::SetPlotFile(std::string* options_list, uint32_t options_number,
-                std::string* field_names, uint32_t field_number,
-                std::string name)
-{
-    std::string title = ( name.empty() ) ? fName : name;
-    std::string plot_filename = title + ".plt";
-    std::string data_filename = title + ".log";
-
-    std::ofstream file ( plot_filename.c_str() );
-
-    file << "set multiplot" << std::endl;
-    file << "set grid" << std::endl;
-    file << "set title \"" << title << "\"" << std::endl;
-
-    for ( uint32_t i = 0; i < options_number; i++ )
-        file << options_list[i] << std::endl;
-
-    file << "plot ";
-    for ( uint32_t row = 1; row <= field_number; row++ )
-    {
-        file << "\"" << data_filename << "\" using " << row << " title \"" << field_names[row-1] << "\" with lines";
-        file << ( ( row < field_number ) ? ", " : "\n" );
-    }
-
-    jack_log ( "JackGnuPlotMonitor::SetPlotFile - Save GnuPlot file to '%s'", plot_filename.c_str() );
-
-    file.close();
-    return 0;
-}
-
 }  // end of namespace
 
diff --git a/common/JackTools.h b/common/JackTools.h
index 5d9d633..be7c833 100644
--- a/common/JackTools.h
+++ b/common/JackTools.h
@@ -38,12 +38,6 @@
 #include "jslist.h"
 #include "JackCompilerDeps.h"
 
-#include <string>
-#include <algorithm>
-#include <vector>
-#include <iostream>
-#include <fstream>
-
 namespace Jack
 {
 
@@ -82,57 +76,6 @@ namespace Jack
         }
     };
 
-    /*!
-    \brief Generic monitoring class. Saves data to GnuPlot files ('.plt' and '.log' datafile)
-
-    This template class allows to manipulate monitoring records, and automatically generate the GnuPlot config and data files.
-    Operations are RT safe because it uses fixed size data buffers.
-    You can set the number of measure points, and the number of records.
-
-    To use it :
-    - create a JackGnuPlotMonitor, you can use the data type you want.
-    - create a temporary array for your measure
-    - once you have filled this array with 'measure points' value, call write() to add it to the record
-    - once you've done with your measurment, just call save() to save your data file
-
-    You can also call SetPlotFile() to automatically generate '.plt' file from an options list.
-
-    */
-
-    template <class T> class JackGnuPlotMonitor
-    {
-        private:
-            uint32_t fMeasureCnt;
-            uint32_t fMeasurePoints;
-            uint32_t fMeasureId;
-            T* fCurrentMeasure;
-            T** fMeasureTable;
-            uint32_t fTablePos;
-            std::string fName;
-
-        public:
-
-            JackGnuPlotMonitor(uint32_t measure_cnt = 512, uint32_t measure_points = 5, std::string name = std::string("default"));
-
-            ~JackGnuPlotMonitor();
-
-            T AddNew(T measure_point);
-
-			uint32_t New();
-
-            T Add(T measure_point);
-
-            uint32_t AddLast(T measure_point);
-
-            uint32_t Write();
-
-            int Save(std::string name = std::string(""));
-
-            int SetPlotFile(std::string* options_list = NULL, uint32_t options_number = 0,
-                            std::string* field_names = NULL, uint32_t field_number = 0,
-                            std::string name = std::string(""));
-    };
-
     void BuildClientPath(char* path_to_so, int path_len, const char* so_name);
     void PrintLoadError(const char* so_name);
 
diff --git a/common/wscript b/common/wscript
index 7a79a8a..b870412 100644
--- a/common/wscript
+++ b/common/wscript
@@ -63,6 +63,7 @@ def build(bld):
         'JackTransportEngine.cpp',
         'timestamps.c',
         'JackTools.cpp',
+        'JackGnuPlotMonitor.cpp',
         'JackMessageBuffer.cpp',
         'JackEngineProfiling.cpp',
         ]
-- 
1.7.9.2

