<commit_before>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "UserDataIO.h"
#include "UserObject.h"
#include <vector>

const unsigned int UserDataIO::file_version = 1;

struct MUDSHeader               // MOOSE User Data Storage
{
  char _id[4];                  // 4 letter ID
  unsigned int _file_version;   // file version
};


UserDataIO::UserDataIO(UserObjectWarehouse & ud_wh) :
    _userobject_wh(ud_wh)
{
}

UserDataIO::~UserDataIO()
{
}

void
UserDataIO::write(const std::string & file_name)
{
  std::ofstream out(file_name.c_str(), std::ios::out | std::ios::binary);

  // header
  MUDSHeader head;
  memcpy(head._id, "MUDS", 4);
  head._file_version = file_version;
  out.write((const char *) & head, sizeof(head));

  // save the number of user objects
  unsigned int n_objs = _userobject_wh.size();
  out.write((const char *) & n_objs, sizeof(n_objs));

  // loop over objects and save them
  std::vector<UserObject *> & uds = _userobject_wh.getObjects();
  for (std::vector<UserObject *>::iterator it = uds.begin(); it != uds.end(); ++it)
  {
    UserObject * uo = *it;

    // write out the name
    std::string name = uo->name();
    out.write(name.c_str(), name.length() + 1);                 // do not forget the trailing zero ;-)

    long pos = out.tellp();
    unsigned int size = 0;
    // write out the size
    out.write((const char *) & size, sizeof(size));
    // write out the data
    uo->store(out);
    long end = out.tellp();
    // go back and overwrite the size<commit_msg>Use C++ version of memcpy (#1152)<commit_after>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "UserDataIO.h"
#include "UserObject.h"
#include <vector>
#include <cstring>

const unsigned int UserDataIO::file_version = 1;

struct MUDSHeader               // MOOSE User Data Storage
{
  char _id[4];                  // 4 letter ID
  unsigned int _file_version;   // file version
};


UserDataIO::UserDataIO(UserObjectWarehouse & ud_wh) :
    _userobject_wh(ud_wh)
{
}

UserDataIO::~UserDataIO()
{
}

void
UserDataIO::write(const std::string & file_name)
{
  std::ofstream out(file_name.c_str(), std::ios::out | std::ios::binary);

  // header
  MUDSHeader head;
  std::memcpy(head._id, "MUDS", 4);
  head._file_version = file_version;
  out.write((const char *) & head, sizeof(head));

  // save the number of user objects
  unsigned int n_objs = _userobject_wh.size();
  out.write((const char *) & n_objs, sizeof(n_objs));

  // loop over objects and save them
  std::vector<UserObject *> & uds = _userobject_wh.getObjects();
  for (std::vector<UserObject *>::iterator it = uds.begin(); it != uds.end(); ++it)
  {
    UserObject * uo = *it;

    // write out the name
    std::string name = uo->name();
    out.write(name.c_str(), name.length() + 1);                 // do not forget the trailing zero ;-)

    long pos = out.tellp();
    unsigned int size = 0;
    // write out the size
    out.write((const char *) & size, sizeof(size));
    // write out the data
    uo->store(out);
    long end = out.tellp();
    // go back and overwrite the size
{'fraction_non_alphanumeric': 0.17315834038950043, 'fraction_numerical': 0.008890770533446233, 'mean_word_length': 1.8225806451612903, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '652061', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1260, 'n_words': 352}