Main Lemma Repository
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TEMSurveyLineData.cpp 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 03/03/2015 10:23:22
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2015, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2015, Trevor Irons
  16. */
  17. #include "TEMSurveyLineData.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurveyLineData &ob) {
  22. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  23. return stream;
  24. }
  25. #else
  26. std::ostream &operator<<(std::ostream &stream, const TEMSurveyLineData& ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // ==================== LIFECYCLE =======================
  32. //--------------------------------------------------------------------------------------
  33. // Class: TEMSurveyLineData
  34. // Method: TEMSurveyLineData
  35. // Description: constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. TEMSurveyLineData::TEMSurveyLineData (const std::string& name) : LemmaObject(name) {
  38. } // ----- end of method TEMSurveyLineData::TEMSurveyLineData (constructor) -----
  39. #ifdef HAVE_YAMLCPP
  40. //--------------------------------------------------------------------------------------
  41. // Class: TEMSurveyLineData
  42. // Method: TEMSurveyLineData
  43. // Description: DeSerializing constructor (protected)
  44. //--------------------------------------------------------------------------------------
  45. TEMSurveyLineData::TEMSurveyLineData (const YAML::Node& node) : LemmaObject(node) {
  46. for (int ii=0; ii< node["numberOfRecords"].as<int>( ); ++ii) {
  47. RecordData.push_back( TEMSurveyLineRecordData::DeSerialize( node[ std::string("record_") + to_string(ii)] ) );
  48. RecordData[ii]->AttachTo(this);
  49. }
  50. } // ----- end of method TEMSurveyLineData::TEMSurveyLineData (constructor) -----
  51. #endif
  52. //--------------------------------------------------------------------------------------
  53. // Class: TEMSurveyLineData
  54. // Method: New()
  55. // Description: public constructor
  56. //--------------------------------------------------------------------------------------
  57. TEMSurveyLineData* TEMSurveyLineData::New() {
  58. TEMSurveyLineData* Obj = new TEMSurveyLineData("TEMSurveyLineData");
  59. Obj->AttachTo(Obj);
  60. return Obj;
  61. }
  62. //--------------------------------------------------------------------------------------
  63. // Class: TEMSurveyLineRecordData
  64. // Method: Clone
  65. //--------------------------------------------------------------------------------------
  66. TEMSurveyLineData* TEMSurveyLineData::Clone ( ) {
  67. return TEMSurveyLineData::DeSerialize( this->Serialize() ) ;
  68. } // ----- end of method TEMSurveyLineRecordData::Clone -----
  69. //--------------------------------------------------------------------------------------
  70. // Class: TEMSurveyLineData
  71. // Method: ~TEMSurveyLineData
  72. // Description: destructor (protected)
  73. //--------------------------------------------------------------------------------------
  74. TEMSurveyLineData::~TEMSurveyLineData () {
  75. } // ----- end of method TEMSurveyLineData::~TEMSurveyLineData (destructor) -----
  76. //--------------------------------------------------------------------------------------
  77. // Class: TEMSurveyLineData
  78. // Method: Delete
  79. // Description: public destructor
  80. //--------------------------------------------------------------------------------------
  81. void TEMSurveyLineData::Delete() {
  82. this->DetachFrom(this);
  83. }
  84. //--------------------------------------------------------------------------------------
  85. // Class: TEMSurveyLineData
  86. // Method: Release
  87. // Description: destructor (protected)
  88. //--------------------------------------------------------------------------------------
  89. void TEMSurveyLineData::Release() {
  90. for (std::vector<TEMSurveyLineRecordData*>::iterator it = RecordData.begin() ; it != RecordData.end(); ++it) {
  91. (*it)->DetachFrom(this);
  92. (*it)->Delete();
  93. }
  94. delete this;
  95. }
  96. // =================== OPERATORS ===============================
  97. TEMSurveyLineRecordData* TEMSurveyLineData::operator( ) ( const int& idx ) const {
  98. return RecordData[ idx ];
  99. }
  100. //--------------------------------------------------------------------------------------
  101. // Class: TEMSurveyLineData
  102. // Method: operator +=
  103. //--------------------------------------------------------------------------------------
  104. void TEMSurveyLineData::operator += ( const TEMSurveyLineData& rhs) {
  105. if ( this->GetNumberOfRecords() != rhs.GetNumberOfRecords() ) {
  106. throw std::runtime_error( "Record mismatch in TEMSurveyLineData +=" );
  107. }
  108. for (int irec=0; irec<this->GetNumberOfRecords(); ++irec ) {
  109. *(*this)(irec) += *rhs(irec);
  110. //*LineData[irec] += *rhs(irec);
  111. //*LineData[irec] += *rhs.GetLine(irec);
  112. }
  113. return ;
  114. } // ----- end of method TEMSurveyLineData::+= -----
  115. //--------------------------------------------------------------------------------------
  116. // Class: TEMSurveyLineData
  117. // Method: operator +
  118. //--------------------------------------------------------------------------------------
  119. TEMSurveyLineData* TEMSurveyLineData::operator + ( const TEMSurveyLineData& rhs) {
  120. TEMSurveyLineData* clone = Clone();
  121. *clone += rhs;
  122. return clone;
  123. } // ----- end of method TEMSurveyLineData::operator + -----
  124. //--------------------------------------------------------------------------------------
  125. // Class: TEMSurveyLineData
  126. // Method: operator -=
  127. //--------------------------------------------------------------------------------------
  128. void TEMSurveyLineData::operator -= ( const TEMSurveyLineData& rhs ) {
  129. if ( this->GetNumberOfRecords() != rhs.GetNumberOfRecords() ) {
  130. throw std::runtime_error( "Record mismatch in TEMSurveyLineData +=" );
  131. }
  132. for (int irec=0; irec<this->GetNumberOfRecords(); ++irec ) {
  133. *(*this)(irec) -= *rhs(irec);
  134. //*LineData[irec] -= *rhs(irec);
  135. //*LineData[irec] -= *rhs.GetLine(irec);
  136. }
  137. return ;
  138. } // ----- end of method TEMSurveyLineData::operator -= -----
  139. //--------------------------------------------------------------------------------------
  140. // Class: TEMSurveyLineData
  141. // Method: operator -
  142. //--------------------------------------------------------------------------------------
  143. TEMSurveyLineData* TEMSurveyLineData::operator - ( const TEMSurveyLineData& rhs) {
  144. TEMSurveyLineData* clone = Clone();
  145. *clone -= rhs;
  146. return clone;
  147. } // ----- end of method TEMSurveyLineData::operator - -----
  148. // ==================== ACCESS =======================
  149. //--------------------------------------------------------------------------------------
  150. // Class: TEMSurveyLineData
  151. // Method: GetRecord
  152. //--------------------------------------------------------------------------------------
  153. TEMSurveyLineRecordData* TEMSurveyLineData::GetRecord(const int& ir) const {
  154. return RecordData[ir];
  155. } // ----- end of method TEMSurveyLineData::GetRecord -----
  156. //--------------------------------------------------------------------------------------
  157. // Class: TEMSurveyLineRecordData
  158. // Method: GetNumberOfRecords
  159. //--------------------------------------------------------------------------------------
  160. int TEMSurveyLineData::GetNumberOfRecords ( ) const {
  161. return RecordData.size();
  162. } // ----- end of method TEMSurveyLineRecordData::GetNumberOfRecords -----
  163. #ifdef HAVE_YAMLCPP
  164. //--------------------------------------------------------------------------------------
  165. // Class: TEMSurveyLineData
  166. // Method: Serialize
  167. //--------------------------------------------------------------------------------------
  168. YAML::Node TEMSurveyLineData::Serialize ( ) const {
  169. YAML::Node node = LemmaObject::Serialize();;
  170. node.SetTag( this->Name );
  171. node["numberOfRecords"] = RecordData.size();
  172. // FILL IN CLASS SPECIFICS HERE
  173. for (unsigned int it = 0; it< RecordData.size(); ++it) {
  174. node[std::string("record_") + to_string(it)] = RecordData[it]->Serialize();
  175. }
  176. return node;
  177. } // ----- end of method TEMSurveyLineData::Serialize -----
  178. //--------------------------------------------------------------------------------------
  179. // Class: TEMSurveyLineData
  180. // Method: DeSerialize
  181. //--------------------------------------------------------------------------------------
  182. TEMSurveyLineData* TEMSurveyLineData::DeSerialize ( const YAML::Node& node ) {
  183. TEMSurveyLineData* Object = new TEMSurveyLineData(node);
  184. Object->AttachTo(Object);
  185. DESERIALIZECHECK( node, Object )
  186. return Object ;
  187. } // ----- end of method TEMSurveyLineData::DeSerialize -----
  188. #endif
  189. } // ----- end of Lemma name -----