Added serialization, working on properties.
authorTrevor Irons <tirons@egi.utah.edu>
Wed, 15 Jun 2016 19:27:15 +0000 (13:27 -0600)
committerTrevor Irons <tirons@egi.utah.edu>
Wed, 15 Jun 2016 19:27:15 +0000 (13:27 -0600)
examples/DEMGrain.cpp
include/.DEMParticle.h.swp [deleted file]
include/DEM4Core
include/DEMParticle.h
src/.DEMObject.cpp.swp [deleted file]
src/DEMParticle.cpp

index 9dbb979..2a7eb01 100644 (file)
  * @copyright Copyright (c) 2016, Lemma Software, LLC
  */
 
-
-#include "Lemma"
+#include "LemmaCore"
 #include "DEM4Core"
 using namespace Lemma;
-
-
 int main()
 {
-    std::cout << "Hello DEM" << std::endl;
+    auto Grain = DEMParticle::NewSP();
+    Grain->SetCentreMass( (Vector3r() << 2,3,4).finished() );
+    std::cout << *Grain << std::endl;
+    YAML::Node ng = Grain->Serialize();
+
+    //Vector3r pos; pos << 2,3,4;
+
+    //Grain->SetCentreMass( pos );
+
+    auto Grain2 = DEMParticle::DeSerialize(ng);
+    std::cout << *Grain2 << std::endl;
+
+    if ( Grain2 != Grain) {
+        std::cout << "Not Equal" << std::endl;
+    }
 }
 
diff --git a/include/.DEMParticle.h.swp b/include/.DEMParticle.h.swp
deleted file mode 100644 (file)
index 1fd44fa..0000000
Binary files a/include/.DEMParticle.h.swp and /dev/null differ
index 8b13789..d41a689 100644 (file)
@@ -1 +1 @@
-
+#include "DEMParticle.h"
index a065ce8..2fe1cfb 100644 (file)
@@ -38,16 +38,10 @@ namespace Lemma {
         // ====================  LIFECYCLE     =======================
 
         /**
-         * @copybrief LemmaObject::New()
-         * @copydetails LemmaObject::New()
+         *  Factory method for generating concrete class.
+         *  @return a std::shared_ptr of type DEMParticle
          */
-        static DEMParticle* New();
-
-        /**
-         *  @copybrief   LemmaObject::Delete()
-         *  @copydetails LemmaObject::Delete()
-         */
-        void Delete();
+        static std::shared_ptr< DEMParticle > NewSP();
 
         // ====================  OPERATORS     =======================
 
@@ -55,6 +49,10 @@ namespace Lemma {
 
         // ====================  ACCESS        =======================
 
+        void SetCentreMass( const Vector3r& pos );
+
+        Vector3r GetCentreMass(  );
+
         // ====================  INQUIRY       =======================
 
 #ifdef HAVE_YAMLCPP
@@ -67,7 +65,7 @@ namespace Lemma {
         /**
          *   Constructs an object from a YAML::Node.
          */
-        static DEMParticle* DeSerialize(const YAML::Node& node);
+        static std::shared_ptr< DEMParticle > DeSerialize(const YAML::Node& node);
 #endif
 
         protected:
@@ -85,16 +83,12 @@ namespace Lemma {
         /** Default protected destructor, use Delete */
         ~DEMParticle ();
 
-        /**
-         *  @copybrief   LemmaObject::Release()
-         *  @copydetails LemmaObject::Release()
-         */
-        void Release();
-
         private:
 
         // ====================  DATA MEMBERS  =========================
 
+        Vector3r    centreMass;
+
     }; // -----  end of class  DEMParticle  -----
 
 }              // -----  end of Lemma  name  -----
diff --git a/src/.DEMObject.cpp.swp b/src/.DEMObject.cpp.swp
deleted file mode 100644 (file)
index c9f2c8c..0000000
Binary files a/src/.DEMObject.cpp.swp and /dev/null differ
index 7ccae17..b90ac1c 100644 (file)
@@ -52,19 +52,18 @@ DEMParticle::DEMParticle (const std::string& name) : LemmaObject(name) {
 // Description:  DeSerializing constructor (protected)
 //--------------------------------------------------------------------------------------
 DEMParticle::DEMParticle (const YAML::Node& node) : LemmaObject(node) {
-
+    this->centreMass = node["centreMass"].as<Vector3r>();
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
 #endif
 
 //--------------------------------------------------------------------------------------
 //       Class:  DEMParticle
-//      Method:  New()
+//      Method:  NewSP()
 // Description:  public constructor
 //--------------------------------------------------------------------------------------
-DEMParticle* DEMParticle::New() {
-    DEMParticle*  Obj = new DEMParticle("DEMParticle");
-    Obj->AttachTo(Obj);
-    return Obj;
+std::shared_ptr< DEMParticle > DEMParticle::NewSP() {
+    std::shared_ptr<DEMParticle> sp(new  DEMParticle("DEMParticle"), LemmaObjectDeleter() );
+    return sp;
 }
 
 //--------------------------------------------------------------------------------------
@@ -76,25 +75,6 @@ DEMParticle::~DEMParticle () {
 
 }  // -----  end of method DEMParticle::~DEMParticle  (destructor)  -----
 
-//--------------------------------------------------------------------------------------
-//       Class:  DEMParticle
-//      Method:  Delete
-// Description:  public destructor
-//--------------------------------------------------------------------------------------
-void DEMParticle::Delete() {
-    this->DetachFrom(this);
-}
-
-//--------------------------------------------------------------------------------------
-//       Class:  DEMParticle
-//      Method:  Release
-// Description:  destructor (protected)
-//--------------------------------------------------------------------------------------
-void DEMParticle::Release() {
-    delete this;
-}
-
-
 #ifdef HAVE_YAMLCPP
 //--------------------------------------------------------------------------------------
 //       Class:  DEMParticle
@@ -102,23 +82,41 @@ void DEMParticle::Release() {
 //--------------------------------------------------------------------------------------
 YAML::Node  DEMParticle::Serialize (  ) const {
     YAML::Node node = LemmaObject::Serialize();;
-    node.SetTag( this->Name );
+    node.SetTag( this->GetName() );
     // FILL IN CLASS SPECIFICS HERE
+    node["centreMass"] = centreMass;
     return node;
 }              // -----  end of method DEMParticle::Serialize  -----
 
-
 //--------------------------------------------------------------------------------------
 //       Class:  DEMParticle
 //      Method:  DeSerialize
 //--------------------------------------------------------------------------------------
-DEMParticle* DEMParticle::DeSerialize ( const YAML::Node& node  ) {
-    DEMParticle* Object = new DEMParticle(node);
-    Object->AttachTo(Object);
-    DESERIALIZECHECK( node, Object )
+std::shared_ptr<DEMParticle> DEMParticle::DeSerialize ( const YAML::Node& node  ) {
+    std::shared_ptr<DEMParticle> Object(new  DEMParticle(node), LemmaObjectDeleter() );
+    DESERIALIZECHECK( node, Object.get() )
         return Object ;
 }              // -----  end of method DEMParticle::DeSerialize  -----
 #endif
 
+
+//--------------------------------------------------------------------------------------
+//       Class:  DEMParticle
+//      Method:  GetCentreMass
+//--------------------------------------------------------------------------------------
+Vector3r DEMParticle::GetCentreMass (  ) {
+    return centreMass;
+}              // -----  end of method DEMParticle::get_CentreMass  -----
+
+//--------------------------------------------------------------------------------------
+//       Class:  DEMParticle
+//      Method:  SetCentreMass
+//--------------------------------------------------------------------------------------
+void DEMParticle::SetCentreMass ( const Vector3r& pos ) {
+    centreMass = pos;
+    return ;
+}              // -----  end of method DEMParticle::set_CentreMass  -----
+
+
 }              // -----  end of Lemma  name  -----