Bläddra i källkod

Rebasing code for better C++-11 useage

enhancement_3
Trevor Irons 8 år sedan
förälder
incheckning
a0a0d30207

+ 2
- 2
LemmaCore/src/CMakeLists.txt Visa fil

@@ -9,8 +9,8 @@ set (SOURCE
9 9
 	${CMAKE_CURRENT_SOURCE_DIR}/data.cpp
10 10
 	${CMAKE_CURRENT_SOURCE_DIR}/datafem.cpp
11 11
 	${CMAKE_CURRENT_SOURCE_DIR}/datareader.cpp
12
-	${CMAKE_CURRENT_SOURCE_DIR}/datareaderfem.cpp
13
-	${CMAKE_CURRENT_SOURCE_DIR}/datareaderfemubc.cpp
12
+#	${CMAKE_CURRENT_SOURCE_DIR}/datareaderfem.cpp
13
+#	${CMAKE_CURRENT_SOURCE_DIR}/datareaderfemubc.cpp
14 14
 	${CMAKE_CURRENT_SOURCE_DIR}/datareadertem.cpp
15 15
 	${CMAKE_CURRENT_SOURCE_DIR}/datatem.cpp
16 16
 	${CMAKE_CURRENT_SOURCE_DIR}/DCIPElectrode.cpp

+ 16
- 81
LemmaCore/src/LemmaObject.cpp Visa fil

@@ -15,87 +15,41 @@
15 15
 
16 16
 namespace Lemma {
17 17
 
18
-    std::ostream &operator<<(std::ostream &stream,
18
+    std::ostream &operator << (std::ostream &stream,
19 19
                 const LemmaObject &ob) {
20
-
21 20
       stream << "Class name= " << ob.Name  << "\n";
22 21
       return stream;
23 22
     }
24 23
 
25 24
     #ifdef HAVE_YAMLCPP
26 25
     YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
27
-    out << YAML::BeginMap;
28
-    out << YAML::Key <<"Class Name"    << YAML::Value << ob.Name;
29
-    return out;
26
+        out << YAML::BeginMap;
27
+        out << YAML::Key <<"Class Name"    << YAML::Value << ob.GetName();
28
+        return out;
30 29
     }
31 30
     #endif
32 31
 
33 32
     // ====================  LIFECYCLE     ==============================
34 33
 
35 34
     // Constructor
36
-    LemmaObject::LemmaObject(const std::string& name) :
37
-        NumberOfReferences(0), Name(name) {
35
+    LemmaObject::LemmaObject(const std::string& name) : Name(name) {
38 36
     }
39 37
 
40 38
     #ifdef HAVE_YAMLCPP
41
-    LemmaObject::LemmaObject(const YAML::Node &node) :
42
-        NumberOfReferences(0), Name(node.Tag()) {
43
-
39
+    LemmaObject::LemmaObject(const YAML::Node &node) : Name(node.Tag()) {
44 40
     }
45 41
     #endif
46 42
 
47 43
     // Destructor
48 44
     LemmaObject::~LemmaObject() {
49
-        if (this->NumberOfReferences != 0) {
50
-            throw DeleteObjectWithReferences(this);
51
-        }
45
+        std::cout << "~LemmaObject()" << std::endl;
52 46
     }
53 47
 
54 48
     // ====================  OPERATIONS    ==============================
55 49
 
56
-    void LemmaObject::AttachTo (LemmaObject* ptrIn) {
57
-        this->NumberOfReferences++;
58
-        this->RefPtrList.push_back(ptrIn);
59
-    }
60
-
61
-    void LemmaObject::DetachFrom (LemmaObject* ptrIn) {
62
-        bool found(false);
63
-        std::vector<LemmaObject*>::iterator iter = this->RefPtrList.begin();
64
-        while (iter != this->RefPtrList.end() ) {
65
-            if (*iter == ptrIn) {
66
-                this->RefPtrList.erase(iter);
67
-                this->NumberOfReferences--;
68
-                found = true;
69
-                break;
70
-            }
71
-            ++iter;
72
-        }
73
-        if (!found) {
74
-            std::cout << *this;
75
-            std::cerr << "Function call DetachFrom Failed \n"
76
-                      << "Caller name " << this->Name << " address=" << this <<
77
-                      " detaching from " <<  ptrIn->Name << " address= " << ptrIn<< "\n"
78
-                      <<  "This class was not listed as attached to this\n";
79
-            exit(EXIT_FAILURE);
80
-        }
81
-
82
-        // If there are no remaining references, free up memory.
83
-        if (NumberOfReferences == 0) {
84
-            this->Release();
85
-        }
86
-    }
87
-
88 50
     // ====================  INQUIRY       ==============================
89 51
 
90
-    unsigned int LemmaObject::GetNumberOfReferences() {
91
-        return this->NumberOfReferences;
92
-    }
93
-
94
-    std::vector<LemmaObject*> LemmaObject::GetReferences() {
95
-        return RefPtrList;
96
-    }
97
-
98
-    std::string LemmaObject::GetName() {
52
+    std::string LemmaObject::GetName() const {
99 53
         return Name;
100 54
     }
101 55
 
@@ -107,25 +61,6 @@ namespace Lemma {
107 61
 
108 62
     //////////////////////////////////////////////////////////////////////
109 63
     //////////////////////////////////////////////////////////////////////
110
-    // Exception classes
111
-    DeleteObjectWithReferences::DeleteObjectWithReferences() :
112
-        runtime_error("DELETED OBJECT WITH REFERENCES") {
113
-        }
114
-
115
-    DeleteObjectWithReferences::
116
-            DeleteObjectWithReferences(LemmaObject* ptr) :
117
-        runtime_error("DELETED OBJECT WITH REFERENCES") {
118
-            std::cerr << "DELETED OBJECT WITH REFERENCES THROWN BY INSTANCE OF  "
119
-                      << ptr->GetName() << std::endl;
120
-            std::cerr << ptr->RefPtrList.size() << " connection(s) remain\n";
121
-            for (unsigned int i=0; i<ptr->RefPtrList.size(); ++i) {
122
-                std::cerr << "\tConnection " << i << " is " << ptr->RefPtrList[i]->GetName();
123
-                if (ptr->RefPtrList[i]->GetName().empty())
124
-                    std::cerr << "a deleted object! PLEASE REPORT BUG!\n";
125
-                else
126
-                std::cerr << "\n" << *ptr->RefPtrList[i] << std::endl;
127
-            }
128
-        }
129 64
 
130 65
     DeSerializeTypeMismatch::DeSerializeTypeMismatch(LemmaObject *ptr, const std::string& got) :
131 66
         runtime_error("DESERIALIZE TYPE MISMATCH") {
@@ -135,7 +70,7 @@ namespace Lemma {
135 70
     RequestToReturnNullPointer::
136 71
         RequestToReturnNullPointer(LemmaObject *ptr) :
137 72
         runtime_error("REQUEST TO RETURN NULL POINTER"){
138
-            std::cout << "Thrown by instance of "
73
+            std::cerr << "Thrown by instance of "
139 74
                       << ptr->GetName() << std::endl;
140 75
         }
141 76
 
@@ -146,19 +81,19 @@ namespace Lemma {
146 81
     AssignmentOutOfBounds::
147 82
         AssignmentOutOfBounds(LemmaObject *ptr) :
148 83
         runtime_error("ASSIGNMENT OUT OF BOUNDS"){
149
-            std::cout << "Thrown by instance of "
84
+            std::cerr << "Thrown by instance of "
150 85
                       << ptr->GetName() << std::endl;
151 86
        }
152 87
 
153 88
 	GenericFileIOError::
154 89
 		GenericFileIOError(LemmaObject *ptr, const std::string &filename) : runtime_error("FILE I/O ERROR"){
155
-			std::cout << std::endl;
156
-			std::cout << "FILE I/O ERROR" << std::endl;
157
-			std::cout << std::endl;
158
-			std::cout << "Thrown by instance of "
90
+			std::cerr << std::endl;
91
+			std::cerr << "FILE I/O ERROR" << std::endl;
92
+			std::cerr << std::endl;
93
+			std::cerr << "Thrown by instance of "
159 94
 				<< ptr->GetName() << std::endl;
160
-			std::cout << "  while trying to access " << filename << std::endl;
161
-			std::cout << std::endl;
95
+			std::cerr << "  while trying to access " << filename << std::endl;
96
+			std::cerr << std::endl;
162 97
 		}
163 98
 
164 99
 } // end of namespace Lemma

+ 2
- 2
LemmaCore/src/datafem.cpp Visa fil

@@ -65,6 +65,8 @@ namespace Lemma {
65 65
 	}
66 66
 
67 67
 	void DataFEM::Release() {
68
+		if (this->NumberOfReferences != 0)
69
+			throw DeleteObjectWithReferences(this);
68 70
 		delete this;
69 71
 	}
70 72
 
@@ -85,8 +87,6 @@ namespace Lemma {
85 87
 	}
86 88
 
87 89
 	DataFEM::~DataFEM() {
88
-		if (this->NumberOfReferences != 0)
89
-			throw DeleteObjectWithReferences(this);
90 90
 	}
91 91
 
92 92
 	void DataFEM::Zero() {

+ 0
- 3
LemmaCore/src/datareaderfem.cpp Visa fil

@@ -19,9 +19,6 @@ namespace Lemma {
19 19
 	}
20 20
 
21 21
 	DataReaderFem::~DataReaderFem() {
22
-		if (NumberOfReferences != 0) {
23
-			throw DeleteObjectWithReferences(this);
24
-		}
25 22
 	}
26 23
 
27 24
 	DataReaderFem* DataReaderFem::New() {

+ 1
- 0
Modules/FDEM1D/README Visa fil

@@ -0,0 +1 @@
1
+Frequency Domain EM in 1D

Laddar…
Avbryt
Spara