EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: ca patch
From: "Shen, Guobao" <[email protected]>
To: "Davidsaver, Michael" <[email protected]>, "'tech-talk'" <[email protected]>
Date: Mon, 10 Dec 2012 16:10:06 -0500

 From 0b5c0803d8facca0693457dfc9aa7296df0543d2 Mon Sep 17 00:00:00 2001
From: = <=>
Date: Mon, 10 Dec 2012 16:07:02 -0500
Subject: c++ build fix for gcc 4.7

---
 Storage/ListIndex.cpp |    9 ++++-----
 Storage/RTree.cpp     |    6 ++++--
 Tools/AVLTree.h       |   12 +++++++++---
 Tools/AVLTreeTest.cpp |   20 ++++++++++++--------
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/Storage/ListIndex.cpp b/Storage/ListIndex.cpp
index 6b83635..3d23c37 100644
--- a/Storage/ListIndex.cpp
+++ b/Storage/ListIndex.cpp
@@ -139,11 +139,10 @@ class RTree *ListIndex::getTree(const stdString &channel,
     return 0;
 }
 
-int sort_compare(const stdString &a,
-                 const stdString &b)
-{
-    return b.compare(a);
-}
+template<> struct ItemOps<stdString> {
+	static int compare(const stdString &a, const stdString &b)
+	{   return b.compare(a); }
+};
 
 void ListIndex::name_traverser(const stdString &name,
                                void *self)
diff --git a/Storage/RTree.cpp b/Storage/RTree.cpp
index ebc6aec..4830b45 100644
--- a/Storage/RTree.cpp
+++ b/Storage/RTree.cpp
@@ -409,8 +409,10 @@ bool RTree::selfTest(unsigned long &nodes, unsigned long &records)
 }
 
 // Comparison routine for AVLTree (node_cache)
-int sort_compare(const RTree::Node &a, const RTree::Node &b)
-{    return b.offset - a.offset; }
+template<> struct ItemOps<RTree::Node> {
+	static int compare(const RTree::Node &a, const RTree::Node &b)
+	{   return b.offset - a.offset; }
+};
 
 void RTree::read_node(Node &node) const
 {
diff --git a/Tools/AVLTree.h b/Tools/AVLTree.h
index c0a5222..0a1fdbf 100644
--- a/Tools/AVLTree.h
+++ b/Tools/AVLTree.h
@@ -15,6 +15,12 @@
 #include <GenericException.h>
 #include <AutoFilePtr.h>
 
+template<class Item>
+struct ItemOps {
+  //static int compare(const Item& a, const Item& b) {return a-b;}
+  //static const char *tostr(const Item &) {return "hi";}
+};
+
 // Tree Item:
 // Holds the full Item as well as left/right pointers
 template<class Item> class AVLItem
@@ -77,7 +83,7 @@ public:
         int comp;
         while (n)
         {
-            comp = sort_compare(item, n->item);
+            comp = ItemOps<Item>::compare(item, n->item);
             if (comp == 0)
             {
                 item = n->item;
@@ -165,7 +171,7 @@ private:
             *node = new_node;
             return true;
         }
-        int comp = sort_compare(new_node->item, (*node)->item);
+        int comp = ItemOps<Item>::compare(new_node->item, (*node)->item);
         if (comp == 0)
         {   // Don't insert new node, only update data item
             (*node)->item = new_node->item;
@@ -217,7 +223,7 @@ private:
         ++i;
         int me = i;
         fprintf(f, "n%d [ label=\"%s (%d)\" ];\n",
-                me, toString(node->item), (int)node->balance);
+                me, ItemOps<Item>::tostr(node->item), (int)node->balance);
         if (node->left)
         {
             fprintf(f, "n%d -> n%d\n", me, i+1);
diff --git a/Tools/AVLTreeTest.cpp b/Tools/AVLTreeTest.cpp
index 4d48933..f423152 100644
--- a/Tools/AVLTreeTest.cpp
+++ b/Tools/AVLTreeTest.cpp
@@ -1,11 +1,10 @@
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "AVLTree.h"
 #include "UnitTest.h"
 
-static int sort_compare(const int &a, const int &b)
-{   return b-a; }
 
 static int avl_last_number;
 static bool tree_is_ordered;
@@ -17,12 +16,17 @@ static void avl_order_test(const int &i, void *)
     avl_last_number = i;
 }
 
-static const char *toString(const int &i)
-{
-    static char txt[10];
-    sprintf(txt, "%d", i);
-    return txt;
-}
+template<> struct ItemOps<int> {
+	static int compare(const int &a, const int &b)
+	{   return b-a; }
+
+	static const char *tostr(const int &i)
+	{
+	    static char txt[10];
+	    sprintf(txt, "%d", i);
+	    return txt;
+	}
+};
 
 TEST_CASE avl_test()
 {
-- 
1.7.10.4


Navigate by Date:
Prev: James Rowland mark.heron
Next: Passive Scanning processing Diego Sanz
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: James Rowland mark.heron
Next: Passive Scanning processing Diego Sanz
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·