<commit_before>/*******************************************************************/
/*                               XDMF                              */
/*                   eXtensible Data Model and Format              */
/*                                                                 */
/*  Id : Id  */
/*  Date : $Date$ */
/*  Version : $Revision$ */
/*                                                                 */
/*  Author:                                                        */
/*     <NAME>                                             */
/*     <EMAIL>                                         */
/*     US Army Research Laboratory                                 */
/*     Aberdeen Proving Ground, MD                                 */
/*                                                                 */
/*     Copyright @ 2002 US Army Research Laboratory                */
/*     All Rights Reserved                                         */
/*     See Copyright.txt or http://www.arl.hpc.mil/ice 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 "XdmfFormatXML.h"

#include "XdmfDOM.h"
#include "XdmfArray.h"
#include "XdmfHDF.h"

XdmfFormatXML::XdmfFormatXML() {
  strcpy( this->DataFormat, "XML" );
}

XdmfFormatXML::~XdmfFormatXML() {
}

XdmfArray *
XdmfFormatXML::ElementToArray( XdmfXNode *Element, XdmfDataDesc *Desc, XdmfArray *Array  ) {

XdmfInt32  NumberType;
XdmfConstString  Data;
XdmfArray  *NewArray = NULL;
XdmfDataDesc  *NewDesc = NULL;

if( !this->DOM ){
  XdmfErrorMessage("Object has no DOM");
  return( NULL );
  }
if( !Element ) {
  XdmfErrorMessage("Element is NULL");
  return( NULL );
  }
NumberType = this->DOM->GetNumberType( Element );
Data = this->DOM->Get(Element, "CData");
if( Data && strlen( Data ) > 1 ){
  if( Array == NULL ){
    NewArray = Array = new XdmfArray( NumberType );
    }
  if( Desc == NULL ){
    NewDesc = Desc = this->ElementToDataDesc( Element, 0 );
    }
  if( Desc ){
    if( NewArray ){
      Array->CopyType( Desc );
      Array->CopyShape( Desc );
      Array->CopySelection( Desc );
      Array->Allocate();
    }
    if( Desc->GetSelectionSize() != Array->GetNumberOfElements() ){
      XdmfInt64  SelectionSize = Desc->GetSelectionSize();
      XdmfArray  *TempArray = new XdmfArray();

      TempArray->CopyType( Desc );
      TempArray->CopyShape( Desc );
      TempArray->CopySelection( Desc );
      TempArray->Allocate();
      TempArray->SetValues(0, Data );
      if( NewArray ){
        NewArray->SetShape( 1, &SelectionSize );
        NewArray->SelectAll();
        }
      CopyArray( TempArray, Array );
      delete TempArray;
    } else {
      Array->SetValues(0, Data );
    }
    if( NewDesc ){
      delete Desc;
      }
  }else{
    XdmfErrorMessage("Node has Invalid Data Desc");
    if( NewArray ){
      delete NewArray;
      }
    return( NULL );
    }
  
} else {
  XdmfErrorMessage("Node has no CData");
  return( NULL );
}
return( Array );
}

XdmfXNode *
XdmfFormatXML::ArrayToElement( XdmfArray *Array,
      XdmfString /*HeavyDataset*/,
      XdmfXNode *Element,
      XdmfDataDesc *Desc ) {

char    Attribute[ XDMF_MAX_STRING_LENGTH  ];
ostrstream  Value( Attribute, XDMF_MAX_STRING_LENGTH );
<commit_msg>ENH: Make local copy of Data so that we do not rely on some ivar not changing<commit_after>/*******************************************************************/
/*                               XDMF                              */
/*                   eXtensible Data Model and Format              */
/*                                                                 */
/*  Id : Id  */
/*  Date : $Date$ */
/*  Version : $Revision$ */
/*                                                                 */
/*  Author:                                                        */
/*     <NAME>                                             */
/*     <EMAIL>l.army.mil                                         */
/*     US Army Research Laboratory                                 */
/*     Aberdeen Proving Ground, MD                                 */
/*                                                                 */
/*     Copyright @ 2002 US Army Research Laboratory                */
/*     All Rights Reserved                                         */
/*     See Copyright.txt or http://www.arl.hpc.mil/ice 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 "XdmfFormatXML.h"

#include "XdmfDOM.h"
#include "XdmfArray.h"
#include "XdmfHDF.h"

XdmfFormatXML::XdmfFormatXML() {
  strcpy( this->DataFormat, "XML" );
}

XdmfFormatXML::~XdmfFormatXML() {
}

XdmfArray *
XdmfFormatXML::ElementToArray( XdmfXNode *Element, XdmfDataDesc *Desc, XdmfArray *Array  ) {

XdmfInt32  NumberType;
XdmfConstString  Data;
XdmfArray  *NewArray = NULL;
XdmfDataDesc  *NewDesc = NULL;

if( !this->DOM ){
  XdmfErrorMessage("Object has no DOM");
  return( NULL );
  }
if( !Element ) {
  XdmfErrorMessage("Element is NULL");
  return( NULL );
  }
NumberType = this->DOM->GetNumberType( Element );
Data = this->DOM->Get(Element, "CData");
if( Data && strlen( Data ) > 1 ){
  XdmfString NewData = 0;
  XDMF_STRING_DUPLICATE(NewData, Data);
  if( Array == NULL ){
    NewArray = Array = new XdmfArray( NumberType );
    }
  if( Desc == NULL ){
    NewDesc = Desc = this->ElementToDataDesc( Element, 0 );
    }
  if( Desc ){
    if( NewArray ){
      Array->CopyType( Desc );
      Array->CopyShape( Desc );
      Array->CopySelection( Desc );
      Array->Allocate();
    }
    if( Desc->GetSelectionSize() != Array->GetNumberOfElements() ){
      XdmfInt64  SelectionSize = Desc->GetSelectionSize();
      XdmfArray  *TempArray = new XdmfArray();

      TempArray->CopyType( Desc );
      TempArray->CopyShape( Desc );
      TempArray->CopySelection( Desc );
      TempArray->Allocate();
      TempArray->SetValues(0, NewData );
      if( NewArray ){
        NewArray->SetShape( 1, &SelectionSize );
        NewArray->SelectAll();
        }
      CopyArray( TempArray, Array );
      delete TempArray;
    } else {
      Array->SetValues(0, NewData );
    }
    if( NewDesc ){
      delete Desc;
      }
  }else{
    XdmfErrorMessage("Node has Invalid Data Desc");
    if( NewArray ){
      delete NewArray;
      }
    delete [] NewData;
    return( NULL );
    }
  
  delete [] NewData;
} else {
  XdmfErrorMessage("Node has no CData");
  return( NULL );
}
return( Array );
}

XdmfXNode *
XdmfFormatXML::ArrayToElement( XdmfArray *Array,
      XdmfString /*HeavyDataset*/,
      XdmfXNode *Element,
      XdmfDataDesc *Desc ) {

char    Attribute[ XDMF_MAX_STRING_LENGTH  ];
ostrstream  Value( Attribute, XDMF_MAX_STRING_LENGTH );

{'fraction_non_alphanumeric': 0.14907407407407408, 'fraction_numerical': 0.0035714285714285713, 'mean_word_length': 1.553529213103681, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5183059', 'n_tokens_mistral': 2056, 'n_tokens_neox': 2038, 'n_words': 477}