1414#include < string>
1515#include < string_view>
1616#include < vector>
17+ #include < utility>
1718
1819// LibTokaMap includes
1920#include < utils/ram_cache.hpp>
@@ -350,6 +351,33 @@ bool json_plugin::copy_dim_from_cache(const libtokamap::RamCache& cache, const s
350351 return true ;
351352}
352353
354+ void json_plugin::copy_to_cache (libtokamap::RamCache& ram_cache, const std::string& key, const DATA_BLOCK* data_block) {
355+ auto entry = std::make_unique<UDACacheEntry>();
356+
357+ size_t data_size = data_block->data_n * size_of_uda_type (data_block->data_type );
358+ entry->data .resize (data_size);
359+ std::copy (data_block->data , data_block->data + data_size, entry->data .begin ());
360+
361+ entry->error_high = {};
362+ entry->error_low = {};
363+
364+ entry->dims .resize (data_block->rank );
365+ entry->dim_types .resize (data_block->rank );
366+ for (int i = 0 ; i < data_block->rank ; i++) {
367+ const DIMS* dim = &data_block->dims [i];
368+ size_t dim_size = dim->dim_n * size_of_uda_type (dim->data_type );
369+ entry->dims [i].resize (dim_size);
370+ std::copy (dim->dim , dim->dim + dim_size, entry->dims [i].begin ());
371+ entry->dim_types [i] = dim->data_type ;
372+ }
373+
374+ entry->order = data_block->order ;
375+ entry->data_type = data_block->data_type ;
376+ entry->error_type = data_block->error_type ;
377+
378+ ram_cache.add (key, std::move (entry));
379+ }
380+
353381bool json_plugin::copy_from_cache (const libtokamap::RamCache& cache, const std::string& key, DATA_BLOCK* data_block)
354382{
355383 auto entry = cache.get (key);
@@ -366,38 +394,39 @@ bool json_plugin::copy_from_cache(const libtokamap::RamCache& cache, const std::
366394 // DATA_BLOCK* data_block = (DATA_BLOCK*) malloc(sizeof(DATA_BLOCK));
367395 initDataBlock (data_block);
368396 data_block->data_type = data_entry->data_type ;
369- data_block->data_n = data_entry->data .size () / size_of_uda_type (data_entry->data_type );
397+ data_block->data_n = static_cast < int >( data_entry->data .size () ) / size_of_uda_type (data_entry->data_type );
370398
371399 log (LogLevel::INFO, " data size is: " + std::to_string (data_block->data_n ));
372400
373401 data_block->data = (char *)malloc (data_entry->data .size ());
374- std::copy (data_entry->data .data (), data_entry->data .data () + data_entry->data .size (), data_block->data );
402+ std::copy (data_entry->data .begin (), data_entry->data .end (), data_block->data );
403+
375404 if (!data_entry->error_high .empty ()) {
376405 data_block->errhi = (char *)malloc (data_entry->error_high .size ());
377- std::copy (data_entry->error_high .data (), data_entry->error_high .data () + data_entry->error_high .size (),
378- data_block->errhi );
406+ std::copy (data_entry->error_high .begin (), data_entry->error_high .end (), data_block->errhi );
379407 }
380408 if (!data_entry->error_low .empty ()) {
381409 data_block->errlo = (char *)malloc (data_entry->error_low .size ());
382- std::copy (data_entry->error_low .data (), data_entry->error_low .data () + data_entry->error_low .size (),
383- data_block->errlo );
410+ std::copy (data_entry->error_low .begin (), data_entry->error_low .end (), data_block->errlo );
384411 }
412+
385413 data_block->rank = data_entry->dims .size ();
386414 log (LogLevel::INFO, " data rank is: " + std::to_string (data_block->rank ));
387415
388- DIMS* dims = (DIMS*)malloc (data_block->rank * sizeof (DIMS));
416+ data_block-> dims = (DIMS*)malloc (data_block->rank * sizeof (DIMS));
389417 for (unsigned int i = 0 ; i < data_block->rank ; ++i) {
390- initDimBlock (&dims[i]);
418+ DIMS* dim = &data_block->dims [i];
419+ initDimBlock (dim);
391420
392- dims[i]. data_type = data_entry->dim_types [i];
393- dims[i]. dim_n = data_entry->dims [i].size () / size_of_uda_type (dims[i]. data_type );
421+ dim-> data_type = data_entry->dim_types [i];
422+ dim-> dim_n = data_entry->dims [i].size () / size_of_uda_type (dim-> data_type );
394423
395- log (LogLevel::INFO, " dim " + std::to_string (i) + " length: " + std::to_string (dims[i]. dim_n ));
424+ log (LogLevel::INFO, " dim " + std::to_string (i) + " length: " + std::to_string (dim-> dim_n ));
396425
397- dims[i]. dim = (char *)malloc (data_entry->dims [i].size ());
398- std::copy (data_entry->dims [i].data (), data_entry->dims [i].data () + data_entry-> dims [i]. size (), dims[i]. dim );
426+ dim-> dim = (char *)malloc (data_entry->dims [i].size ());
427+ std::copy (data_entry->dims [i].begin (), data_entry->dims [i].end (), dim-> dim );
399428 }
400- data_block-> dims = dims;
429+
401430 data_block->order = data_entry->order ;
402431
403432 log_datablock_status (data_block, " data_block from cache" );
0 commit comments