Browse Source

Added serialization, working on properties.

master
Trevor Irons 7 years ago
parent
commit
2af1cd9dd4
6 changed files with 56 additions and 53 deletions
  1. 16
    5
      examples/DEMGrain.cpp
  2. BIN
      include/.DEMParticle.h.swp
  3. 1
    1
      include/DEM4Core
  4. 10
    16
      include/DEMParticle.h
  5. BIN
      src/.DEMObject.cpp.swp
  6. 29
    31
      src/DEMParticle.cpp

+ 16
- 5
examples/DEMGrain.cpp View File

@@ -17,14 +17,25 @@
17 17
  * @copyright Copyright (c) 2016, Lemma Software, LLC
18 18
  */
19 19
 
20
-
21
-#include "Lemma"
20
+#include "LemmaCore"
22 21
 #include "DEM4Core"
23 22
 using namespace Lemma;
24
-
25
-
26 23
 int main()
27 24
 {
28
-    std::cout << "Hello DEM" << std::endl;
25
+    auto Grain = DEMParticle::NewSP();
26
+    Grain->SetCentreMass( (Vector3r() << 2,3,4).finished() );
27
+    std::cout << *Grain << std::endl;
28
+    YAML::Node ng = Grain->Serialize();
29
+
30
+    //Vector3r pos; pos << 2,3,4;
31
+
32
+    //Grain->SetCentreMass( pos );
33
+
34
+    auto Grain2 = DEMParticle::DeSerialize(ng);
35
+    std::cout << *Grain2 << std::endl;
36
+
37
+    if ( Grain2 != Grain) {
38
+        std::cout << "Not Equal" << std::endl;
39
+    }
29 40
 }
30 41
 

BIN
include/.DEMParticle.h.swp View File


+ 1
- 1
include/DEM4Core View File

@@ -1 +1 @@
1
-
1
+#include "DEMParticle.h"

+ 10
- 16
include/DEMParticle.h View File

@@ -38,16 +38,10 @@ namespace Lemma {
38 38
         // ====================  LIFECYCLE     =======================
39 39
 
40 40
         /**
41
-         * @copybrief LemmaObject::New()
42
-         * @copydetails LemmaObject::New()
41
+         *  Factory method for generating concrete class.
42
+         *  @return a std::shared_ptr of type DEMParticle
43 43
          */
44
-        static DEMParticle* New();
45
-
46
-        /**
47
-         *  @copybrief   LemmaObject::Delete()
48
-         *  @copydetails LemmaObject::Delete()
49
-         */
50
-        void Delete();
44
+        static std::shared_ptr< DEMParticle > NewSP();
51 45
 
52 46
         // ====================  OPERATORS     =======================
53 47
 
@@ -55,6 +49,10 @@ namespace Lemma {
55 49
 
56 50
         // ====================  ACCESS        =======================
57 51
 
52
+        void SetCentreMass( const Vector3r& pos );
53
+
54
+        Vector3r GetCentreMass(  );
55
+
58 56
         // ====================  INQUIRY       =======================
59 57
 
60 58
 #ifdef HAVE_YAMLCPP
@@ -67,7 +65,7 @@ namespace Lemma {
67 65
         /**
68 66
          *   Constructs an object from a YAML::Node.
69 67
          */
70
-        static DEMParticle* DeSerialize(const YAML::Node& node);
68
+        static std::shared_ptr< DEMParticle > DeSerialize(const YAML::Node& node);
71 69
 #endif
72 70
 
73 71
         protected:
@@ -85,16 +83,12 @@ namespace Lemma {
85 83
         /** Default protected destructor, use Delete */
86 84
         ~DEMParticle ();
87 85
 
88
-        /**
89
-         *  @copybrief   LemmaObject::Release()
90
-         *  @copydetails LemmaObject::Release()
91
-         */
92
-        void Release();
93
-
94 86
         private:
95 87
 
96 88
         // ====================  DATA MEMBERS  =========================
97 89
 
90
+        Vector3r    centreMass;
91
+
98 92
     }; // -----  end of class  DEMParticle  -----
99 93
 
100 94
 }		// -----  end of Lemma  name  -----

BIN
src/.DEMObject.cpp.swp View File


+ 29
- 31
src/DEMParticle.cpp View File

@@ -52,19 +52,18 @@ DEMParticle::DEMParticle (const std::string& name) : LemmaObject(name) {
52 52
 // Description:  DeSerializing constructor (protected)
53 53
 //--------------------------------------------------------------------------------------
54 54
 DEMParticle::DEMParticle (const YAML::Node& node) : LemmaObject(node) {
55
-
55
+    this->centreMass = node["centreMass"].as<Vector3r>();
56 56
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
57 57
 #endif
58 58
 
59 59
 //--------------------------------------------------------------------------------------
60 60
 //       Class:  DEMParticle
61
-//      Method:  New()
61
+//      Method:  NewSP()
62 62
 // Description:  public constructor
63 63
 //--------------------------------------------------------------------------------------
64
-DEMParticle* DEMParticle::New() {
65
-    DEMParticle*  Obj = new DEMParticle("DEMParticle");
66
-    Obj->AttachTo(Obj);
67
-    return Obj;
64
+std::shared_ptr< DEMParticle > DEMParticle::NewSP() {
65
+    std::shared_ptr<DEMParticle> sp(new  DEMParticle("DEMParticle"), LemmaObjectDeleter() );
66
+    return sp;
68 67
 }
69 68
 
70 69
 //--------------------------------------------------------------------------------------
@@ -76,25 +75,6 @@ DEMParticle::~DEMParticle () {
76 75
 
77 76
 }  // -----  end of method DEMParticle::~DEMParticle  (destructor)  -----
78 77
 
79
-//--------------------------------------------------------------------------------------
80
-//       Class:  DEMParticle
81
-//      Method:  Delete
82
-// Description:  public destructor
83
-//--------------------------------------------------------------------------------------
84
-void DEMParticle::Delete() {
85
-    this->DetachFrom(this);
86
-}
87
-
88
-//--------------------------------------------------------------------------------------
89
-//       Class:  DEMParticle
90
-//      Method:  Release
91
-// Description:  destructor (protected)
92
-//--------------------------------------------------------------------------------------
93
-void DEMParticle::Release() {
94
-    delete this;
95
-}
96
-
97
-
98 78
 #ifdef HAVE_YAMLCPP
99 79
 //--------------------------------------------------------------------------------------
100 80
 //       Class:  DEMParticle
@@ -102,23 +82,41 @@ void DEMParticle::Release() {
102 82
 //--------------------------------------------------------------------------------------
103 83
 YAML::Node  DEMParticle::Serialize (  ) const {
104 84
     YAML::Node node = LemmaObject::Serialize();;
105
-    node.SetTag( this->Name );
85
+    node.SetTag( this->GetName() );
106 86
     // FILL IN CLASS SPECIFICS HERE
87
+    node["centreMass"] = centreMass;
107 88
     return node;
108 89
 }		// -----  end of method DEMParticle::Serialize  -----
109 90
 
110
-
111 91
 //--------------------------------------------------------------------------------------
112 92
 //       Class:  DEMParticle
113 93
 //      Method:  DeSerialize
114 94
 //--------------------------------------------------------------------------------------
115
-DEMParticle* DEMParticle::DeSerialize ( const YAML::Node& node  ) {
116
-    DEMParticle* Object = new DEMParticle(node);
117
-    Object->AttachTo(Object);
118
-    DESERIALIZECHECK( node, Object )
95
+std::shared_ptr<DEMParticle> DEMParticle::DeSerialize ( const YAML::Node& node  ) {
96
+    std::shared_ptr<DEMParticle> Object(new  DEMParticle(node), LemmaObjectDeleter() );
97
+    DESERIALIZECHECK( node, Object.get() )
119 98
         return Object ;
120 99
 }		// -----  end of method DEMParticle::DeSerialize  -----
121 100
 #endif
122 101
 
102
+
103
+//--------------------------------------------------------------------------------------
104
+//       Class:  DEMParticle
105
+//      Method:  GetCentreMass
106
+//--------------------------------------------------------------------------------------
107
+Vector3r DEMParticle::GetCentreMass (  ) {
108
+    return centreMass;
109
+}		// -----  end of method DEMParticle::get_CentreMass  -----
110
+
111
+//--------------------------------------------------------------------------------------
112
+//       Class:  DEMParticle
113
+//      Method:  SetCentreMass
114
+//--------------------------------------------------------------------------------------
115
+void DEMParticle::SetCentreMass ( const Vector3r& pos ) {
116
+    centreMass	= pos;
117
+    return ;
118
+}		// -----  end of method DEMParticle::set_CentreMass  -----
119
+
120
+
123 121
 }		// -----  end of Lemma  name  -----
124 122
 

Loading…
Cancel
Save