Parcourir la source

Serializing of MatrixXr

submodule
Trevor Irons il y a 7 ans
Parent
révision
7bee2933f0

+ 2
- 1
Modules/LemmaCore/include/LemmaObject.h Voir le fichier

@@ -39,7 +39,7 @@ class LemmaObject {
39 39
     /**
40 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 44
     friend class LemmaObjectDeleter;
45 45
 
@@ -64,6 +64,7 @@ class LemmaObject {
64 64
         virtual YAML::Node Serialize() const {
65 65
             std::cout.precision( 20 );
66 66
             YAML::Node node = YAML::Node();
67
+            //node.SetStyle(YAML::EmitterStyle::Flow);
67 68
             node.SetTag( GetName() );
68 69
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
69 70
             std::string ser_time =  std::string( std::ctime(&now) );

+ 16
- 12
Modules/LemmaCore/include/helper.h Voir le fichier

@@ -13,6 +13,7 @@
13 13
  * @version   $Id$
14 14
  * @author    Trevor Irons (ti)
15 15
  * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2017, University of Utah
16 17
  * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17 18
  * @copyright Copyright (c) 2014, Trevor Irons
18 19
  */
@@ -292,24 +293,27 @@ struct convert<Lemma::MatrixXr> {
292 293
     node["cols"] = rhs.cols();
293 294
     for (int ir=0; ir<rhs.rows(); ++ir) {
294 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 301
     node.SetTag( "MatrixXr" );
299 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 Voir le fichier

@@ -15,11 +15,12 @@
15 15
 
16 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 25
     // ====================  LIFECYCLE     ==============================
25 26
 

Chargement…
Annuler
Enregistrer