2018-10-25 08:34:21 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-10-25 08:34:21 -05:00
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "VdePacketDirectory.h"
|
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
#include <algorithm>
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
VdePacketDirectory::VdePacketDirectory()
|
|
|
|
{
|
|
|
|
}
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void VdePacketDirectory::addPacket( std::unique_ptr<VdeArrayDataPacket> packet )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const int id = packet->arrayId();
|
|
|
|
m_idToPacketMap[id] = std::move( packet );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
const VdeArrayDataPacket* VdePacketDirectory::lookupPacket( int arrayId ) const
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find( arrayId );
|
|
|
|
if ( it == m_idToPacketMap.end() )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void VdePacketDirectory::clear()
|
|
|
|
{
|
|
|
|
m_idToPacketMap.clear();
|
|
|
|
}
|
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void VdePacketDirectory::pruneUnreferencedPackets( const std::vector<int>& packetIdsInUseArr )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<int> sortedPacketsIdsInUse( packetIdsInUseArr );
|
|
|
|
std::sort( sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end() );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
IdToPacketMap_T::const_iterator it = m_idToPacketMap.cbegin();
|
2019-09-06 03:40:57 -05:00
|
|
|
while ( it != m_idToPacketMap.cend() )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
|
|
|
const int packetId = it->first;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !std::binary_search( sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end(), packetId ) )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
it = m_idToPacketMap.erase( it );
|
2018-12-19 05:31:44 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 08:34:21 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
bool VdePacketDirectory::getPacketsAsCombinedBuffer( const std::vector<int>& packetIdsToGet, QByteArray* combinedPacketArr ) const
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const int arrayId : packetIdsToGet )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find( arrayId );
|
|
|
|
if ( it == m_idToPacketMap.end() )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VdeArrayDataPacket& packet = *it->second;
|
2023-02-26 03:48:40 -06:00
|
|
|
*combinedPacketArr += QByteArray::fromRawData( packet.fullPacketRawPtr(), static_cast<int>( packet.fullPacketSize() ) );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|