소스 검색

Serializing of MatrixXr

submodule
Trevor Irons 7 년 전
부모
커밋
7bee2933f0
3개의 변경된 파일24개의 추가작업 그리고 18개의 파일을 삭제
  1. 2
    1
      Modules/LemmaCore/include/LemmaObject.h
  2. 16
    12
      Modules/LemmaCore/include/helper.h
  3. 6
    5
      Modules/LemmaCore/src/LemmaObject.cpp

+ 2
- 1
Modules/LemmaCore/include/LemmaObject.h 파일 보기

39
     /**
39
     /**
40
      *  Streams class information as YAML::Node
40
      *  Streams class information as YAML::Node
41
      */
41
      */
42
-    friend YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject &ob) ;
42
+    //friend YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject &ob) ;
43
 
43
 
44
     friend class LemmaObjectDeleter;
44
     friend class LemmaObjectDeleter;
45
 
45
 
64
         virtual YAML::Node Serialize() const {
64
         virtual YAML::Node Serialize() const {
65
             std::cout.precision( 20 );
65
             std::cout.precision( 20 );
66
             YAML::Node node = YAML::Node();
66
             YAML::Node node = YAML::Node();
67
+            //node.SetStyle(YAML::EmitterStyle::Flow);
67
             node.SetTag( GetName() );
68
             node.SetTag( GetName() );
68
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
69
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
69
             std::string ser_time =  std::string( std::ctime(&now) );
70
             std::string ser_time =  std::string( std::ctime(&now) );

+ 16
- 12
Modules/LemmaCore/include/helper.h 파일 보기

13
  * @version   $Id$
13
  * @version   $Id$
14
  * @author    Trevor Irons (ti)
14
  * @author    Trevor Irons (ti)
15
  * @email     Trevor.Irons@xri-geo.com
15
  * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2017, University of Utah
16
  * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
  * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
  * @copyright Copyright (c) 2014, Trevor Irons
18
  * @copyright Copyright (c) 2014, Trevor Irons
18
  */
19
  */
292
     node["cols"] = rhs.cols();
293
     node["cols"] = rhs.cols();
293
     for (int ir=0; ir<rhs.rows(); ++ir) {
294
     for (int ir=0; ir<rhs.rows(); ++ir) {
294
         for (int ic=0; ic<rhs.cols(); ++ic) {
295
         for (int ic=0; ic<rhs.cols(); ++ic) {
295
-            node["data"].push_back( rhs(ir,ic) );
296
+            node[ir][ic] = rhs(ir,ic);
296
         }
297
         }
298
+        node[ir].SetStyle(YAML::EmitterStyle::Flow);
297
     }
299
     }
300
+    //node.SetStyle(YAML::EmitterStyle::Block);
298
     node.SetTag( "MatrixXr" );
301
     node.SetTag( "MatrixXr" );
299
     return node;
302
     return node;
300
   }
303
   }
301
 
304
 
302
-//   static bool decode(const Node& node, Lemma::Vector3r& rhs) {
303
-//     if( node.Tag() != "Vector3r" ) {
304
-//         return false;
305
-//     }
306
-//     int ir=0;
307
-//     for(YAML::const_iterator it=node[0].begin(); it!=node[0].end(); ++it) {
308
-//         rhs(ir) = it->as<Lemma::Real>();
309
-//         ++ir;
310
-//     }
311
-//     return true;
312
-//   }
305
+  static bool decode(const Node& node, Lemma::MatrixXr& rhs) {
306
+    if( node.Tag() != "MatrixXr" ) {
307
+        return false;
308
+    }
309
+    rhs.resize( node["rows"].as<int>(), node["cols"].as<int>() );
310
+    int ir=0;
311
+    for(YAML::const_iterator it=node[0].begin(); it!=node[0].end(); ++it) {
312
+        rhs(ir) = it->as<Lemma::Real>();
313
+        ++ir;
314
+    }
315
+    return true;
316
+  }
313
 
317
 
314
 };
318
 };
315
 
319
 

+ 6
- 5
Modules/LemmaCore/src/LemmaObject.cpp 파일 보기

15
 
15
 
16
 namespace Lemma {
16
 namespace Lemma {
17
 
17
 
18
-    YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
19
-        out << YAML::BeginMap;
20
-        out << YAML::Key <<"Class Name"    << YAML::Value << ob.GetName();
21
-        return out;
22
-    }
18
+//     YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
19
+//         out << YAML::Flow;
20
+//         out << YAML::BeginMap;
21
+//         out << YAML::Key <<"Class Name"    << YAML::Value << ob.GetName();
22
+//         return out;
23
+//     }
23
 
24
 
24
     // ====================  LIFECYCLE     ==============================
25
     // ====================  LIFECYCLE     ==============================
25
 
26
 

Loading…
취소
저장