Przeglądaj źródła

Cleaning up yaml, and adding funtionality.

master
Trevor Irons 8 lat temu
rodzic
commit
dc6be59497
4 zmienionych plików z 21 dodań i 19 usunięć
  1. 8
    4
      examples/DEMGrain.cpp
  2. 4
    0
      include/DEM4Core
  3. 1
    0
      src/CMakeLists.txt
  4. 8
    15
      src/DEMParticle.cpp

+ 8
- 4
examples/DEMGrain.cpp Wyświetl plik

@@ -19,11 +19,12 @@
19 19
 
20 20
 #include "LemmaCore"
21 21
 #include "DEM4Core"
22
+
22 23
 using namespace Lemma;
23 24
 int main()
24 25
 {
25
-    auto Grain = DEMParticle::NewSP();
26
-    Grain->SetCentreMass( (Vector3r() << 2,3,4).finished() );
26
+    auto Grain = DEMGrain::NewSP();
27
+    Grain->SetCentreMass( (Vector3r() << 2.254,3.14,4.).finished() );
27 28
     std::cout << *Grain << std::endl;
28 29
     YAML::Node ng = Grain->Serialize();
29 30
 
@@ -31,11 +32,14 @@ int main()
31 32
 
32 33
     //Grain->SetCentreMass( pos );
33 34
 
34
-    auto Grain2 = DEMParticle::DeSerialize(ng);
35
+    auto Grain2 = DEMGrain::DeSerialize(ng);
35 36
     std::cout << *Grain2 << std::endl;
36 37
 
37
-    if ( Grain2 != Grain) {
38
+/*
39
+    if ( *Grain2 != *Grain) {
38 40
         std::cout << "Not Equal" << std::endl;
39 41
     }
42
+*/
43
+
40 44
 }
41 45
 

+ 4
- 0
include/DEM4Core Wyświetl plik

@@ -1 +1,5 @@
1 1
 #include "DEMParticle.h"
2
+#include "DEMGrain.h"
3
+
4
+/* vim: set tabstop=4 expandtab: */
5
+/* vim: set filetype=cpp: */

+ 1
- 0
src/CMakeLists.txt Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 set (DEMSOURCE
2 2
 	${DEMSOURCE}
3 3
 	${CMAKE_CURRENT_SOURCE_DIR}/DEMParticle.cpp
4
+	${CMAKE_CURRENT_SOURCE_DIR}/DEMGrain.cpp
4 5
 	PARENT_SCOPE
5 6
 )

+ 8
- 15
src/DEMParticle.cpp Wyświetl plik

@@ -22,17 +22,11 @@
22 22
 namespace Lemma {
23 23
 
24 24
 // ====================  FRIEND METHODS  =====================
25
-#ifdef HAVE_YAMLCPP
25
+
26 26
 std::ostream &operator << (std::ostream &stream, const DEMParticle &ob) {
27 27
     stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
28 28
     return stream;
29 29
 }
30
-#else
31
-std::ostream &operator<<(std::ostream &stream, const DEMParticle& ob) {
32
-    stream << *(LemmaObject*)(&ob);
33
-    return stream;
34
-}
35
-#endif
36 30
 
37 31
 // ====================  LIFECYCLE     =======================
38 32
 
@@ -45,7 +39,6 @@ DEMParticle::DEMParticle (const std::string& name) : LemmaObject(name) {
45 39
 
46 40
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
47 41
 
48
-#ifdef HAVE_YAMLCPP
49 42
 //--------------------------------------------------------------------------------------
50 43
 //       Class:  DEMParticle
51 44
 //      Method:  DEMParticle
@@ -54,7 +47,6 @@ DEMParticle::DEMParticle (const std::string& name) : LemmaObject(name) {
54 47
 DEMParticle::DEMParticle (const YAML::Node& node) : LemmaObject(node) {
55 48
     this->centreMass = node["centreMass"].as<Vector3r>();
56 49
 }  // -----  end of method DEMParticle::DEMParticle  (constructor)  -----
57
-#endif
58 50
 
59 51
 //--------------------------------------------------------------------------------------
60 52
 //       Class:  DEMParticle
@@ -75,14 +67,13 @@ DEMParticle::~DEMParticle () {
75 67
 
76 68
 }  // -----  end of method DEMParticle::~DEMParticle  (destructor)  -----
77 69
 
78
-#ifdef HAVE_YAMLCPP
79 70
 //--------------------------------------------------------------------------------------
80 71
 //       Class:  DEMParticle
81 72
 //      Method:  Serialize
82 73
 //--------------------------------------------------------------------------------------
83 74
 YAML::Node  DEMParticle::Serialize (  ) const {
84 75
     YAML::Node node = LemmaObject::Serialize();;
85
-    node.SetTag( this->GetName() );
76
+    node.SetTag( GetName() );
86 77
     // FILL IN CLASS SPECIFICS HERE
87 78
     node["centreMass"] = centreMass;
88 79
     return node;
@@ -93,12 +84,12 @@ YAML::Node  DEMParticle::Serialize (  ) const {
93 84
 //      Method:  DeSerialize
94 85
 //--------------------------------------------------------------------------------------
95 86
 std::shared_ptr<DEMParticle> DEMParticle::DeSerialize ( const YAML::Node& node  ) {
87
+    if (node.Tag() != "DEMParticle") {
88
+        throw  DeSerializeTypeMismatch( "DEMParticle", node.Tag());
89
+    }
96 90
     std::shared_ptr<DEMParticle> Object(new  DEMParticle(node), LemmaObjectDeleter() );
97
-    DESERIALIZECHECK( node, Object.get() )
98
-        return Object ;
91
+    return Object ;
99 92
 }		// -----  end of method DEMParticle::DeSerialize  -----
100
-#endif
101
-
102 93
 
103 94
 //--------------------------------------------------------------------------------------
104 95
 //       Class:  DEMParticle
@@ -120,3 +111,5 @@ void DEMParticle::SetCentreMass ( const Vector3r& pos ) {
120 111
 
121 112
 }		// -----  end of Lemma  name  -----
122 113
 
114
+/* vim: set tabstop=4 expandtab: */
115
+/* vim: set filetype=cpp: */

Ładowanie…
Anuluj
Zapisz