ソースを参照

More cleaning up towards the port to c++-11. Documentation and consistency and better testing.

enhancement_3
Trevor Irons 8年前
コミット
f1ad8f2f9e

+ 4
- 3
Modules/LemmaCore/examples/CubicSplineInterpolator.cpp ファイルの表示

@@ -17,14 +17,15 @@
17 17
  * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
18 18
  */
19 19
 
20
-#include "CubicSplineInterpolator.h"
21
-#include "ASCIIParser.h"
20
+#include "LemmaCore"
22 21
 using namespace Lemma;
23 22
 
24 23
 int main() {
24
+    auto win = WindowFilter::NewSP();
25
+        std::cout << *win << std::endl;
25 26
     //auto Spline = CubicSplineInterpolator::NewSP();
26 27
     //auto Spline2 = CubicSplineInterpolator();
27
-    auto Parser = ASCIIParser::NewSP();
28
+    //auto Parser = ASCIIParser::NewSP();
28 29
     //ASCIIParser Parser2 = ASCIIParser();
29 30
     //    Parser2.SetCommentString( "#");
30 31
     //auto Parser3 = ASCIIParser(Parser2);

+ 20
- 6
Modules/LemmaCore/include/ASCIIParser.h ファイルの表示

@@ -33,20 +33,34 @@ class ASCIIParser : public LemmaObject {
33 33
 
34 34
     friend std::ostream &operator<<(std::ostream &stream,
35 35
             const ASCIIParser &ob);
36
-
36
+    /*
37
+     *  This key is used to lock the constructors
38
+     */
37 39
     struct ctor_key {};
38 40
 
39 41
     public:
40 42
 
41 43
     // ====================  LIFECYCLE     =======================
42 44
 
43
-    /** Default constructor */
45
+    /** Default constructor
46
+     * @note This method is locked
47
+     * @see ASCIIParser::NewSP
48
+     */
44 49
     explicit ASCIIParser ( const ctor_key& );
45 50
 
46
-    /** Constructor using YAML::Node */
51
+    /**
52
+     * DeSerializing constructor.
53
+     * @note This method is locked, and cannot be called directly.
54
+     *       The reason that the method is public is to enable the use
55
+     *       of make_shared whilst enforcing the use of shared_ptr,
56
+     *       in c++-17, this curiosity may be resolved.
57
+     * @see ASCIIParser::DeSerialize
58
+     */
47 59
     ASCIIParser ( const YAML::Node& node, const ctor_key& );
48 60
 
49
-    /** Default  destructor */
61
+    /** Default  destructor
62
+     *  @note This should never be called explicitly, use NewSP
63
+     */
50 64
     virtual ~ASCIIParser ();
51 65
 
52 66
     /**
@@ -65,7 +79,7 @@ class ASCIIParser : public LemmaObject {
65 79
      *  Uses YAML to serialize this object.
66 80
      *  @return a YAML::Node
67 81
      */
68
-    YAML::Node Serialize() const;
82
+    virtual YAML::Node Serialize() const;
69 83
 
70 84
     // ====================  OPERATORS     =======================
71 85
 
@@ -112,7 +126,7 @@ class ASCIIParser : public LemmaObject {
112 126
      */
113 127
     void SetCommentString( const std::string& key );
114 128
 
115
-    /** Sets the buffer size. This affects the maximum number of column in a line. Defaults
129
+    /** Sets the buffer size. This affects the maximum number of columns in a line. Defaults
116 130
      *  is 255.
117 131
      *  @param[in] BufferSize is the size of the buffer to use
118 132
      */

+ 2
- 2
Modules/LemmaCore/include/CubicSplineInterpolator.h ファイルの表示

@@ -60,7 +60,7 @@ struct SplineSet{
60 60
 class CubicSplineInterpolator : public LemmaObject {
61 61
 
62 62
     friend std::ostream &operator<<(std::ostream &stream,
63
-            const CubicSplineInterpolator &ob);
63
+            const CubicSplineInterpolator& ob);
64 64
 
65 65
     struct ctor_key {};
66 66
 
@@ -87,7 +87,7 @@ class CubicSplineInterpolator : public LemmaObject {
87 87
      *  Uses YAML to serialize this object.
88 88
      *  @return a YAML::Node
89 89
      */
90
-    YAML::Node Serialize() const;
90
+    virtual YAML::Node Serialize() const;
91 91
 
92 92
     /**
93 93
      *   Constructs an object from a YAML::Node.

+ 9
- 6
Modules/LemmaCore/include/Data.h ファイルの表示

@@ -36,12 +36,10 @@ namespace Lemma {
36 36
 
37 37
             // ====================  LIFECYCLE     =======================
38 38
 
39
-            /** Copies the *structure* of this class to a new object and
40
-             * returns a pointer to this object. Memory management is
41
-             * the responsibility of the receiver!. The data values are
42
-             * not copied.
39
+            /**
40
+             * Returns a deep copy
43 41
              */
44
-            virtual Data* Clone()=0;
42
+            virtual std::shared_ptr<Data> DeepCopy()=0;
45 43
 
46 44
             // ====================  OPERATORS     =======================
47 45
 
@@ -74,8 +72,11 @@ namespace Lemma {
74 72
             /** Default protected constructor. */
75 73
             Data (  );
76 74
 
75
+            /** Deserializing contructor */
76
+            Data ( const YAML::Node& node );
77
+
77 78
             /** Default protected constructor. */
78
-            ~Data ();
79
+            ~Data ( );
79 80
 
80 81
             // ====================  DATA MEMBERS  =========================
81 82
 
@@ -84,6 +85,8 @@ namespace Lemma {
84 85
             /** ASCII string representation of the class name */
85 86
             static constexpr auto CName = "Data";
86 87
 
88
+            Data ( const Data& ) = delete;
89
+
87 90
     }; // -----  end of class  Data  -----
88 91
 
89 92
 }       // -----  end of Lemma  name  -----

+ 6
- 1
Modules/LemmaCore/include/DataReader.h ファイルの表示

@@ -40,7 +40,7 @@ class DataReader : public LemmaObject {
40 40
         // ====================  OPERATIONS    =======================
41 41
 
42 42
         // ====================  ACCESS        =======================
43
-        virtual Data* GetData()=0;
43
+        virtual std::shared_ptr< Data > GetData()=0;
44 44
 
45 45
         // ====================  INQUIRY       =======================
46 46
         /** Returns the name of the underlying class, similiar to Python's type */
@@ -56,6 +56,9 @@ class DataReader : public LemmaObject {
56 56
         DataReader ( );
57 57
 
58 58
         /// Default protected constructor.
59
+        DataReader ( const YAML::Node& node );
60
+
61
+        /// Default protected constructor.
59 62
         ~DataReader ( );
60 63
 
61 64
         // ====================  DATA MEMBERS  =========================
@@ -65,6 +68,8 @@ class DataReader : public LemmaObject {
65 68
         /** ASCII string representation of the class name */
66 69
         static constexpr auto CName = "DataReader";
67 70
 
71
+        DataReader( const DataReader& ) = delete;
72
+
68 73
 }; // -----  end of class  DataReader  -----
69 74
 
70 75
 }       // -----  end of Lemma  name  -----

+ 3
- 1
Modules/LemmaCore/include/EarthModel.h ファイルの表示

@@ -20,7 +20,7 @@ namespace Lemma {
20 20
 
21 21
     // ===================================================================
22 22
     //        Class:  EarthModel
23
-    /// \ingroup LemmaGroup
23
+    /// \ingroup LemmaCore
24 24
     /// \brief abstract class for Earth models
25 25
     /// \details
26 26
     // ===================================================================
@@ -113,6 +113,8 @@ namespace Lemma {
113 113
 
114 114
         private:
115 115
 
116
+            EarthModel(const EarthModel& ) = delete;
117
+
116 118
             /** ASCII string representation of the class name */
117 119
             static constexpr auto CName = "EarthModel";
118 120
 

+ 12
- 1
Modules/LemmaCore/include/Filter.h ファイルの表示

@@ -28,14 +28,22 @@ namespace Lemma {
28 28
 
29 29
     class Filter : public LemmaObject {
30 30
 
31
+        friend std::ostream &operator<<(std::ostream &stream, const Filter& ob);
32
+
31 33
         public:
32 34
 
33 35
             // ====================  LIFECYCLE     =======================
36
+            /**
37
+             *  Uses YAML to serialize this object.
38
+             *  @return a YAML::Node
39
+             */
40
+            virtual YAML::Node Serialize() const;
34 41
 
35 42
             // ====================  OPERATORS     =======================
36 43
 
37 44
             // ====================  OPERATIONS    =======================
38 45
 
46
+
39 47
             // ====================  ACCESS        =======================
40 48
 
41 49
             // ====================  INQUIRY       =======================
@@ -53,7 +61,10 @@ namespace Lemma {
53 61
             Filter ( );
54 62
 
55 63
             /// Default protected constructor.
56
-            ~Filter ();
64
+            Filter ( const YAML::Node& node );
65
+
66
+            /// Default protected constructor.
67
+            virtual ~Filter ();
57 68
 
58 69
             // ====================  DATA MEMBERS  =========================
59 70
 

+ 2
- 2
Modules/LemmaCore/include/Grid.h ファイルの表示

@@ -35,7 +35,7 @@ class Grid : public LemmaObject {
35 35
 
36 36
         // ====================  LIFECYCLE     ===================================
37 37
 
38
-        YAML::Node Serialize() const;
38
+        virtual YAML::Node Serialize() const;
39 39
 
40 40
         // ====================  OPERATORS     ===================================
41 41
 
@@ -61,7 +61,7 @@ class Grid : public LemmaObject {
61 61
         Grid ( );
62 62
 
63 63
         /// Default protected constructor.
64
-        ~Grid ();
64
+        virtual ~Grid ( );
65 65
 
66 66
         // ====================  DATA MEMBERS  ===================================
67 67
 

+ 9
- 0
Modules/LemmaCore/include/Instrument.h ファイルの表示

@@ -33,6 +33,12 @@ namespace Lemma {
33 33
 
34 34
 			// ====================  LIFECYCLE     ===========================
35 35
 
36
+            /**
37
+             *  Uses YAML to serialize this object.
38
+             *  @return a YAML::Node
39
+             */
40
+            YAML::Node Serialize() const;
41
+
36 42
 			// ====================  OPERATORS     ===========================
37 43
 
38 44
 			// ====================  OPERATIONS    ===========================
@@ -53,6 +59,9 @@ namespace Lemma {
53 59
 
54 60
 			// ====================  LIFECYCLE     ===========================
55 61
 
62
+            /// Default protected constructor.
63
+			Instrument ( const YAML::Node& node );
64
+
56 65
 			/// Default protected constructor.
57 66
 			Instrument ( );
58 67
 

+ 4
- 1
Modules/LemmaCore/include/LayeredEarth.h ファイルの表示

@@ -86,7 +86,6 @@ namespace Lemma {
86 86
             /** YAML Serializing method
87 87
              */
88 88
             YAML::Node Serialize() const;
89
-            //static LayeredEarth* DeSerialize(const YAML::Node& node);
90 89
 
91 90
             /** Returns the name of the underlying class, similiar to Python's type */
92 91
             virtual inline std::string GetName() const {
@@ -109,9 +108,13 @@ namespace Lemma {
109 108
 			// ====================  DATA MEMBERS  ===========================
110 109
 
111 110
         private:
111
+
112 112
             /** ASCII string representation of the class name */
113 113
             static constexpr auto CName = "LayeredEarth";
114 114
 
115
+            /** no copy */
116
+            LayeredEarth ( const LayeredEarth& ) = delete;
117
+
115 118
 			/** Number of layers in the model, including the air layer,
116 119
 			 * and counting from 0
117 120
              */

+ 17
- 18
Modules/LemmaCore/include/LemmaObject.h ファイルの表示

@@ -44,28 +44,11 @@ class LemmaObject {
44 44
     friend class LemmaObjectDeleter;
45 45
 
46 46
     public:
47
-
48
-        // ====================  LIFECYCLE     ==============================
49
-
50 47
         // Needed because many derived classes have Eigen vectors as members,
51 48
         // causing alignment issues when vectorisation is enabled.
52 49
         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53 50
 
54
-        // ====================  OPERATORS     ==============================
55
-
56
-        // ====================  OPERATIONS    ==============================
57
-
58
-        // ====================  ACCESS        ==============================
59
-
60
-        // ====================  INQUIRY       ==============================
61
-
62
-        /** Returns the name of the underlying class; Run-time type information (RTTI). This approach
63
-            Was chosen over typeid due to name mangling among various compilers, and the need for consistency
64
-            in Serialized objects.
65
-         */
66
-        virtual inline std::string GetName() const {
67
-            return this->CName;
68
-        }
51
+        // ====================  LIFECYCLE     ==============================
69 52
 
70 53
         /**
71 54
          *  Uses YAML to serialize this object.
@@ -86,6 +69,22 @@ class LemmaObject {
86 69
             return node;
87 70
         };
88 71
 
72
+        // ====================  OPERATORS     ==============================
73
+
74
+        // ====================  OPERATIONS    ==============================
75
+
76
+        // ====================  ACCESS        ==============================
77
+
78
+        // ====================  INQUIRY       ==============================
79
+
80
+        /** Returns the name of the underlying class; Run-time type information (RTTI). This approach
81
+            Was chosen over typeid due to name mangling among various compilers, and the need for consistency
82
+            in Serialized objects.
83
+         */
84
+        virtual inline std::string GetName() const {
85
+            return this->CName;
86
+        }
87
+
89 88
     protected:
90 89
 
91 90
         // ====================  LIFECYCLE     ==============================

+ 1
- 1
Modules/LemmaCore/include/RectilinearGrid.h ファイルの表示

@@ -50,7 +50,7 @@ namespace Lemma {
50 50
              *  Uses YAML to serialize this object.
51 51
              *  @return a YAML::Node
52 52
              */
53
-            YAML::Node Serialize() const;
53
+            virtual YAML::Node Serialize() const;
54 54
 
55 55
             /**
56 56
              *   Constructs an object from a YAML::Node.

+ 32
- 18
Modules/LemmaCore/include/WindowFilter.h ファイルの表示

@@ -16,12 +16,6 @@
16 16
 #include "Filter.h"
17 17
 
18 18
 namespace Lemma {
19
-    /** Types of filter window that are supported.
20
-     */
21
-    enum WINDOWTYPE { HAMMING, /*!< A hamming window */
22
-                      HANNING, /*!< A hanning window */
23
-                      RECTANGULAR /*!< Rectangular window */
24
-                    };
25 19
 
26 20
     // ===================================================================
27 21
     //  Class:  WindowFilter
@@ -34,14 +28,38 @@ namespace Lemma {
34 28
     // ===================================================================
35 29
     class WindowFilter : public Filter {
36 30
 
31
+        friend std::ostream &operator<<(std::ostream &stream, const WindowFilter& ob);
32
+
33
+        struct ctor_key {};
34
+
37 35
         public:
38 36
 
39 37
             // ====================  LIFECYCLE     =======================
40 38
 
41
-           /**
42
-            *  Factory method for generating concrete class.
43
-            *  @return a std::shared_ptr of type WindowFilter
44
-            */
39
+            /** Default constructor, inaccessible use NewSP  */
40
+            explicit WindowFilter ( const ctor_key& );
41
+
42
+            /** DeSerializing constructor, usees factory DeSerialize  method, inaccessible use DeSerialize*/
43
+            WindowFilter ( const YAML::Node& node, const ctor_key& );
44
+
45
+            /** Default constructor. */
46
+            virtual ~WindowFilter ( );
47
+
48
+            /**
49
+             *  Uses YAML to serialize this object.
50
+             *  @return a YAML::Node
51
+             */
52
+            YAML::Node Serialize() const;
53
+
54
+            /**
55
+             *   Constructs an object from a YAML::Node.
56
+             */
57
+            static std::shared_ptr< WindowFilter > DeSerialize(const YAML::Node& node);
58
+
59
+            /**
60
+             *  Factory method for generating concrete class.
61
+             *  @return a std::shared_ptr of type WindowFilter
62
+             */
45 63
             static std::shared_ptr< WindowFilter > NewSP();
46 64
 
47 65
             // ====================  OPERATORS     =======================
@@ -86,12 +104,8 @@ namespace Lemma {
86 104
 
87 105
             // ====================  LIFECYCLE     =======================
88 106
 
89
-            /// Default protected constructor.
90
-            WindowFilter ( );
91
-
92
-            /// Default protected constructor.
93
-            ~WindowFilter ( );
94 107
 
108
+        private:
95 109
             // ====================  DATA MEMBERS  =========================
96 110
 
97 111
             /// Width of the window
@@ -115,10 +129,10 @@ namespace Lemma {
115 129
             /// The type of filter to use
116 130
             WINDOWTYPE  Type;
117 131
 
118
-        private:
132
+            /** ASCII string representation of the class name */
133
+            static constexpr auto CName = "WindowFilter";
119 134
 
120
-        /** ASCII string representation of the class name */
121
-        static constexpr auto CName = "WindowFilter";
135
+            WindowFilter ( const WindowFilter& ) = delete;
122 136
 
123 137
     }; // -----  end of class  WindowFilter  -----
124 138
 

+ 2
- 0
Modules/LemmaCore/include/helper.h ファイルの表示

@@ -61,6 +61,8 @@ namespace Lemma {
61 61
     std::string enum2String(const HANKELTRANSFORMTYPE& Htype);
62 62
     /// convert enums to string saves repeated code useful for YAML serializing
63 63
     std::string enum2String(const FIELDCALCULATIONS& Htype);
64
+    /// convert enums to string saves repeated code useful for YAML serializing
65
+    std::string enum2String(const WINDOWTYPE& Wtype);
64 66
 
65 67
     // other way around is a template, where template argument lets us know
66 68
     // which specialisation to use.

+ 8
- 0
Modules/LemmaCore/include/lemma.h ファイルの表示

@@ -317,6 +317,14 @@
317 317
         */
318 318
         enum FIELDCALCULATIONS {E, H, BOTH};
319 319
 
320
+        /** Windowing function type
321
+         */
322
+        enum WINDOWTYPE { HAMMING, /*!< A hamming window */
323
+                          HANNING, /*!< A hanning window */
324
+                          RECTANGULAR /*!< Rectangular window */
325
+        };
326
+
327
+
320 328
     }
321 329
 
322 330
 #endif // __Lemma_H

+ 8
- 8
Modules/LemmaCore/src/CMakeLists.txt ファイルの表示

@@ -4,16 +4,16 @@ set (SOURCE
4 4
 	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
5 5
 	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp                # fixed, key 
6 6
 	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp    # fixed, key 
7
-	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp
8
-	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp
9
-	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp
10
-	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp
11
-	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp
12
-	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp       
7
+	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp                       # ABC, no key 
13 8
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp
14 9
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp
15 10
 	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridVTKExporter.cpp
16
-	${CMAKE_CURRENT_SOURCE_DIR}/Filter.cpp
17
-	${CMAKE_CURRENT_SOURCE_DIR}/WindowFilter.cpp
11
+	${CMAKE_CURRENT_SOURCE_DIR}/Filter.cpp                     # ABC, no key
12
+	${CMAKE_CURRENT_SOURCE_DIR}/WindowFilter.cpp			   # fixed, key
13
+	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp                 # ABC, no key
14
+	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp			   # ABC, no key
15
+	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp                       # ABC, no key
16
+	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp                 # ABC, no key
17
+	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp                 # ABC, no key
18 18
 	PARENT_SCOPE
19 19
 )

+ 2
- 6
Modules/LemmaCore/src/CubicSplineInterpolator.cpp ファイルの表示

@@ -38,7 +38,7 @@ namespace Lemma {
38 38
     //--------------------------------------------------------------------------------------
39 39
     //       Class:  CubicSplineInterpolator
40 40
     //      Method:  CubicSplineInterpolator
41
-    // Description:  constructor (protected)
41
+    // Description:  constructor (locked with ctor_key)
42 42
     //--------------------------------------------------------------------------------------
43 43
     CubicSplineInterpolator::CubicSplineInterpolator ( const ctor_key& ) : LemmaObject( ) {
44 44
 
@@ -47,7 +47,7 @@ namespace Lemma {
47 47
     //--------------------------------------------------------------------------------------
48 48
     //       Class:  CubicSplineInterpolator
49 49
     //      Method:  CubicSplineInterpolator
50
-    // Description:  DeSerializing constructor (protected)
50
+    // Description:  DeSerializing constructor (locked with ctor_key)
51 51
     //--------------------------------------------------------------------------------------
52 52
     CubicSplineInterpolator::CubicSplineInterpolator (const YAML::Node& node, const ctor_key& ) : LemmaObject(node) {
53 53
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
@@ -58,8 +58,6 @@ 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( CubicSplineInterpolator::ctor_key ), LemmaObjectDeleter() );
62
-        //return sp;
63 61
         return std::make_shared<CubicSplineInterpolator>( ctor_key() );
64 62
     }
65 63
 
@@ -82,8 +80,6 @@ namespace Lemma {
82 80
         if (node.Tag() != "CubicSplineInterpolator") {
83 81
             throw  DeSerializeTypeMismatch( "CubicSplineInterpolator", node.Tag());
84 82
         }
85
-        //std::shared_ptr<CubicSplineInterpolator> Object(new  CubicSplineInterpolator(node), LemmaObjectDeleter() );
86
-        //return Object ;
87 83
         return std::make_shared<CubicSplineInterpolator>( node, ctor_key() );
88 84
     }
89 85
 

+ 3
- 0
Modules/LemmaCore/src/Data.cpp ファイルの表示

@@ -23,6 +23,9 @@ namespace Lemma {
23 23
 	Data::Data(  ) : LemmaObject( ) {
24 24
 	}
25 25
 
26
+    Data::Data( const YAML::Node& node ) : LemmaObject( node ) {
27
+	}
28
+
26 29
 
27 30
 	Data::~Data() {
28 31
 	}

+ 6
- 0
Modules/LemmaCore/src/DataReader.cpp ファイルの表示

@@ -21,9 +21,15 @@ namespace Lemma {
21 21
     }
22 22
 
23 23
 	DataReader::DataReader( ) : LemmaObject( ) {
24
+
25
+	}
26
+
27
+    DataReader::DataReader( const YAML::Node& node ) : LemmaObject( node ) {
28
+
24 29
 	}
25 30
 
26 31
 	DataReader::~DataReader() {
32
+
27 33
 	}
28 34
 
29 35
 }		// -----  end of Lemma  name  -----

+ 33
- 0
Modules/LemmaCore/src/Filter.cpp ファイルの表示

@@ -15,8 +15,41 @@
15 15
 
16 16
 namespace Lemma {
17 17
 
18
+    std::ostream &operator << (std::ostream &stream, const Filter &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+    //--------------------------------------------------------------------------------------
24
+    //       Class:  Filter
25
+    //      Method:  Filter
26
+    // Description:  constructor (protected)
27
+    //--------------------------------------------------------------------------------------
18 28
     Filter::Filter( ) : LemmaObject( ) { }
19 29
 
30
+    //--------------------------------------------------------------------------------------
31
+    //       Class:  Filter
32
+    //      Method:  ~Filter
33
+    // Description:  destructor (protected)
34
+    //--------------------------------------------------------------------------------------
20 35
     Filter::~Filter( ) { }
21 36
 
37
+    //--------------------------------------------------------------------------------------
38
+    //       Class:  Filter
39
+    //      Method:  Filter
40
+    // Description:  DeSerializing constructor (protected)
41
+    //--------------------------------------------------------------------------------------
42
+    Filter::Filter ( const YAML::Node& node ) : LemmaObject(node) {
43
+    }
44
+
45
+    //--------------------------------------------------------------------------------------
46
+    //       Class:  Filter
47
+    //      Method:  Serialize
48
+    //--------------------------------------------------------------------------------------
49
+    YAML::Node  Filter::Serialize (  ) const {
50
+        YAML::Node node = LemmaObject::Serialize();;
51
+        node.SetTag( GetName() );
52
+        // FILL IN CLASS SPECIFICS HERE
53
+        return node;
54
+    }		// -----  end of method Filter::Serialize  -----
22 55
 }		// -----  end of Lemma  name  -----

+ 0
- 2
Modules/LemmaCore/src/Grid.cpp ファイルの表示

@@ -33,11 +33,9 @@ namespace Lemma {
33 33
 	}
34 34
 
35 35
     YAML::Node Grid::Serialize() const {
36
-
37 36
         YAML::Node node = LemmaObject::Serialize();
38 37
         node.SetTag( this->GetName() );
39 38
         return node;
40
-
41 39
     }
42 40
 
43 41
 }

+ 15
- 0
Modules/LemmaCore/src/Instrument.cpp ファイルの表示

@@ -23,7 +23,22 @@ namespace Lemma {
23 23
 	Instrument::Instrument( ) : LemmaObject() {
24 24
 	}
25 25
 
26
+    Instrument::Instrument( const YAML::Node& node ) : LemmaObject( node ) {
27
+	    // Fill in class specifics
28
+    }
29
+
26 30
 	Instrument::~Instrument() {
27 31
 	}
28 32
 
33
+    //--------------------------------------------------------------------------------------
34
+    //       Class:  Instrument
35
+    //      Method:  Serialize
36
+    //--------------------------------------------------------------------------------------
37
+    YAML::Node  Instrument::Serialize (  ) const {
38
+        YAML::Node node = LemmaObject::Serialize();;
39
+        node.SetTag( GetName() );
40
+        // Fill in class specifics
41
+        return node;
42
+    }		// -----  end of method Instrument::Serialize  -----
43
+
29 44
 }		// -----  end of Lemma  name  -----

+ 1
- 2
Modules/LemmaCore/src/LayeredEarth.cpp ファイルの表示

@@ -33,8 +33,7 @@ namespace Lemma {
33 33
 	LayeredEarth::~LayeredEarth() {
34 34
 	}
35 35
 
36
-    LayeredEarth::LayeredEarth(const YAML::Node& node) : EarthModel(node)
37
-    {
36
+    LayeredEarth::LayeredEarth(const YAML::Node& node) : EarthModel(node) {
38 37
         NumberOfLayers = node["NumberOfLayers"].as<int>();
39 38
         NumberOfInterfaces = node["NumberOfInterfaces"].as<int>();
40 39
         LayerThickness = node["LayerThickness"].as<VectorXr>();

+ 73
- 6
Modules/LemmaCore/src/WindowFilter.cpp ファイルの表示

@@ -15,20 +15,87 @@
15 15
 
16 16
 namespace Lemma {
17 17
 
18
-    // ====================  LIFECYCLE     =======================
18
+    // ====================  FRIEND METHODS  =====================
19
+
20
+    std::ostream &operator << (std::ostream &stream, const WindowFilter &ob) {
21
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
22
+        return stream;
23
+    }
19 24
 
20
-    WindowFilter::WindowFilter( ) : Filter( ),
21
-        Width(0), SamplingRate(0), Bandwidth(0), Coefficients(),
22
-        Type(RECTANGULAR) {}
25
+    // ====================  LIFECYCLE     =======================
23 26
 
27
+    //--------------------------------------------------------------------------------------
28
+    //       Class:  WindowFilter
29
+    //      Method:  WindowFilter
30
+    // Description:  constructor (locked with ctor_key)
31
+    //--------------------------------------------------------------------------------------
32
+    WindowFilter::WindowFilter( const ctor_key& ) : Filter( ),
33
+        Width(0), SamplingRate(0), Bandwidth(0), Coefficients(), Type(RECTANGULAR)
34
+    {
35
+    }   // -----  end of method WindowFilter::WindowFilter  (constructor)  -----
36
+
37
+    //--------------------------------------------------------------------------------------
38
+    //       Class:  WindowFilter
39
+    //      Method:  WindowFilter
40
+    // Description:  DeSerializing constructor (locked with ctor_key)
41
+    //--------------------------------------------------------------------------------------
42
+    WindowFilter::WindowFilter( const YAML::Node& node, const ctor_key& ) : Filter( node ),
43
+        Width(0), SamplingRate(0), Bandwidth(0), Coefficients(), Type(RECTANGULAR)
44
+    {
45
+        Width = node["Width"].as<int>( );
46
+        Nt = node["Nt"].as<int>( );
47
+        Nw = node["Nw"].as<int>( );
48
+        SamplingRate = node["SamplingRate"].as<Real>();
49
+        Bandwidth = node["Bandwidth"].as<Real>();
50
+        Coefficients = node["Coefficients"].as<VectorXr>();
51
+        Type = string2Enum<WINDOWTYPE>( node["WINDOWTYPE"].as<std::string>() );
52
+    } // -----  end of method WindowFilter::WindowFilter  (constructor)  -----
53
+
54
+    //--------------------------------------------------------------------------------------
55
+    //       Class:  WindowFilter
56
+    //      Method:  NewSP()
57
+    // Description:  public constructor
58
+    //--------------------------------------------------------------------------------------
24 59
     std::shared_ptr< WindowFilter > WindowFilter::NewSP() {
25
-        std::shared_ptr<WindowFilter> sp(new  WindowFilter( ), LemmaObjectDeleter() );
26
-        return sp;
60
+        return std::make_shared< WindowFilter >( ctor_key() );
27 61
     }
28 62
 
63
+    //--------------------------------------------------------------------------------------
64
+    //       Class:  WindowFilter
65
+    //      Method:  ~WindowFilter
66
+    // Description:  destructor (protected)
67
+    //--------------------------------------------------------------------------------------
29 68
     WindowFilter::~WindowFilter() {
30 69
     }
31 70
 
71
+    //--------------------------------------------------------------------------------------
72
+    //       Class:  WindowFilter
73
+    //      Method:  Serialize
74
+    //--------------------------------------------------------------------------------------
75
+    YAML::Node  WindowFilter::Serialize (  ) const {
76
+        YAML::Node node = Filter::Serialize();;
77
+        node.SetTag( GetName() );
78
+        // FILL IN CLASS SPECIFICS HERE
79
+        node["Width"] = Width;
80
+        node["Nt"] = Nt;
81
+        node["Nw"] = Nw;
82
+        node["SamplingRate"] = SamplingRate;
83
+        node["Bandwidth"] = Bandwidth;
84
+        node["Coefficients"] = Coefficients;
85
+        node["WINDOWTYPE"] = enum2String(Type);
86
+        return node;
87
+    }
88
+
89
+    //--------------------------------------------------------------------------------------
90
+    //       Class:  WindowFilter
91
+    //      Method:  DeSerialize
92
+    //--------------------------------------------------------------------------------------
93
+    std::shared_ptr<WindowFilter> WindowFilter::DeSerialize ( const YAML::Node& node  ) {
94
+        if (node.Tag() != "WindowFilter") {
95
+            throw  DeSerializeTypeMismatch( "WindowFilter", node.Tag());
96
+        }
97
+        return std::make_shared<WindowFilter>( node, ctor_key() );
98
+    }
32 99
 
33 100
     // ====================  OPERATIONS    =======================
34 101
 

+ 24
- 0
Modules/LemmaCore/src/helper.cpp ファイルの表示

@@ -150,6 +150,20 @@ std::string enum2String(const HANKELTRANSFORMTYPE& Type) {
150 150
     return t;
151 151
 }
152 152
 
153
+std::string enum2String( const WINDOWTYPE& Type ) {
154
+    std::string t;
155
+    switch (Type) {
156
+        case HAMMING:
157
+            return std::string("HAMMING");
158
+        case HANNING:
159
+            return  std::string("HANNING");
160
+        case RECTANGULAR:
161
+            return std::string("RECTANGULAR");
162
+        default:
163
+            throw( std::runtime_error( "In enum2String WINDOWTYPE, type not identified" ) );
164
+    }
165
+}
166
+
153 167
 template<>
154 168
 FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
155 169
     if       (str ==  "HZ") return   HZ;
@@ -197,5 +211,15 @@ FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
197 211
     }
198 212
 }
199 213
 
214
+template<>
215
+WINDOWTYPE string2Enum<WINDOWTYPE>( const std::string& str ) {
216
+    if      (str == "HAMMING")      return HAMMING;
217
+    if      (str == "HANNING")      return HANNING;
218
+    if      (str == "RECTANGULAR")  return RECTANGULAR;
219
+    else {
220
+        throw std::runtime_error("string not recognized as WindowType");
221
+    }
222
+}
223
+
200 224
 }		// -----  end of Lemma  name  -----
201 225
 

+ 16
- 13
Modules/LemmaCore/testing/SerializeCheck.h ファイルの表示

@@ -26,14 +26,13 @@ class MyTestSuite : public CxxTest::TestSuite
26 26
 {
27 27
     public:
28 28
 
29
-//     void testASCIIParser( void )
30
-//     {
31
-//         auto Obj = ASCIIParser::NewSP();
32
-//         YAML::Node node = Obj->Serialize();
33
-//         auto Obj2 = ASCIIParser::DeSerialize(node);
34
-//         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
35
-//     }
36
-
29
+    void testASCIIParser( void )
30
+    {
31
+        auto Obj = ASCIIParser::NewSP();
32
+        YAML::Node node = Obj->Serialize();
33
+        auto Obj2 = ASCIIParser::DeSerialize(node);
34
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
35
+    }
37 36
 
38 37
     void testCubicSplineInterpolator(void)
39 38
     {
@@ -51,6 +50,14 @@ class MyTestSuite : public CxxTest::TestSuite
51 50
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
52 51
     }
53 52
 
53
+    void testWindowFilter( void )
54
+    {
55
+        auto Obj = WindowFilter::NewSP();
56
+        YAML::Node node = Obj->Serialize();
57
+        auto Obj2 = WindowFilter::DeSerialize(node);
58
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
59
+    }
60
+
54 61
 // /*
55 62
 //     void testRectilinearGridReader( void )
56 63
 //     {
@@ -64,11 +71,7 @@ class MyTestSuite : public CxxTest::TestSuite
64 71
 //         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridVTKExporter") );
65 72
 //     }
66 73
 //
67
-//     void testWindowFilter( void )
68
-//     {
69
-//         auto Obj = WindowFilter::NewSP();
70
-//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("WindowFilter") );
71
-//     }
74
+
72 75
 // */
73 76
 
74 77
 };

+ 23
- 20
vim/c.vim ファイルの表示

@@ -1,21 +1,24 @@
1
-"===================================================================================
2
-"
3
-"         FILE:  c.vim
4
-"  DESCRIPTION:  syntax file
5
-"                enable syntax based folding
6
-"                part of the c-support plugin
7
-"
8
-"       AUTHOR:  Trevor Irons
9
-"        EMAIL:  tirons@mines.edu
10
-"      COMPANY:  FH Südwestfalen, Iserlohn
11
-"      VERSION:  1.0
12
-"      CREATED:  11.03.2006
13
-"     REVISION:  ---
14
-"===================================================================================
15
-"
16
-" fold C blocks
17
-"
18
-syn region cBlock start="{" end="}" transparent fold
19
-set foldmethod=syntax
20
-set foldlevel=999
1
+"highlight cComment ctermfg=Green guifg=Green
2
+highlight cType ctermfg=Green guifg=Green
3
+syn keyword cType Real Complex VectorXr VectorXcr Vector3r Vector3Xr VectorXi Vector3cr Vector3Xcr MatrixXr MatrixXi MatrixXcr shared_ptr make_shared
21 4
 
5
+highlight constType ctermfg=Red guifg=Red
6
+syn keyword constType  PI EPSILON0 MU0 QPI  
7
+
8
+highlight eType ctermfg=Magenta guifg=Magenta
9
+syn keyword eType  MAGUNITS  TEMPUNITS  TIMEUNITS FREQUENCYUNITS FEMCOILORIENTATION ORIENTATION FIELDTYPE FIELDCOMPONENT SPATIALCOORDINANT HANKELTRANSFORMTYPE FIELDCALCULATIONS WINDOWTYPE 
10
+
11
+highlight eeType ctermfg=Cyan guifg=Cyan
12
+syn keyword eeType  TESLA NANOTESLA GAUSS CELCIUS KELVIN SEC MILLISEC MICROSEC NANOSEC PICOSEC HZ KHZ MHZ GHZ COAXIAL COPLANAR HFIELDREAL HFIELDIMAG EFIELDREAL EFIELDIMAG XCOMPONENT YCOMPONENT ZCOMPONENT XCOORD YCOORD ZCOORD X Y Z NX  NY  NZ ANDERSON801 CHAVE FHTKEY201 FHTKEY101 FHTKEY51 QWEKEY E H BOTH HAMMING HANNING RECTANGULAR
13
+
14
+" Namespaces
15
+highlight nspace ctermfg=Red guifg=Red
16
+syn keyword nspace Lemma YAML Eigen 
17
+
18
+" Lemma types
19
+highlight leType ctermfg=Yellow guifg=Yellow
20
+syn keyword leType HankelTransform KernelEm1D KernelEM1DManager DipoleSource EarthModel LayeredEarth LayeredEarthEM TEMSurvey TEMSurveyLine TEMSurveyLineRecord TEMInductiveReceiver PolygonalWireAntenna TEMTransmitter TEMReceiver Instrument InstrumentTem LemmaObject ReceiverPoints DCIPElectrode TEMSurveyData TEMSurveyLineData TEMSurveyLineRecordData  ASCIIParser CubicSplineInterpolator RectilinearGrid RectilinearGridReader RectilinearGridVTKExporter Filter WindowFilter DEMParticle DEMGrain Data DataReader
21
+
22
+" Deprecated Lemma Types
23
+highlight dleType ctermfg=Blue guifg=Blue 
24
+syn keyword dleType  ReferenceCountedObject 

+ 44
- 24
vim/cpp.cpp.template ファイルの表示

@@ -129,22 +129,56 @@ class |?CLASSNAME:c| : public |BASECLASS:c| {
129 129
 
130 130
 	friend std::ostream &operator<<(std::ostream &stream, const |CLASSNAME| &ob);
131 131
 
132
+    /*
133
+     *  This key is used to lock the constructor.
134
+     */
135
+    struct ctor_key {};
136
+
132 137
 	public:
133 138
 
134 139
 	    // ====================  LIFECYCLE     =======================
135 140
 
136
-        /*
137
-         *  Factory method for generating concrete class.
138
-         *  @return a std::shared_ptr of type |CLASSNAME|
141
+        /**
142
+         * Default constructor.
143
+         * @note This method is locked, and cannot be called directly.
144
+         *       The reason that the method is public is to enable the use
145
+         *       of make_shared whilst enforcing the use of shared_ptr,
146
+         *       in c++-17, this curiosity may be resolved.
147
+         * @see |CLASSNAME|::NewSP
139 148
          */
140
-	    static std::shared_ptr< |CLASSNAME| > NewSP();
149
+        explicit |CLASSNAME| ( const ctor_key& );
150
+
151
+        /**
152
+         * DeSerializing constructor.
153
+         * @note This method is locked, and cannot be called directly.
154
+         *       The reason that the method is public is to enable the use
155
+         *       of make_shared whilst enforcing the use of shared_ptr,
156
+         *       in c++-17, this curiosity may be resolved.
157
+         * @see |CLASSNAME|::DeSerialize
158
+         */
159
+        |CLASSNAME| (const YAML::Node& node);
160
+
161
+        /**
162
+         * Default destructor.
163
+         * @note This method should never be called due to the mandated
164
+         *       use of smart pointers. It is necessary to keep the method
165
+         *       public in order to allow for the use of the more efficeint
166
+         *       make_shared constructor.
167
+         */
168
+        virtual ~|CLASSNAME| ();
141 169
 
142 170
         /**
143 171
          *  Uses YAML to serialize this object.
144 172
          *  @return a YAML::Node
145
-         *   @see |CLASSNAME|::DeSerialize
173
+         *  @see |CLASSNAME|::DeSerialize
174
+         */
175
+        virtual YAML::Node Serialize() const;
176
+
177
+        /*
178
+         *  Factory method for generating concrete class.
179
+         *  @return a std::shared_ptr of type |CLASSNAME|
146 180
          */
147
-        YAML::Node Serialize() const;
181
+	    static std::shared_ptr< |CLASSNAME| > NewSP();
148 182
 
149 183
         /**
150 184
          *   Constructs an |CLASSNAME| object from a YAML::Node.
@@ -160,31 +194,17 @@ class |?CLASSNAME:c| : public |BASECLASS:c| {
160 194
 
161 195
         // ====================  INQUIRY       =======================
162 196
 
163
-
164
-
165 197
     protected:
166 198
 
167 199
         // ====================  LIFECYCLE     =======================
168 200
 
169
-        /**
170
-         * Default protected constructor, use NewSP methods to construct
171
-         * @see |CLASSNAME|::NewSP
172
-         */
173
-        |CLASSNAME| (const std::string& name);
174
-
175
-        /**
176
-         * Protected DeDerializing constructor, use factory DeSerialize  method.
177
-         * @see |CLASSNAME|::DeSerialize
178
-         */
179
-        |CLASSNAME| (const YAML::Node& node);
180
-
181
-        /** Default protected destructor, use smart pointers (std::shared_ptr) */
182
-        ~|CLASSNAME| ();
183
-
184
-	// ====================  DATA MEMBERS  =========================
201
+    	// ====================  DATA MEMBERS  =========================
185 202
 
186 203
     private:
187 204
 
205
+        /** ASCII string representation of the class name */
206
+        static constexpr auto CName = "|CLASSNAME|";
207
+
188 208
 }; // -----  end of class  |CLASSNAME|  -----
189 209
 }  // -----  end of namespace Lemma ----
190 210
 

読み込み中…
キャンセル
保存