← Back to team overview

dolfin team mailing list archive

[noreply@xxxxxxxxxxxxx: [Branch ~dolfin-core/dolfin/main] Rev 5359: Add singleton ID generator class.]

 

It would be good to move the id() function to the Variable class. That
way we have it for free for all classes that subclass Variable (which
are most classes). The overhead will be minimal.

--
Anders
--- Begin Message ---
------------------------------------------------------------
revno: 5359
committer: Garth N. Wells <gnw20@xxxxxxxxx>
branch nick: dolfin-all
timestamp: Sun 2010-12-05 10:50:27 +0000
message:
  Add singleton ID generator class.
  
  Add unique integer ID to Mesh.
added:
  dolfin/common/UniqueIdGenerator.cpp
  dolfin/common/UniqueIdGenerator.h
modified:
  demo/pde/poisson/cpp/main.cpp
  dolfin/common/real.cpp*
  dolfin/common/real.h*
  dolfin/mesh/Mesh.cpp
  dolfin/mesh/Mesh.h


--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/main

Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription
=== modified file 'demo/pde/poisson/cpp/main.cpp'
--- demo/pde/poisson/cpp/main.cpp	2010-11-29 13:31:55 +0000
+++ demo/pde/poisson/cpp/main.cpp	2010-12-05 10:50:27 +0000
@@ -80,7 +80,7 @@
   file << u;
 
   // Plot solution
-  plot(u);
+  //plot(u);
 
   return 0;
 }

=== added file 'dolfin/common/UniqueIdGenerator.cpp'
--- dolfin/common/UniqueIdGenerator.cpp	1970-01-01 00:00:00 +0000
+++ dolfin/common/UniqueIdGenerator.cpp	2010-12-05 10:50:27 +0000
@@ -0,0 +1,30 @@
+// Copyright (C) 2010 Garth N. Wells.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// First added:  2010-12-05
+// Last changed:
+
+#include "UniqueIdGenerator.h"
+
+using namespace dolfin;
+
+// Initialise static data
+dolfin::UniqueIdGenerator dolfin::UniqueIdGenerator::unique_id_generator;
+
+//-----------------------------------------------------------------------------
+UniqueIdGenerator::UniqueIdGenerator() : next_id(0)
+{
+  // Do nothing
+}
+//-----------------------------------------------------------------------------
+dolfin::uint UniqueIdGenerator::id()
+{
+  // Get ID
+  const uint _id = unique_id_generator.next_id;
+
+  // Increment ID
+  ++unique_id_generator.next_id;
+
+  return _id;
+}
+//-----------------------------------------------------------------------------

=== added file 'dolfin/common/UniqueIdGenerator.h'
--- dolfin/common/UniqueIdGenerator.h	1970-01-01 00:00:00 +0000
+++ dolfin/common/UniqueIdGenerator.h	2010-12-05 10:50:27 +0000
@@ -0,0 +1,39 @@
+// Copyright (C) 2010 Garth N. Wells.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// First added:  2010-12-05
+// Last changed:
+
+#ifndef __UNIQUE_ID_GENERATOR_H
+#define __UNIQUE_ID_GENERATOR_H
+
+#include <dolfin/common/types.h>
+
+namespace dolfin
+{
+
+  /// This is a singleton class that return IDs that are unique in the
+  /// lifetime of a program.
+
+  class UniqueIdGenerator
+  {
+  public:
+
+    UniqueIdGenerator();
+
+    /// Generate a unique ID
+    static uint id();
+
+  private:
+
+    // Singleton instance
+    static UniqueIdGenerator unique_id_generator;
+
+    // Next ID to be returned
+    uint next_id;
+
+  };
+
+}
+
+#endif

=== modified file 'dolfin/common/real.cpp' (properties changed: +x to -x)
=== modified file 'dolfin/common/real.h' (properties changed: +x to -x)
=== modified file 'dolfin/mesh/Mesh.cpp'
--- dolfin/mesh/Mesh.cpp	2010-11-29 11:53:26 +0000
+++ dolfin/mesh/Mesh.cpp	2010-12-05 10:50:27 +0000
@@ -2,24 +2,21 @@
 // Licensed under the GNU LGPL Version 2.1.
 //
 // Modified by Johan Hoffman, 2007.
-// Modified by Garth N. Wells 2007.
+// Modified by Garth N. Wells 2007-2010.
 // Modified by Niclas Jansson 2008.
 // Modified by Kristoffer Selim 2008.
 // Modified by Andre Massing, 2009-2010.
 //
 // First added:  2006-05-09
-// Last changed: 2010-11-29
-
-#include <sstream>
-#include <vector>
-
+// Last changed: 2010-12-05
+
+#include <dolfin/ale/ALE.h>
+#include <dolfin/common/Timer.h>
+#include <dolfin/common/UniqueIdGenerator.h>
+#include <dolfin/common/utils.h>
+#include <dolfin/io/File.h>
 #include <dolfin/log/log.h>
-#include <dolfin/io/File.h>
 #include <dolfin/main/MPI.h>
-#include <dolfin/ale/ALE.h>
-#include <dolfin/io/File.h>
-#include <dolfin/common/utils.h>
-#include <dolfin/common/Timer.h>
 #include "IntersectionOperator.h"
 #include "TopologyComputation.h"
 #include "MeshSmoothing.h"
@@ -38,13 +35,16 @@
 
 //-----------------------------------------------------------------------------
 Mesh::Mesh() : Variable("mesh", "DOLFIN mesh"), _data(*this), _cell_type(0),
+               unique_id(UniqueIdGenerator::id()),
                _intersection_operator(*this), _ordered(false), _colored(-1)
 {
   // Do nothing
 }
 //-----------------------------------------------------------------------------
 Mesh::Mesh(const Mesh& mesh) : Variable("mesh", "DOLFIN mesh"), _data(*this),
-                               _cell_type(0), _intersection_operator(*this),
+                               _cell_type(0),
+                               unique_id(UniqueIdGenerator::id()),
+                               _intersection_operator(*this),
                                _ordered(false), _colored(-1)
 {
   *this = mesh;
@@ -52,6 +52,7 @@
 //-----------------------------------------------------------------------------
 Mesh::Mesh(std::string filename) : Variable("mesh", "DOLFIN mesh"),
                                    _data(*this), _cell_type(0),
+                                   unique_id(UniqueIdGenerator::id()),
                                    _intersection_operator(*this),
                                    _ordered(false), _colored(-1)
 {

=== modified file 'dolfin/mesh/Mesh.h'
--- dolfin/mesh/Mesh.h	2010-11-29 11:53:26 +0000
+++ dolfin/mesh/Mesh.h	2010-12-05 10:50:27 +0000
@@ -3,7 +3,7 @@
 //
 // Modified by Johan Hoffman, 2007.
 // Modified by Magnus Vikstrøm, 2007.
-// Modified by Garth N. Wells, 2007.
+// Modified by Garth N. Wells, 2007-2010.
 // Modified by Niclas Jansson, 2008.
 // Modified by Kristoffer Selim, 2008.
 // Modified by Andre Massing, 2009-2010.
@@ -16,6 +16,7 @@
 
 #include <string>
 #include <utility>
+#include <vector>
 
 #include <dolfin/common/types.h>
 #include <dolfin/common/Variable.h>
@@ -611,6 +612,9 @@
     // Cell type
     CellType* _cell_type;
 
+    // Unique mesh identifier
+    const uint unique_id;
+
     // Intersection detector
     IntersectionOperator _intersection_operator;
 


--- End Message ---

Follow ups