Browse Source

Cleaning up yaml, and adding funtionality.

master
Trevor Irons 8 years ago
parent
commit
dc6be59497
4 changed files with 21 additions and 19 deletions
  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 View File

19
 
19
 
20
 #include "LemmaCore"
20
 #include "LemmaCore"
21
 #include "DEM4Core"
21
 #include "DEM4Core"
22
+
22
 using namespace Lemma;
23
 using namespace Lemma;
23
 int main()
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
     std::cout << *Grain << std::endl;
28
     std::cout << *Grain << std::endl;
28
     YAML::Node ng = Grain->Serialize();
29
     YAML::Node ng = Grain->Serialize();
29
 
30
 
31
 
32
 
32
     //Grain->SetCentreMass( pos );
33
     //Grain->SetCentreMass( pos );
33
 
34
 
34
-    auto Grain2 = DEMParticle::DeSerialize(ng);
35
+    auto Grain2 = DEMGrain::DeSerialize(ng);
35
     std::cout << *Grain2 << std::endl;
36
     std::cout << *Grain2 << std::endl;
36
 
37
 
37
-    if ( Grain2 != Grain) {
38
+/*
39
+    if ( *Grain2 != *Grain) {
38
         std::cout << "Not Equal" << std::endl;
40
         std::cout << "Not Equal" << std::endl;
39
     }
41
     }
42
+*/
43
+
40
 }
44
 }
41
 
45
 

+ 4
- 0
include/DEM4Core View File

1
 #include "DEMParticle.h"
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 View File

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

+ 8
- 15
src/DEMParticle.cpp View File

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

Loading…
Cancel
Save