Browse Source

Deciding on design changes wrt. allowing stack allocation?

enhancement_3
T-bone 8 years ago
parent
commit
9ef7370e73

+ 4
- 0
Modules/LemmaCore/examples/CMakeLists.txt View File

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

+ 36
- 0
Modules/LemmaCore/examples/CubicSplineInterpolator.cpp View File

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 View File

34
     friend std::ostream &operator<<(std::ostream &stream,
34
     friend std::ostream &operator<<(std::ostream &stream,
35
             const ASCIIParser &ob);
35
             const ASCIIParser &ob);
36
 
36
 
37
+    struct ctor_cookie {};
38
+
37
     public:
39
     public:
38
 
40
 
39
     // ====================  LIFECYCLE     =======================
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
      *  Factory method for generating concrete class.
53
      *  Factory method for generating concrete class.
43
      *  @return a std::shared_ptr of type ASCIIParser
54
      *  @return a std::shared_ptr of type ASCIIParser
121
 
132
 
122
     protected:
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
     private:
138
     private:
142
 
139
 

+ 11
- 17
Modules/LemmaCore/include/CubicSplineInterpolator.h View File

62
     friend std::ostream &operator<<(std::ostream &stream,
62
     friend std::ostream &operator<<(std::ostream &stream,
63
             const CubicSplineInterpolator &ob);
63
             const CubicSplineInterpolator &ob);
64
 
64
 
65
+    struct ctor_cookie {};
66
+
65
     public:
67
     public:
66
 
68
 
67
     // ====================  LIFECYCLE     =======================
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
      *  Factory method for generating concrete class.
81
      *  Factory method for generating concrete class.
71
      *  @return a std::shared_ptr of type CubicSplineInterpolator
82
      *  @return a std::shared_ptr of type CubicSplineInterpolator
149
 
160
 
150
     protected:
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
     // ====================  OPERATIONS    =======================
163
     // ====================  OPERATIONS    =======================
170
 
164
 
171
     /** Finds the interval of knots in spline to use for integration.
165
     /** Finds the interval of knots in spline to use for integration.

+ 1
- 1
Modules/LemmaCore/include/LemmaObject.h View File

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

+ 20
- 17
Modules/LemmaCore/src/ASCIIParser.cpp View File

35
     //      Method:  ASCIIParser
35
     //      Method:  ASCIIParser
36
     // Description:  constructor (protected)
36
     // Description:  constructor (protected)
37
     //--------------------------------------------------------------------------------------
37
     //--------------------------------------------------------------------------------------
38
-    ASCIIParser::ASCIIParser ( ) : LemmaObject( ),
38
+    ASCIIParser::ASCIIParser ( const ctor_cookie& ) : LemmaObject( ), input(),
39
             CommentString("//"), BufferSize(255) {
39
             CommentString("//"), BufferSize(255) {
40
 
40
 
41
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
41
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
47
     // Description:  public smart pointer factory constructor
47
     // Description:  public smart pointer factory constructor
48
     //--------------------------------------------------------------------------------------
48
     //--------------------------------------------------------------------------------------
49
     std::shared_ptr< ASCIIParser > ASCIIParser::NewSP() {
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
     //       Class:  ASCIIParser
68
     //       Class:  ASCIIParser
69
     //      Method:  DeSerialize
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
         if (node.Tag() != "ASCIIParser") {
72
         if (node.Tag() != "ASCIIParser") {
73
             throw  DeSerializeTypeMismatch( "ASCIIParser", node.Tag());
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
     }		// -----  end of method ASCIIParser::DeSerialize  -----
77
     }		// -----  end of method ASCIIParser::DeSerialize  -----
78
 
78
 
79
     //--------------------------------------------------------------------------------------
79
     //--------------------------------------------------------------------------------------
85
 
85
 
86
     }  // -----  end of method ASCIIParser::~ASCIIParser  (destructor)  -----
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
     //       Class:  ASCIIParser
101
     //       Class:  ASCIIParser
90
     //      Method:  ASCIIParser
102
     //      Method:  ASCIIParser
91
     // Description:  DeSerializing constructor (protected)
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
         this->CommentString = node["CommentString"].as<std::string>();
106
         this->CommentString = node["CommentString"].as<std::string>();
95
         this->BufferSize = node["BufferSize"].as<int>();
107
         this->BufferSize = node["BufferSize"].as<int>();
96
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
108
     }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
97
 
109
 
98
     //--------------------------------------------------------------------------------------
110
     //--------------------------------------------------------------------------------------
99
     //       Class:  ASCIIParser
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
     //      Method:  Open
112
     //      Method:  Open
110
     //--------------------------------------------------------------------------------------
113
     //--------------------------------------------------------------------------------------
111
     void ASCIIParser::Open ( const std::string& fname ) {
114
     void ASCIIParser::Open ( const std::string& fname ) {

+ 3
- 3
Modules/LemmaCore/src/CMakeLists.txt View File

1
 set (SOURCE 
1
 set (SOURCE 
2
 	${SOURCE}
2
 	${SOURCE}
3
 	${CMAKE_CURRENT_SOURCE_DIR}/helper.cpp
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
 	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp
7
 	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp
7
 	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp
8
 	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp
8
 	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp
9
 	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp
9
 	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp
10
 	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp
10
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp
11
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp
11
-	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
12
 	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp       
12
 	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp       
13
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp
13
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp
14
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp
14
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp

+ 8
- 14
Modules/LemmaCore/src/CubicSplineInterpolator.cpp View File

40
     //      Method:  CubicSplineInterpolator
40
     //      Method:  CubicSplineInterpolator
41
     // Description:  constructor (protected)
41
     // Description:  constructor (protected)
42
     //--------------------------------------------------------------------------------------
42
     //--------------------------------------------------------------------------------------
43
-    CubicSplineInterpolator::CubicSplineInterpolator ( ) : LemmaObject( ) {
43
+    CubicSplineInterpolator::CubicSplineInterpolator ( const ctor_cookie& ) : LemmaObject( ) {
44
 
44
 
45
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
45
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
46
 
46
 
49
     //      Method:  CubicSplineInterpolator
49
     //      Method:  CubicSplineInterpolator
50
     // Description:  DeSerializing constructor (protected)
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
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
53
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
54
 
54
 
55
     //--------------------------------------------------------------------------------------
55
     //--------------------------------------------------------------------------------------
58
     // Description:  public constructor
58
     // Description:  public constructor
59
     //--------------------------------------------------------------------------------------
59
     //--------------------------------------------------------------------------------------
60
     std::shared_ptr<CubicSplineInterpolator> CubicSplineInterpolator::NewSP() {
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
         if (node.Tag() != "CubicSplineInterpolator") {
82
         if (node.Tag() != "CubicSplineInterpolator") {
82
             throw  DeSerializeTypeMismatch( "CubicSplineInterpolator", node.Tag());
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
 
96
 
95
     }  // -----  end of method CubicSplineInterpolator::~CubicSplineInterpolator  (destructor)  -----
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
     // ====================  OPERATIONS    =======================
100
     // ====================  OPERATIONS    =======================
107
 
101
 

Loading…
Cancel
Save