<commit_before>/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Duplication helper for some specific formats
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//---------------------------------------------------------------------------
// Pre-compilation
#include "MediaInfo/PreComp.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Setup.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#if defined(MEDIAINFO_MPEGPS_YES) || defined(MEDIAINFO_MPEGTS_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Duplicate/File__Duplicate_MpegTs.h"
#include "MediaInfo/MediaInfo_Config.h"
#include "ZenLib/ZtringList.h"
#include "ZenLib/File.h"
#include <cstring>
using namespace ZenLib;
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

//---------------------------------------------------------------------------
// CRC_32_Table
// A CRC is computed like this:
// Init: int32u CRC_32 = 0xFFFFFFFF;
// for each data byte do
//     CRC_32=(CRC_32<<8) ^ CRC_32_Table[(CRC_32>>24)^(data_byte)];
extern const int32u Psi_CRC_32_Table[256];

//***************************************************************************
// Constructor/Destructor
//***************************************************************************

File__Duplicate_MpegTs::File__Duplicate_MpegTs (const Ztring &Target)
: File__Duplicate__Base()
{
    Writer.Configure(Target);

    //Current
    program_map_PIDs.resize(0x2000, 0);
    elementary_PIDs.resize(0x2000, 0);
    elementary_PIDs_program_map_PIDs.resize(0x2000, 0);
}

//***************************************************************************
// Set
//***************************************************************************

//---------------------------------------------------------------------------
void File__Duplicate_MpegTs::Internal_Remove_Wanted_Program(int16u Program_number, bool ToRemove)
{
    if (ToRemove)
    {
        if (Wanted_program_numbers.find(Program_number) != Wanted_program_numbers.end())
            Wanted_program_numbers.erase(Program_number);
        else if (Remove_program_numbers.find(Program_number) == Remove_program_numbers.end())
            Remove_program_numbers.insert(Program_number);
    }
    else
    {
        if (Remove_program_numbers.find(Program_number) != Remove_program_numbers.end())
            Remove_program_numbers.erase(Program_number);
        if (Wanted_program_numbers.find(Program_number) == Wanted_program_numbers.end())
            Wanted_program_numbers.insert(Program_number);
    }
    if (!PAT.empty())
        PAT.begin()->second.ConfigurationHasChanged = true;
}
//---------------------------------------------------------------------------
bool File__Duplicate_MpegTs::Configure (const Ztring &Value, bool ToRemove)
{
    //Form: "program_number"
    if (Value.find(__T("program_number="))==0)
    {
        const int16u program_number=Ztring(Value.substr(15, std::string::npos)).To_int16u();
        Internal_Remove_Wanted_Program(program_number, ToRemove);
    }
    //Form: "program_map_PID"
    else if (Value.find(__T("program_map_PID="))==0)
    {
        const int16u program_map_PID=Ztring(Value.substr(16, std::string::npos)).To_int16u();
        if (ToRemove)
        {
            if (Wanted_program_map_PIDs.find(program_map_PID)!=Wanted_program_map_PIDs.end())
                Wanted_program_map_PIDs.erase(program_map_PID);
            else if (Remove_program_map_PIDs.find(program_map_PID)==Remove_program_map_PIDs.end())
                Remove_program_map_PIDs.insert(program_map_PID);
        }
        else
        {
            if (Remove_program_map_PIDs.find(program_map_PID)!=Remove_program_map_PIDs.end())
                Remove_program_map_PIDs.erase(program_map_PID);
            if (Wanted_program_map_PIDs.find(program_map_PID)==Wanted_program_map_PIDs.end())
                Wanted_program_map_PIDs.insert(program_map_PID);
        }
        if (PMT.find(program_map_PID)!=PMT.end())
            PMT[program_map_PID].ConfigurationHasChanged=true;
    }
    //Form: "elementary_PID"
    else if (Value.find(__T("elementary_PID="))==0)
    {
        const int16u elementary_PID=Ztring(Value.substr(15, std::string::npos)).To_int16u();
        if (ToRemove)
        {
            if (Wanted_elementary_PIDs.find(elementary_PID)!=Wanted_elementary_PIDs.end())
                Wanted_elementary_PIDs.erase(elementary_PID);
            else if (Remove_elementary_PIDs.find(elementary_PID)==Remove_elementary_PIDs.end())
                Remove_elementary_PIDs.insert(elementary_PID);
        }
        else
        {
            if (Remove_elementary_PIDs.find(elementary_PID)!=Remove_elementary_PIDs.end())
                Remove_elementary_PIDs.erase(elementary_PID);
            if (Wanted_elementary_PIDs.find(elementary_PID)==Wanted_elementary_PIDs.end())
                Wanted_elementary_PIDs.insert(elementary_PID);
        }
        if (PMT.find(elementary_PIDs_program_map_PIDs[elementary_PID])!=PMT.end())<commit_msg>Step 3  * [cppcheck] Redundant checking of STL container element existence before removing it. It is safe to call the remove method on a non-existing element.<commit_after>/*  Copyright (c) Media<EMAIL> SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Duplication helper for some specific formats
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//---------------------------------------------------------------------------
// Pre-compilation
#include "MediaInfo/PreComp.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Setup.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#if defined(MEDIAINFO_MPEGPS_YES) || defined(MEDIAINFO_MPEGTS_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Duplicate/File__Duplicate_MpegTs.h"
#include "MediaInfo/MediaInfo_Config.h"
#include "ZenLib/ZtringList.h"
#include "ZenLib/File.h"
#include <cstring>
using namespace ZenLib;
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

//---------------------------------------------------------------------------
// CRC_32_Table
// A CRC is computed like this:
// Init: int32u CRC_32 = 0xFFFFFFFF;
// for each data byte do
//     CRC_32=(CRC_32<<8) ^ CRC_32_Table[(CRC_32>>24)^(data_byte)];
extern const int32u Psi_CRC_32_Table[256];

//***************************************************************************
// Constructor/Destructor
//***************************************************************************

File__Duplicate_MpegTs::File__Duplicate_MpegTs (const Ztring &Target)
: File__Duplicate__Base()
{
    Writer.Configure(Target);

    //Current
    program_map_PIDs.resize(0x2000, 0);
    elementary_PIDs.resize(0x2000, 0);
    elementary_PIDs_program_map_PIDs.resize(0x2000, 0);
}

//***************************************************************************
// Set
//***************************************************************************

//---------------------------------------------------------------------------
void File__Duplicate_MpegTs::Internal_Remove_Wanted_Program(int16u Program_number, bool ToRemove)
{
    if (ToRemove)
    {
        if(Wanted_program_numbers.erase(Program_number) == 0)
           Remove_program_numbers.insert(Program_number);
    }
    else
    {
        if(Remove_program_numbers.erase(Program_number) == 0)
           Wanted_program_numbers.insert(Program_number);
    }
    if (!PAT.empty())
        PAT.begin()->second.ConfigurationHasChanged = true;
}
//---------------------------------------------------------------------------
bool File__Duplicate_MpegTs::Configure (const Ztring &Value, bool ToRemove)
{
    //Form: "program_number"
    if (Value.find(__T("program_number="))==0)
    {
        const int16u program_number=Ztring(Value.substr(15, std::string::npos)).To_int16u();
        Internal_Remove_Wanted_Program(program_number, ToRemove);
    }
    //Form: "program_map_PID"
    else if (Value.find(__T("program_map_PID="))==0)
    {
        const int16u program_map_PID=Ztring(Value.substr(16, std::string::npos)).To_int16u();
        if (ToRemove)
        {
            if(Wanted_program_map_PIDs.erase(program_map_PID) == 0)
               Remove_program_map_PIDs.insert(program_map_PID);
        }
        else
        {
             Remove_program_map_PIDs.erase(program_map_PID);
             Wanted_program_map_PIDs.insert(program_map_PID);
        }
        if (PMT.find(program_map_PID)!=PMT.end())
            PMT[program_map_PID].ConfigurationHasChanged=true;
    }
    //Form: "elementary_PID"
    else if (Value.find(__T("elementary_PID="))==0)
    {
        const int16u elementary_PID=Ztring(Value.substr(15, std::string::npos)).To_int16u();
        if (ToRemove)
        {
            if(Wanted_elementary_PIDs.erase(elementary_PID) == 0)
               Remove_elementary_PIDs.insert(elementary_PID);
        }
        else
        {
                Remove_elementary_PIDs.erase(elementary_PID);
                Wanted_elementary_PIDs.insert(elementary_PID);
        }
        if (PMT.find(elementary_PIDs_program_map_PIDs[elementary_PID])!=PMT.end())
{'fraction_non_alphanumeric': 0.3346105948845675, 'fraction_numerical': 0.013123862438930932, 'mean_word_length': 2.003452243958573, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5320617', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2797, 'n_words': 408}