@@ -12,6 +12,23 @@ namespace xt
1212{
1313 enum class xfile_mode { load, init, init_on_fail };
1414
15+ struct xfile_dirty
16+ {
17+ bool data_dirty;
18+ bool shape_dirty;
19+
20+ xfile_dirty (bool is_dirty=false )
21+ {
22+ data_dirty = is_dirty;
23+ shape_dirty = is_dirty;
24+ }
25+
26+ operator bool () const
27+ {
28+ return data_dirty || shape_dirty;
29+ }
30+ };
31+
1532 template <class T >
1633 class xfile_value_reference
1734 {
@@ -20,7 +37,7 @@ namespace xt
2037 using self_type = xfile_value_reference<T>;
2138 using const_reference = const T&;
2239
23- xfile_value_reference (T& value, bool & dirty);
40+ xfile_value_reference (T& value, xfile_dirty & dirty);
2441 ~xfile_value_reference () = default ;
2542
2643 xfile_value_reference (const xfile_value_reference&) = default ;
@@ -49,7 +66,7 @@ namespace xt
4966 private:
5067
5168 T& m_value;
52- bool & m_dirty;
69+ xfile_dirty & m_dirty;
5370 };
5471}
5572
@@ -205,7 +222,7 @@ namespace xt
205222 private:
206223
207224 E m_storage;
208- bool m_dirty;
225+ xfile_dirty m_dirty;
209226 IOH m_io_handler;
210227 std::string m_path;
211228 xfile_mode m_file_mode;
@@ -223,7 +240,7 @@ namespace xt
223240 ****************************************/
224241
225242 template <class T >
226- inline xfile_value_reference<T>::xfile_value_reference(T& value, bool & dirty)
243+ inline xfile_value_reference<T>::xfile_value_reference(T& value, xfile_dirty & dirty)
227244 : m_value(value), m_dirty(dirty)
228245 {
229246 }
@@ -235,7 +252,7 @@ namespace xt
235252 if (v != m_value)
236253 {
237254 m_value = v;
238- m_dirty = true ;
255+ m_dirty. data_dirty = true ;
239256 }
240257 return *this ;
241258 }
@@ -247,7 +264,7 @@ namespace xt
247264 if (v != T (0 ))
248265 {
249266 m_value += v;
250- m_dirty = true ;
267+ m_dirty. data_dirty = true ;
251268 }
252269 return *this ;
253270 }
@@ -259,7 +276,7 @@ namespace xt
259276 if (v != T (0 ))
260277 {
261278 m_value -= v;
262- m_dirty = true ;
279+ m_dirty. data_dirty = true ;
263280 }
264281 return *this ;
265282 }
@@ -271,7 +288,7 @@ namespace xt
271288 if (v != T (1 ))
272289 {
273290 m_value *= v;
274- m_dirty = true ;
291+ m_dirty. data_dirty = true ;
275292 }
276293 return *this ;
277294 }
@@ -283,7 +300,7 @@ namespace xt
283300 if (v != T (1 ))
284301 {
285302 m_value /= v;
286- m_dirty = true ;
303+ m_dirty. data_dirty = true ;
287304 }
288305 return *this ;
289306 }
@@ -411,27 +428,31 @@ namespace xt
411428 inline void xfile_array_container<E, IOH>::resize(S&& shape, bool force)
412429 {
413430 m_storage.resize (std::forward<S>(shape), force);
431+ m_dirty.shape_dirty = true ;
414432 }
415433
416434 template <class E , class IOH >
417435 template <class S >
418436 inline void xfile_array_container<E, IOH>::resize(S&& shape, layout_type l)
419437 {
420438 m_storage.resize (std::forward<S>(shape), l);
439+ m_dirty.shape_dirty = true ;
421440 }
422441
423442 template <class E , class IOH >
424443 template <class S >
425444 inline void xfile_array_container<E, IOH>::resize(S&& shape, const strides_type& strides)
426445 {
427446 m_storage.resize (std::forward<S>(shape), strides);
447+ m_dirty.shape_dirty = true ;
428448 }
429449
430450 template <class E , class IOH >
431451 template <class S >
432452 inline auto xfile_array_container<E, IOH>::reshape(S&& shape, layout_type layout) & -> self_type&
433453 {
434454 m_storage.reshape (std::forward<S>(shape), layout);
455+ m_dirty.shape_dirty = true ;
435456 return *this ;
436457 }
437458
@@ -440,6 +461,7 @@ namespace xt
440461 inline auto xfile_array_container<E, IOH>::reshape(std::initializer_list<T> shape, layout_type layout) & -> self_type&
441462 {
442463 m_storage.reshape (shape, layout);
464+ m_dirty.shape_dirty = true ;
443465 return *this ;
444466 }
445467
@@ -601,7 +623,7 @@ namespace xt
601623 {
602624 if (m_dirty)
603625 {
604- m_io_handler.write (m_storage, m_path);
626+ m_io_handler.write (m_storage, m_path, m_dirty );
605627 m_dirty = false ;
606628 }
607629 }
0 commit comments