Преглед изворни кода

Deciding on design changes wrt. allowing stack allocation?

enhancement_3
T-bone пре 7 година
родитељ
комит
9ef7370e73

+ 4
- 0
Modules/LemmaCore/examples/CMakeLists.txt Прегледај датотеку

@@ -27,7 +27,11 @@
27 27
 #add_executable( femforward  femforward.cpp )
28 28
 #target_link_libraries(femforward "lemmacore")
29 29
 
30
+add_executable( CubicSplineInterpolator  CubicSplineInterpolator.cpp )
31
+target_link_libraries(CubicSplineInterpolator "lemmacore")
32
+
30 33
 add_executable( filter  filter.cpp )
31 34
 target_link_libraries(filter "lemmacore")
32 35
 
33 36
 
37
+

+ 36
- 0
Modules/LemmaCore/examples/CubicSplineInterpolator.cpp Прегледај датотеку

@@ -0,0 +1,36 @@
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      09/21/2016 10:24:57 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include "CubicSplineInterpolator.h"
21
+#include "ASCIIParser.h"
22
+using namespace Lemma;
23
+
24
+int main() {
25
+    auto Spline = CubicSplineInterpolator::NewSP();
26
+    //auto Spline2 = CubicSplineInterpolator();
27
+    auto Parser = ASCIIParser::NewSP();
28
+    //ASCIIParser Parser2 = ASCIIParser();
29
+    //    Parser2.SetCommentString( "#");
30
+    //auto Parser3 = ASCIIParser(Parser2);
31
+
32
+    std::cout << *Parser << std::endl;
33
+    //std::cout << Parser2 << std::endl;
34
+    //std::cout << Parser3 << std::endl;
35
+}
36
+

+ 13
- 16
Modules/LemmaCore/include/ASCIIParser.h Прегледај датотеку

@@ -34,10 +34,21 @@ class ASCIIParser : public LemmaObject {
34 34
     friend std::ostream &operator<<(std::ostream &stream,
35 35
             const ASCIIParser &ob);
36 36
 
37
+    struct ctor_cookie {};
38
+
37 39
     public:
38 40
 
39 41
     // ====================  LIFECYCLE     =======================
40 42
 
43
+    /** Default constructor */
44
+    explicit ASCIIParser ( const ctor_cookie& );
45
+
46
+    /** Constructor using YAML::Node */
47
+    ASCIIParser ( const YAML::Node& node, const ctor_cookie& );
48
+
49
+    /** Default  destructor */
50
+    virtual ~ASCIIParser ();
51
+
41 52
     /**
42 53
      *  Factory method for generating concrete class.
43 54
      *  @return a std::shared_ptr of type ASCIIParser
@@ -121,22 +132,8 @@ class ASCIIParser : public LemmaObject {
121 132
 
122 133
     protected:
123 134
 
124
-    // ====================  LIFECYCLE     =======================
125
-
126
-    /** Default protected constructor, use New */
127
-    ASCIIParser ( );
128
-
129
-    /** Constructor using YAML::Node */
130
-    ASCIIParser ( const YAML::Node& node );
131
-
132
-    /** Default protected destructor, use Delete */
133
-    ~ASCIIParser ();
134
-
135
-    /**
136
-     *  @copybrief   LemmaObject::Release()
137
-     *  @copydetails LemmaObject::Release()
138
-     */
139
-    void Release();
135
+    /** Copy constructor */
136
+    ASCIIParser( const ASCIIParser& ) = delete;
140 137
 
141 138
     private:
142 139
 

+ 11
- 17
Modules/LemmaCore/include/CubicSplineInterpolator.h Прегледај датотеку

@@ -62,10 +62,21 @@ class CubicSplineInterpolator : public LemmaObject {
62 62
     friend std::ostream &operator<<(std::ostream &stream,
63 63
             const CubicSplineInterpolator &ob);
64 64
 
65
+    struct ctor_cookie {};
66
+
65 67
     public:
66 68
 
67 69
     // ====================  LIFECYCLE     =======================
68 70
 
71
+    /** Default constructor */
72
+    explicit CubicSplineInterpolator ( const ctor_cookie& );
73
+
74
+    /** DeSerializing constructor, usees factory DeSerialize  method*/
75
+    CubicSplineInterpolator ( const YAML::Node& node, const ctor_cookie& );
76
+
77
+    /** Destructor use smart pointers to auto delete */
78
+    virtual ~CubicSplineInterpolator ();
79
+
69 80
     /**
70 81
      *  Factory method for generating concrete class.
71 82
      *  @return a std::shared_ptr of type CubicSplineInterpolator
@@ -149,23 +160,6 @@ class CubicSplineInterpolator : public LemmaObject {
149 160
 
150 161
     protected:
151 162
 
152
-    // ====================  LIFECYCLE     =======================
153
-
154
-    /** Default protected constructor, use New */
155
-    CubicSplineInterpolator ( );
156
-
157
-    /** Protected DeDerializing constructor, use factory DeSerialize  method*/
158
-    CubicSplineInterpolator (const YAML::Node& node);
159
-
160
-    /** Default protected destructor, smart pointers auto delete */
161
-    ~CubicSplineInterpolator ();
162
-
163
-    /**
164
-     *  @copybrief   LemmaObject::Release()
165
-     *  @copydetails LemmaObject::Release()
166
-     */
167
-    void Release();
168
-
169 163
     // ====================  OPERATIONS    =======================
170 164
 
171 165
     /** Finds the interval of knots in spline to use for integration.

+ 1
- 1
Modules/LemmaCore/include/LemmaObject.h Прегледај датотеку

@@ -95,7 +95,7 @@ class LemmaObject {
95 95
          */
96 96
         LemmaObject ( );
97 97
 
98
-        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
98
+        /** Protected DeSerializing constructor */
99 99
         LemmaObject (const YAML::Node& node);
100 100
 
101 101
         /** Protected default destructor. This is an abstract class and

+ 20
- 17
Modules/LemmaCore/src/ASCIIParser.cpp Прегледај датотеку

@@ -35,7 +35,7 @@ namespace Lemma {
35 35
     //      Method:  ASCIIParser
36 36
     // Description:  constructor (protected)
37 37
     //--------------------------------------------------------------------------------------
38
-    ASCIIParser::ASCIIParser ( ) : LemmaObject( ),
38
+    ASCIIParser::ASCIIParser ( const ctor_cookie& ) : LemmaObject( ), input(),
39 39
             CommentString("//"), BufferSize(255) {
40 40
 
41 41
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
@@ -47,9 +47,9 @@ namespace Lemma {
47 47
     // Description:  public smart pointer factory constructor
48 48
     //--------------------------------------------------------------------------------------
49 49
     std::shared_ptr< ASCIIParser > ASCIIParser::NewSP() {
50
-        std::shared_ptr<ASCIIParser> sp(new  ASCIIParser( ), LemmaObjectDeleter() );
51
-        return sp;
52
-        //return  std::make_shared<ASCIIParser>();
50
+        //std::shared_ptr<ASCIIParser> sp(new  ASCIIParser( ), LemmaObjectDeleter() );
51
+        //return sp;
52
+        return  std::make_shared<ASCIIParser>( ctor_cookie() );
53 53
     }
54 54
 
55 55
     //--------------------------------------------------------------------------------------
@@ -68,12 +68,12 @@ namespace Lemma {
68 68
     //       Class:  ASCIIParser
69 69
     //      Method:  DeSerialize
70 70
     //--------------------------------------------------------------------------------------
71
-    std::shared_ptr<ASCIIParser> ASCIIParser::DeSerialize ( const YAML::Node& node  ) {
71
+    std::shared_ptr<ASCIIParser> ASCIIParser::DeSerialize ( const YAML::Node& node ) {
72 72
         if (node.Tag() != "ASCIIParser") {
73 73
             throw  DeSerializeTypeMismatch( "ASCIIParser", node.Tag());
74 74
         }
75
-        std::shared_ptr<ASCIIParser> Object(new  ASCIIParser(node), LemmaObjectDeleter() );
76
-        return Object ;
75
+        //std::shared_ptr<ASCIIParser> Object(new  ASCIIParser(node), LemmaObjectDeleter() );
76
+        return std::make_shared< ASCIIParser >( node, ctor_cookie() );
77 77
     }		// -----  end of method ASCIIParser::DeSerialize  -----
78 78
 
79 79
     //--------------------------------------------------------------------------------------
@@ -85,27 +85,30 @@ namespace Lemma {
85 85
 
86 86
     }  // -----  end of method ASCIIParser::~ASCIIParser  (destructor)  -----
87 87
 
88
+/*
89
+    //--------------------------------------------------------------------------------------
90
+    //       Class:  ASCIIParser
91
+    //      Method:  ASCIIParser(ASCIIParser)
92
+    // Description:  copy
93
+    //--------------------------------------------------------------------------------------
94
+    ASCIIParser::ASCIIParser ( const ASCIIParser& cp ) {
95
+        //input = cp.input; // Problem line
96
+        CommentString = cp.CommentString;
97
+        BufferSize = cp.BufferSize;
98
+    }  // -----  end of method ASCIIParser::~ASCIIParser  (destructor)  -----
99
+*/
88 100
     //--------------------------------------------------------------------------------------
89 101
     //       Class:  ASCIIParser
90 102
     //      Method:  ASCIIParser
91 103
     // Description:  DeSerializing constructor (protected)
92 104
     //--------------------------------------------------------------------------------------
93
-    ASCIIParser::ASCIIParser (const YAML::Node& node) : LemmaObject(node) {
105
+    ASCIIParser::ASCIIParser (const YAML::Node& node, const ctor_cookie& ) : LemmaObject(node) {
94 106
         this->CommentString = node["CommentString"].as<std::string>();
95 107
         this->BufferSize = node["BufferSize"].as<int>();
96 108
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
97 109
 
98 110
     //--------------------------------------------------------------------------------------
99 111
     //       Class:  ASCIIParser
100
-    //      Method:  Release
101
-    // Description:  destructor (protected)
102
-    //--------------------------------------------------------------------------------------
103
-    void ASCIIParser::Release() {
104
-        delete this;
105
-    }
106
-
107
-    //--------------------------------------------------------------------------------------
108
-    //       Class:  ASCIIParser
109 112
     //      Method:  Open
110 113
     //--------------------------------------------------------------------------------------
111 114
     void ASCIIParser::Open ( const std::string& fname ) {

+ 3
- 3
Modules/LemmaCore/src/CMakeLists.txt Прегледај датотеку

@@ -1,14 +1,14 @@
1 1
 set (SOURCE 
2 2
 	${SOURCE}
3 3
 	${CMAKE_CURRENT_SOURCE_DIR}/helper.cpp
4
-	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp
5
-	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp
4
+	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
5
+	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp                # fixed 
6
+	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp    # fixed, cookie 
6 7
 	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp
7 8
 	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp
8 9
 	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp
9 10
 	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp
10 11
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp
11
-	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
12 12
 	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp       
13 13
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp
14 14
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp

+ 8
- 14
Modules/LemmaCore/src/CubicSplineInterpolator.cpp Прегледај датотеку

@@ -40,7 +40,7 @@ namespace Lemma {
40 40
     //      Method:  CubicSplineInterpolator
41 41
     // Description:  constructor (protected)
42 42
     //--------------------------------------------------------------------------------------
43
-    CubicSplineInterpolator::CubicSplineInterpolator ( ) : LemmaObject( ) {
43
+    CubicSplineInterpolator::CubicSplineInterpolator ( const ctor_cookie& ) : LemmaObject( ) {
44 44
 
45 45
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
46 46
 
@@ -49,7 +49,7 @@ namespace Lemma {
49 49
     //      Method:  CubicSplineInterpolator
50 50
     // Description:  DeSerializing constructor (protected)
51 51
     //--------------------------------------------------------------------------------------
52
-    CubicSplineInterpolator::CubicSplineInterpolator (const YAML::Node& node) : LemmaObject(node) {
52
+    CubicSplineInterpolator::CubicSplineInterpolator (const YAML::Node& node, const ctor_cookie& ) : LemmaObject(node) {
53 53
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
54 54
 
55 55
     //--------------------------------------------------------------------------------------
@@ -58,8 +58,9 @@ namespace Lemma {
58 58
     // Description:  public constructor
59 59
     //--------------------------------------------------------------------------------------
60 60
     std::shared_ptr<CubicSplineInterpolator> CubicSplineInterpolator::NewSP() {
61
-        std::shared_ptr<CubicSplineInterpolator> sp(new  CubicSplineInterpolator( ), LemmaObjectDeleter() );
62
-        return sp;
61
+        //std::shared_ptr<CubicSplineInterpolator> sp(new  CubicSplineInterpolator( CubicSplineInterpolator::ctor_cookie ), LemmaObjectDeleter() );
62
+        //return sp;
63
+        return std::make_shared<CubicSplineInterpolator>( ctor_cookie() );
63 64
     }
64 65
 
65 66
     //--------------------------------------------------------------------------------------
@@ -81,8 +82,9 @@ namespace Lemma {
81 82
         if (node.Tag() != "CubicSplineInterpolator") {
82 83
             throw  DeSerializeTypeMismatch( "CubicSplineInterpolator", node.Tag());
83 84
         }
84
-        std::shared_ptr<CubicSplineInterpolator> Object(new  CubicSplineInterpolator(node), LemmaObjectDeleter() );
85
-        return Object ;
85
+        //std::shared_ptr<CubicSplineInterpolator> Object(new  CubicSplineInterpolator(node), LemmaObjectDeleter() );
86
+        //return Object ;
87
+        return std::make_shared<CubicSplineInterpolator>( node, ctor_cookie() );
86 88
     }
87 89
 
88 90
     //--------------------------------------------------------------------------------------
@@ -94,14 +96,6 @@ namespace Lemma {
94 96
 
95 97
     }  // -----  end of method CubicSplineInterpolator::~CubicSplineInterpolator  (destructor)  -----
96 98
 
97
-    //--------------------------------------------------------------------------------------
98
-    //       Class:  CubicSplineInterpolator
99
-    //      Method:  Release
100
-    // Description:  destructor (protected)
101
-    //--------------------------------------------------------------------------------------
102
-    void CubicSplineInterpolator::Release() {
103
-        delete this;
104
-    }
105 99
 
106 100
     // ====================  OPERATIONS    =======================
107 101
 

Loading…
Откажи
Сачувај