Sfoglia il codice sorgente

Rebasing code for better C++-11 useage

enhancement_3
Trevor Irons 8 anni fa
parent
commit
a0a0d30207

+ 2
- 2
LemmaCore/src/CMakeLists.txt Vedi File

9
 	${CMAKE_CURRENT_SOURCE_DIR}/data.cpp
9
 	${CMAKE_CURRENT_SOURCE_DIR}/data.cpp
10
 	${CMAKE_CURRENT_SOURCE_DIR}/datafem.cpp
10
 	${CMAKE_CURRENT_SOURCE_DIR}/datafem.cpp
11
 	${CMAKE_CURRENT_SOURCE_DIR}/datareader.cpp
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
 	${CMAKE_CURRENT_SOURCE_DIR}/datareadertem.cpp
14
 	${CMAKE_CURRENT_SOURCE_DIR}/datareadertem.cpp
15
 	${CMAKE_CURRENT_SOURCE_DIR}/datatem.cpp
15
 	${CMAKE_CURRENT_SOURCE_DIR}/datatem.cpp
16
 	${CMAKE_CURRENT_SOURCE_DIR}/DCIPElectrode.cpp
16
 	${CMAKE_CURRENT_SOURCE_DIR}/DCIPElectrode.cpp

+ 16
- 81
LemmaCore/src/LemmaObject.cpp Vedi File

15
 
15
 
16
 namespace Lemma {
16
 namespace Lemma {
17
 
17
 
18
-    std::ostream &operator<<(std::ostream &stream,
18
+    std::ostream &operator << (std::ostream &stream,
19
                 const LemmaObject &ob) {
19
                 const LemmaObject &ob) {
20
-
21
       stream << "Class name= " << ob.Name  << "\n";
20
       stream << "Class name= " << ob.Name  << "\n";
22
       return stream;
21
       return stream;
23
     }
22
     }
24
 
23
 
25
     #ifdef HAVE_YAMLCPP
24
     #ifdef HAVE_YAMLCPP
26
     YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
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
     #endif
30
     #endif
32
 
31
 
33
     // ====================  LIFECYCLE     ==============================
32
     // ====================  LIFECYCLE     ==============================
34
 
33
 
35
     // Constructor
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
     #ifdef HAVE_YAMLCPP
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
     #endif
41
     #endif
46
 
42
 
47
     // Destructor
43
     // Destructor
48
     LemmaObject::~LemmaObject() {
44
     LemmaObject::~LemmaObject() {
49
-        if (this->NumberOfReferences != 0) {
50
-            throw DeleteObjectWithReferences(this);
51
-        }
45
+        std::cout << "~LemmaObject()" << std::endl;
52
     }
46
     }
53
 
47
 
54
     // ====================  OPERATIONS    ==============================
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
     // ====================  INQUIRY       ==============================
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
         return Name;
53
         return Name;
100
     }
54
     }
101
 
55
 
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
     DeSerializeTypeMismatch::DeSerializeTypeMismatch(LemmaObject *ptr, const std::string& got) :
65
     DeSerializeTypeMismatch::DeSerializeTypeMismatch(LemmaObject *ptr, const std::string& got) :
131
         runtime_error("DESERIALIZE TYPE MISMATCH") {
66
         runtime_error("DESERIALIZE TYPE MISMATCH") {
135
     RequestToReturnNullPointer::
70
     RequestToReturnNullPointer::
136
         RequestToReturnNullPointer(LemmaObject *ptr) :
71
         RequestToReturnNullPointer(LemmaObject *ptr) :
137
         runtime_error("REQUEST TO RETURN NULL POINTER"){
72
         runtime_error("REQUEST TO RETURN NULL POINTER"){
138
-            std::cout << "Thrown by instance of "
73
+            std::cerr << "Thrown by instance of "
139
                       << ptr->GetName() << std::endl;
74
                       << ptr->GetName() << std::endl;
140
         }
75
         }
141
 
76
 
146
     AssignmentOutOfBounds::
81
     AssignmentOutOfBounds::
147
         AssignmentOutOfBounds(LemmaObject *ptr) :
82
         AssignmentOutOfBounds(LemmaObject *ptr) :
148
         runtime_error("ASSIGNMENT OUT OF BOUNDS"){
83
         runtime_error("ASSIGNMENT OUT OF BOUNDS"){
149
-            std::cout << "Thrown by instance of "
84
+            std::cerr << "Thrown by instance of "
150
                       << ptr->GetName() << std::endl;
85
                       << ptr->GetName() << std::endl;
151
        }
86
        }
152
 
87
 
153
 	GenericFileIOError::
88
 	GenericFileIOError::
154
 		GenericFileIOError(LemmaObject *ptr, const std::string &filename) : runtime_error("FILE I/O ERROR"){
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
 				<< ptr->GetName() << std::endl;
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
 } // end of namespace Lemma
99
 } // end of namespace Lemma

+ 2
- 2
LemmaCore/src/datafem.cpp Vedi File

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

+ 0
- 3
LemmaCore/src/datareaderfem.cpp Vedi File

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

+ 1
- 0
Modules/FDEM1D/README Vedi File

1
+Frequency Domain EM in 1D

Loading…
Annulla
Salva