<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLShader.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLShader.h"

#include "vtkObjectFactory.h"
#include "vtkShaderCodeLibrary.h"
#include "vtkToolkits.h" // for VTK_SHADERS_DIRS.
#include "vtkXMLDataElement.h"

#include <vtksys/SystemTools.hxx>

vtkStandardNewMacro(vtkXMLShader);
vtkCxxRevisionMacro(vtkXMLShader, "1.2");
vtkCxxSetObjectMacro(vtkXMLShader, SourceLibraryElement, vtkXMLDataElement);
//-----------------------------------------------------------------------------
vtkXMLShader::vtkXMLShader()
{
  this->RootElement = 0;
  this->SourceLibraryElement = 0;
  this->Code = 0;
  this->Args = 0;
}

//-----------------------------------------------------------------------------
vtkXMLShader::~vtkXMLShader()
{
  if (this->RootElement)
    {
    this->RootElement->UnRegister(this);
    this->RootElement = 0;
    }
  this->SetSourceLibraryElement(0);
  this->SetCode(0);
  this->CleanupArgs();
}

//-----------------------------------------------------------------------------
void vtkXMLShader::SetRootElement(vtkXMLDataElement* root)
{
  vtkSetObjectBodyMacro(RootElement, vtkXMLDataElement, root);
  this->SetCode(0);
  this->SetSourceLibraryElement(0); // release the SourceLibrary element.
  // Determine if this shader description uses a library.
  if (this->RootElement)
    {
    switch (this->GetLocation())
      {
    case vtkXMLShader::LOCATION_LIBRARY:
        {
        const char* name = this->RootElement->GetAttribute("name");
        this->Code = vtkShaderCodeLibrary::GetShaderCode(name);
        // TODO: the library should be XML enclosed.
        // For now, it's not.
        if (!this->Code)
          {
          vtkErrorMacro("Failed to locate library " << name);
          return;
          }
        }
      break;
    case vtkXMLShader::LOCATION_FILE:
        {
        const char* filename = this->RootElement->GetAttribute("location");
        const char* fullpath = this->LocateFile(filename);
        if (!fullpath)
          {
          vtkErrorMacro("Failed to locate file " << filename);
          return;
          }
        this->ReadCodeFromFile(fullpath);
        delete [] fullpath;<commit_msg>COMP: fixed dashboard compilation error, can't delete const ptr<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLShader.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLShader.h"

#include "vtkObjectFactory.h"
#include "vtkShaderCodeLibrary.h"
#include "vtkToolkits.h" // for VTK_SHADERS_DIRS.
#include "vtkXMLDataElement.h"

#include <vtksys/SystemTools.hxx>

vtkStandardNewMacro(vtkXMLShader);
vtkCxxRevisionMacro(vtkXMLShader, "1.3");
vtkCxxSetObjectMacro(vtkXMLShader, SourceLibraryElement, vtkXMLDataElement);
//-----------------------------------------------------------------------------
vtkXMLShader::vtkXMLShader()
{
  this->RootElement = 0;
  this->SourceLibraryElement = 0;
  this->Code = 0;
  this->Args = 0;
}

//-----------------------------------------------------------------------------
vtkXMLShader::~vtkXMLShader()
{
  if (this->RootElement)
    {
    this->RootElement->UnRegister(this);
    this->RootElement = 0;
    }
  this->SetSourceLibraryElement(0);
  this->SetCode(0);
  this->CleanupArgs();
}

//-----------------------------------------------------------------------------
void vtkXMLShader::SetRootElement(vtkXMLDataElement* root)
{
  vtkSetObjectBodyMacro(RootElement, vtkXMLDataElement, root);
  this->SetCode(0);
  this->SetSourceLibraryElement(0); // release the SourceLibrary element.
  // Determine if this shader description uses a library.
  if (this->RootElement)
    {
    switch (this->GetLocation())
      {
    case vtkXMLShader::LOCATION_LIBRARY:
        {
        const char* name = this->RootElement->GetAttribute("name");
        this->Code = vtkShaderCodeLibrary::GetShaderCode(name);
        // TODO: the library should be XML enclosed.
        // For now, it's not.
        if (!this->Code)
          {
          vtkErrorMacro("Failed to locate library " << name);
          return;
          }
        }
      break;
    case vtkXMLShader::LOCATION_FILE:
        {
        const char* filename = this->RootElement->GetAttribute("location");
        char* fullpath = this->LocateFile(filename);
        if (!fullpath)
          {
          vtkErrorMacro("Failed to locate file " << filename);
          return;
          }
        this->ReadCodeFromFile(fullpath);
        delete [] fullpath;
{'fraction_non_alphanumeric': 0.24068609369236443, 'fraction_numerical': 0.004057543341940244, 'mean_word_length': 2.423611111111111, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3469823', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1461, 'n_words': 324}