Переглянути джерело

Addition of base class for Merlin, for keeping track of versioning in serialized classes.

master
Trevor Irons 7 роки тому
джерело
коміт
c9bfe603ed
1 змінених файлів з 98 додано та 0 видалено
  1. 98
    0
      src/MerlinObject.cpp

+ 98
- 0
src/MerlinObject.cpp Переглянути файл

@@ -0,0 +1,98 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      08/28/2017 11:51:33 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2017, University of Utah
17
+ * @copyright Copyright (c) 2017, Lemma Software, LLC
18
+ */
19
+
20
+
21
+#include "MerlinObject.h"
22
+
23
+namespace Lemma {
24
+
25
+    // ====================  FRIEND METHODS  =====================
26
+
27
+    std::ostream &operator << (std::ostream &stream, const MerlinObject &ob) {
28
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
29
+        return stream;
30
+    }
31
+
32
+    // ====================  LIFECYCLE     =======================
33
+
34
+    //--------------------------------------------------------------------------------------
35
+    //       Class:  MerlinObject
36
+    //      Method:  MerlinObject
37
+    // Description:  constructor (locked)
38
+    //--------------------------------------------------------------------------------------
39
+    MerlinObject::MerlinObject ( ) : LemmaObject( ) {
40
+
41
+    }  // -----  end of method MerlinObject::MerlinObject  (constructor)  -----
42
+
43
+    //--------------------------------------------------------------------------------------
44
+    //       Class:  MerlinObject
45
+    //      Method:  MerlinObject
46
+    // Description:  DeSerializing constructor (locked)
47
+    //--------------------------------------------------------------------------------------
48
+    MerlinObject::MerlinObject (const YAML::Node& node ) : LemmaObject(node) {
49
+
50
+    }  // -----  end of method MerlinObject::MerlinObject  (constructor)  -----
51
+
52
+    //--------------------------------------------------------------------------------------
53
+    //       Class:  MerlinObject
54
+    //      Method:  NewSP()
55
+    // Description:  public constructor returing a shared_ptr
56
+    //--------------------------------------------------------------------------------------
57
+    std::shared_ptr< MerlinObject >  MerlinObject::NewSP() {
58
+        return std::make_shared< MerlinObject >( );
59
+    }
60
+
61
+    //--------------------------------------------------------------------------------------
62
+    //       Class:  MerlinObject
63
+    //      Method:  ~MerlinObject
64
+    // Description:  destructor (protected)
65
+    //--------------------------------------------------------------------------------------
66
+    MerlinObject::~MerlinObject () {
67
+
68
+    }  // -----  end of method MerlinObject::~MerlinObject  (destructor)  -----
69
+
70
+    //--------------------------------------------------------------------------------------
71
+    //       Class:  MerlinObject
72
+    //      Method:  Serialize
73
+    //--------------------------------------------------------------------------------------
74
+    YAML::Node  MerlinObject::Serialize (  ) const {
75
+        YAML::Node node = LemmaObject::Serialize();
76
+        node.SetTag( GetName() );
77
+        // FILL IN CLASS SPECIFICS HERE
78
+        node["Merlin_VERSION"] = MERLIN_VERSION;
79
+        return node;
80
+    }		// -----  end of method MerlinObject::Serialize  -----
81
+
82
+    //--------------------------------------------------------------------------------------
83
+    //       Class:  MerlinObject
84
+    //      Method:  DeSerialize
85
+    //--------------------------------------------------------------------------------------
86
+    std::shared_ptr<MerlinObject> MerlinObject::DeSerialize ( const YAML::Node& node  ) {
87
+        if (node.Tag() !=  "MerlinObject" ) {
88
+            throw  DeSerializeTypeMismatch( "MerlinObject", node.Tag());
89
+        }
90
+        return std::make_shared< MerlinObject > ( node );
91
+    }		// -----  end of method MerlinObject::DeSerialize  -----
92
+
93
+} // ----  end of namespace Lemma  ----
94
+
95
+/* vim: set tabstop=4 expandtab: */
96
+/* vim: set filetype=cpp: */
97
+
98
+

Завантаження…
Відмінити
Зберегти