Restore the given Grid to a saved state.
| 1120 | |
| 1121 | /// Restore the given Grid to a saved state. |
| 1122 | static void setState(GridType& grid, std::tuple<nb::bytes> state) |
| 1123 | { |
| 1124 | nb::bytes bytesObj = std::get<0>(state); |
| 1125 | std::string serialized(bytesObj.c_str(), bytesObj.c_str() + bytesObj.size()); |
| 1126 | |
| 1127 | // Restore the internal state of the C++ object. |
| 1128 | GridPtrVecPtr grids; |
| 1129 | { |
| 1130 | std::istringstream istr(serialized, std::ios_base::binary); |
| 1131 | io::Stream strm(istr); |
| 1132 | grids = strm.getGrids(); // (note: file-level metadata is ignored) |
| 1133 | } |
| 1134 | if (grids && !grids->empty()) { |
| 1135 | if (typename GridType::Ptr savedGrid = gridPtrCast<GridType>((*grids)[0])) { |
| 1136 | new (&grid) GridType(*savedGrid); |
| 1137 | return; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | new (&grid) GridType(); |
| 1142 | } |
| 1143 | }; // struct PickleSuite |
| 1144 | |
| 1145 |
no test coverage detected