Browse Source

Added serialization, working on properties.

master
Trevor Irons 8 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
  * @copyright Copyright (c) 2016, Lemma Software, LLC
17
  * @copyright Copyright (c) 2016, Lemma Software, LLC
18
  */
18
  */
19
 
19
 
20
-
21
-#include "Lemma"
20
+#include "LemmaCore"
22
 #include "DEM4Core"
21
 #include "DEM4Core"
23
 using namespace Lemma;
22
 using namespace Lemma;
24
-
25
-
26
 int main()
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
+#include "DEMParticle.h"

+ 10
- 16
include/DEMParticle.h View File

38
         // ====================  LIFECYCLE     =======================
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
         // ====================  OPERATORS     =======================
46
         // ====================  OPERATORS     =======================
53
 
47
 
55
 
49
 
56
         // ====================  ACCESS        =======================
50
         // ====================  ACCESS        =======================
57
 
51
 
52
+        void SetCentreMass( const Vector3r& pos );
53
+
54
+        Vector3r GetCentreMass(  );
55
+
58
         // ====================  INQUIRY       =======================
56
         // ====================  INQUIRY       =======================
59
 
57
 
60
 #ifdef HAVE_YAMLCPP
58
 #ifdef HAVE_YAMLCPP
67
         /**
65
         /**
68
          *   Constructs an object from a YAML::Node.
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
 #endif
69
 #endif
72
 
70
 
73
         protected:
71
         protected:
85
         /** Default protected destructor, use Delete */
83
         /** Default protected destructor, use Delete */
86
         ~DEMParticle ();
84
         ~DEMParticle ();
87
 
85
 
88
-        /**
89
-         *  @copybrief   LemmaObject::Release()
90
-         *  @copydetails LemmaObject::Release()
91
-         */
92
-        void Release();
93
-
94
         private:
86
         private:
95
 
87
 
96
         // ====================  DATA MEMBERS  =========================
88
         // ====================  DATA MEMBERS  =========================
97
 
89
 
90
+        Vector3r    centreMass;
91
+
98
     }; // -----  end of class  DEMParticle  -----
92
     }; // -----  end of class  DEMParticle  -----
99
 
93
 
100
 }		// -----  end of Lemma  name  -----
94
 }		// -----  end of Lemma  name  -----

BIN
src/.DEMObject.cpp.swp View File


+ 29
- 31
src/DEMParticle.cpp View File

52
 // Description:  DeSerializing constructor (protected)
52
 // Description:  DeSerializing constructor (protected)
53
 //--------------------------------------------------------------------------------------
53
 //--------------------------------------------------------------------------------------
54
 DEMParticle::DEMParticle (const YAML::Node& node) : LemmaObject(node) {
54
 DEMParticle::DEMParticle (const YAML::Node& node) : LemmaObject(node) {
55
-
55
+    this->centreMass = node["centreMass"].as<Vector3r>();
56
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
56
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
57
 #endif
57
 #endif
58
 
58
 
59
 //--------------------------------------------------------------------------------------
59
 //--------------------------------------------------------------------------------------
60
 //       Class:  DEMParticle
60
 //       Class:  DEMParticle
61
-//      Method:  New()
61
+//      Method:  NewSP()
62
 // Description:  public constructor
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
 
75
 
77
 }  // -----  end of method DEMParticle::~DEMParticle  (destructor)  -----
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
 #ifdef HAVE_YAMLCPP
78
 #ifdef HAVE_YAMLCPP
99
 //--------------------------------------------------------------------------------------
79
 //--------------------------------------------------------------------------------------
100
 //       Class:  DEMParticle
80
 //       Class:  DEMParticle
102
 //--------------------------------------------------------------------------------------
82
 //--------------------------------------------------------------------------------------
103
 YAML::Node  DEMParticle::Serialize (  ) const {
83
 YAML::Node  DEMParticle::Serialize (  ) const {
104
     YAML::Node node = LemmaObject::Serialize();;
84
     YAML::Node node = LemmaObject::Serialize();;
105
-    node.SetTag( this->Name );
85
+    node.SetTag( this->GetName() );
106
     // FILL IN CLASS SPECIFICS HERE
86
     // FILL IN CLASS SPECIFICS HERE
87
+    node["centreMass"] = centreMass;
107
     return node;
88
     return node;
108
 }		// -----  end of method DEMParticle::Serialize  -----
89
 }		// -----  end of method DEMParticle::Serialize  -----
109
 
90
 
110
-
111
 //--------------------------------------------------------------------------------------
91
 //--------------------------------------------------------------------------------------
112
 //       Class:  DEMParticle
92
 //       Class:  DEMParticle
113
 //      Method:  DeSerialize
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
         return Object ;
98
         return Object ;
120
 }		// -----  end of method DEMParticle::DeSerialize  -----
99
 }		// -----  end of method DEMParticle::DeSerialize  -----
121
 #endif
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
 }		// -----  end of Lemma  name  -----
121
 }		// -----  end of Lemma  name  -----
124
 
122
 

Loading…
Cancel
Save