瀏覽代碼

reworking key

submodule
Trevor Irons 6 年之前
父節點
當前提交
64b883ac2f

+ 28
- 23
Modules/FDEM1D/include/LayeredEarthEMReader.h 查看文件

@@ -26,17 +26,14 @@
26 26
 namespace Lemma {
27 27
 
28 28
     /**
29
-      \brief
30
-      \details
29
+      \brief Reads ASCII representation of LayeredEarth, similiar to UBC format.
30
+      \details Largely superceded by YAML serialisation, this class remains for legacy purposes.
31 31
      */
32 32
     class LayeredEarthEMReader : public LemmaObject {
33 33
 
34 34
 		friend std::ostream &operator<<(std::ostream &stream,
35 35
 			const LayeredEarthEMReader &ob);
36 36
 
37
-        friend std::ostream &operator<<(std::ostream &stream,
38
-                const LayeredEarthEMReader &ob);
39
-
40 37
         struct ctor_key{};
41 38
 
42 39
         public:
@@ -44,16 +41,28 @@ namespace Lemma {
44 41
         // ====================  LIFECYCLE     =======================
45 42
 
46 43
         /**
47
-         * @copybrief LemmaObject::New()
48
-         * @copydetails LemmaObject::New()
44
+         * @copybrief LemmaObject::NewSP()
45
+         * @copydetails LemmaObject::NewSP()
49 46
          */
50
-        static LayeredEarthEMReader* New();
47
+        static std::shared_ptr<LayeredEarthEMReader> NewSP();
48
+
49
+        /** Default locked constructor, use New */
50
+        explicit LayeredEarthEMReader ( const ctor_key& );
51
+
52
+        /** Locked deserializing constructor. */
53
+			LayeredEarthEMReader ( const YAML::Node& node, const ctor_key& );
54
+
55
+        /** Default destructor */
56
+        virtual ~LayeredEarthEMReader ();
57
+
58
+        /** YAML Serializing method
59
+         */
60
+        YAML::Node Serialize() const;
51 61
 
52 62
         /**
53
-         *  @copybrief   LemmaObject::Delete()
54
-         *  @copydetails LemmaObject::Delete()
63
+         *   Constructs an object from a YAML::Node.
55 64
          */
56
-        void Delete();
65
+        static std::shared_ptr< LayeredEarthEMReader > DeSerialize(const YAML::Node& node);
57 66
 
58 67
         // ====================  OPERATORS     =======================
59 68
 
@@ -79,28 +88,24 @@ namespace Lemma {
79 88
 
80 89
         // ====================  INQUIRY       =======================
81 90
 
91
+        /** Returns the name of the underlying class, similiar to Python's type */
92
+        virtual std::string GetName() const {
93
+            return this->CName;
94
+        }
95
+
82 96
         protected:
83 97
 
84 98
         // ====================  LIFECYCLE     =======================
85 99
 
86
-        /** Default protected constructor, use New */
87
-        LayeredEarthEMReader (const std::string& name);
88
-
89
-        /** Default protected destructor, use Delete */
90
-        ~LayeredEarthEMReader ();
91
-
92
-        /**
93
-         *  @copybrief   LemmaObject::Release()
94
-         *  @copydetails LemmaObject::Release()
95
-         */
96
-        void Release();
97
-
98 100
         private:
99 101
 
100 102
         // ====================  DATA MEMBERS  =========================
101 103
 
102 104
         LayeredEarthEM*         LayEarth;
103 105
 
106
+        /** ASCII string representation of the class name */
107
+        static constexpr auto CName = "LayeredEarthEMReader";
108
+
104 109
     }; // -----  end of class  LayeredEarthEMReader  -----
105 110
 
106 111
 

+ 1
- 0
Modules/FDEM1D/src/CMakeLists.txt 查看文件

@@ -2,6 +2,7 @@ set (FDEM1DSOURCE
2 2
 	${FDEM1DSOURCE}
3 3
 
4 4
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthEM.cpp
5
+#	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthEMReader.cpp
5 6
 	
6 7
 	${CMAKE_CURRENT_SOURCE_DIR}/FieldPoints.cpp
7 8
 	

+ 1
- 1
Modules/FDEM1D/src/LayeredEarthEM.cpp 查看文件

@@ -22,7 +22,7 @@ namespace Lemma {
22 22
 
23 23
     // ====================  LIFECYCLE     ===================================
24 24
 
25
-    LayeredEarthEM::LayeredEarthEM( const ctor_key& ) : LayeredEarth() {
25
+    LayeredEarthEM::LayeredEarthEM( const ctor_key& key ) : LayeredEarth( LayeredEarth::ctor_key() ) {
26 26
     }
27 27
 
28 28
     LayeredEarthEM::LayeredEarthEM( const YAML::Node& node, const ctor_key& ) : LayeredEarth(node) {

+ 5
- 6
Modules/FDEM1D/src/LayeredEarthEMReader.cpp 查看文件

@@ -22,13 +22,12 @@ namespace Lemma {
22 22
 
23 23
     // ====================  FRIEND METHODS  =====================
24 24
 
25
-    std::ostream &operator<<(std::ostream &stream, const LayeredEarthEMReader &ob) {
26
-
27
-        stream << *(LemmaObject*)(&ob);
28
-
25
+    std::ostream &operator << (std::ostream &stream, const LayeredEarthEMReader &ob) {
26
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
29 27
         return stream;
30 28
     }
31 29
 
30
+
32 31
     // ====================  LIFECYCLE     =======================
33 32
 
34 33
     //--------------------------------------------------------------------------------------
@@ -36,8 +35,8 @@ namespace Lemma {
36 35
     //      Method:  LayeredEarthEMReader
37 36
     // Description:  constructor (protected)
38 37
     //--------------------------------------------------------------------------------------
39
-    LayeredEarthEMReader::LayeredEarthEMReader (const std::string& name) : LemmaObject(name),
40
-        LayEarth(NULL) {
38
+    LayeredEarthEMReader::LayeredEarthEMReader ( const ctor_key& key ) : LemmaObject(),
39
+        LayEarth(nullptr) {
41 40
 
42 41
     }  // -----  end of method LayeredEarthEMReader::LayeredEarthEMReader  (constructor)  -----
43 42
 

+ 1
- 1
Modules/LemmaCore/include/ASCIIParser.h 查看文件

@@ -36,7 +36,7 @@ class ASCIIParser : public LemmaObject {
36 36
     /*
37 37
      *  This key is used to lock the constructors
38 38
      */
39
-    struct ctor_key {};
39
+    //struct ctor_key {};
40 40
 
41 41
     public:
42 42
 

+ 3
- 1
Modules/LemmaCore/include/LayeredEarth.h 查看文件

@@ -30,6 +30,8 @@ namespace Lemma {
30 30
         friend class LayeredEarthEM;
31 31
         friend class LayeredEarthMR;
32 32
 
33
+        struct ctor_key{};
34
+
33 35
 		public:
34 36
 
35 37
 			// ====================    FRIENDS     ===========================
@@ -102,7 +104,7 @@ namespace Lemma {
102 104
 			// ====================  LIFECYCLE     ===========================
103 105
 
104 106
 			/** Default protected constructor. */
105
-			LayeredEarth ( );
107
+			LayeredEarth ( const ctor_key& );
106 108
 
107 109
             /** Default protected constructor. */
108 110
 			LayeredEarth (const YAML::Node& node);

+ 6
- 9
Modules/LemmaCore/include/LemmaObject.h 查看文件

@@ -41,9 +41,11 @@ class LemmaObject {
41 41
      */
42 42
     //friend YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject &ob) ;
43 43
 
44
-    friend class LemmaObjectDeleter;
44
+    protected:
45
+        struct ctor_key{};
45 46
 
46 47
     public:
48
+
47 49
         // Needed because many derived classes have Eigen vectors as members,
48 50
         // causing alignment issues when vectorisation is enabled.
49 51
         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
@@ -95,11 +97,12 @@ class LemmaObject {
95 97
         /** Protected default constructor. This is an abstract class and
96 98
          *  cannot be instantiated.
97 99
          */
98
-        LemmaObject ( );
100
+        LemmaObject ( const ctor_key& );
99 101
 
100 102
         /** Protected DeSerializing constructor */
101
-        LemmaObject (const YAML::Node& node);
103
+        LemmaObject ( const YAML::Node& node, const ctor_key& );
102 104
 
105
+        /** Disable copying Lemma Object */
103 106
         LemmaObject( const LemmaObject& ) = delete;
104 107
 
105 108
         /** Protected default destructor. This is an abstract class and
@@ -117,12 +120,6 @@ class LemmaObject {
117 120
 
118 121
 }; // -----  end of class  LemmaObject  -----
119 122
 
120
-class LemmaObjectDeleter
121
-{
122
-    public:
123
-        void operator()(LemmaObject* p) { delete p; }
124
-};
125
-
126 123
     /////////////////////////////////////////////////////////////////
127 124
     // Error Classes
128 125
 

+ 2
- 2
Modules/LemmaCore/src/ASCIIParser.cpp 查看文件

@@ -35,7 +35,7 @@ namespace Lemma {
35 35
     //      Method:  ASCIIParser
36 36
     // Description:  constructor (locked)
37 37
     //--------------------------------------------------------------------------------------
38
-    ASCIIParser::ASCIIParser ( const ctor_key& ) : LemmaObject( ), input(),
38
+    ASCIIParser::ASCIIParser ( const ctor_key& key ) : LemmaObject( key ), input(),
39 39
             CommentString("//"), BufferSize(255) {
40 40
 
41 41
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
@@ -96,7 +96,7 @@ namespace Lemma {
96 96
     //      Method:  ASCIIParser
97 97
     // Description:  DeSerializing constructor (protected)
98 98
     //--------------------------------------------------------------------------------------
99
-    ASCIIParser::ASCIIParser (const YAML::Node& node, const ctor_key&  key) : LemmaObject(node) {
99
+    ASCIIParser::ASCIIParser (const YAML::Node& node, const ctor_key&  key) : LemmaObject(node, key) {
100 100
         this->CommentString = node["CommentString"].as<std::string>();
101 101
         this->BufferSize = node["BufferSize"].as<int>();
102 102
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----

+ 1
- 1
Modules/LemmaCore/src/LayeredEarth.cpp 查看文件

@@ -24,7 +24,7 @@ namespace Lemma {
24 24
 
25 25
 	// ====================  LIFECYCLE     ===================================
26 26
 
27
-	LayeredEarth::LayeredEarth( ) : EarthModel( ),
27
+	LayeredEarth::LayeredEarth( const ctor_key& key ) : EarthModel( ),
28 28
 		NumberOfLayers(0), 	NumberOfInterfaces(0) {
29 29
 	}
30 30
 

+ 2
- 9
Modules/LemmaCore/src/LemmaObject.cpp 查看文件

@@ -15,21 +15,14 @@
15 15
 
16 16
 namespace Lemma {
17 17
 
18
-//     YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
19
-//         out << YAML::Flow;
20
-//         out << YAML::BeginMap;
21
-//         out << YAML::Key <<"Class Name"    << YAML::Value << ob.GetName();
22
-//         return out;
23
-//     }
24
-
25 18
     // ====================  LIFECYCLE     ==============================
26 19
 
27 20
     // Constructor
28
-    LemmaObject::LemmaObject(  ) {
21
+    LemmaObject::LemmaObject( const ctor_key& ) {
29 22
 
30 23
     }
31 24
 
32
-    LemmaObject::LemmaObject(const YAML::Node &node) {
25
+    LemmaObject::LemmaObject( const YAML::Node &node, const ctor_key& ) {
33 26
     }
34 27
 
35 28
     // Destructor

Loading…
取消
儲存